-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Catch Operator for Error Cases #8
- Loading branch information
Showing
7 changed files
with
111 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Tests | ||
{ | ||
[TestClass] | ||
public class AsyncTests | ||
{ | ||
[TestMethod] | ||
public void AsyncOperationCreationSuccess() | ||
{ | ||
var task = Operation.Run(async () => | ||
{ | ||
await Task.Run(() => Console.WriteLine("Hello Operation")); | ||
}); | ||
|
||
task.Wait(); | ||
|
||
Assert.IsTrue(task.Result.Succeeded); | ||
} | ||
|
||
[TestMethod] | ||
public async Task AsyncOperationCreationFailure() | ||
{ | ||
var task = Operation.Run(() => | ||
{ | ||
return Task.Run(() => | ||
{ | ||
Console.WriteLine("Hello Operation"); | ||
throw new Exception("The Error"); | ||
}); | ||
}); | ||
|
||
var result = await task; | ||
|
||
Assert.IsFalse(result.Succeeded); | ||
Assert.AreEqual(result.Message, "The Error"); | ||
} | ||
|
||
[TestMethod] | ||
public async Task AsyncOperationTCreationFailure() | ||
{ | ||
var task = Operation.Run(() => | ||
{ | ||
return Task.Run(() => | ||
{ | ||
Console.WriteLine("Hello Operation"); | ||
var x = true; | ||
if(x) throw new Exception("The Error"); | ||
return 1; | ||
}); | ||
}); | ||
|
||
var result = await task; | ||
|
||
Assert.IsFalse(result.Succeeded); | ||
Assert.AreEqual(result.Message, "The Error"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters