Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Threading.Tasks;
- using FluentAssertions;
- using NUnit.Framework;
- // see http://nitoprograms.blogspot.ca/2012/02/async-unit-tests-part-2-right-way.html
- // include CapturerAndRestorer.cs and GeneralThreadAffineContext.cs from here:
- // http://www.symbolsource.org/Public/Metadata/NuGet/Project/AsyncUnitTests-MSTest/1.0.1/Release/.NETFramework,Version=v4.0,Profile=Client/Nito.AsyncEx.UnitTests.MSTest
- namespace ClassLibrary1
- {
- public class Calculator
- {
- public Task<int> Add(int a, int b)
- {
- return Task.FromResult(42);
- }
- }
- [TestFixture]
- public class Test
- {
- [Test]
- public void ShouldAdd()
- {
- GeneralThreadAffineContext.Run(async () =>
- {
- var c = new Calculator();
- var sum = await c.Add(1, 2);
- sum.Should().Be(3);
- });
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement