Skip to content

Instantly share code, notes, and snippets.

@PProvost
Created May 26, 2012 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PProvost/2794710 to your computer and use it in GitHub Desktop.
Save PProvost/2794710 to your computer and use it in GitHub Desktop.
Simple Example of C# Async Unit Test in VS11
public class SystemUnderTest
{
public Task<string> LongRunningOperation()
{
return Task.Run(() =>
{
Thread.Sleep(2000); // Simulate the long operation
return "Hello there";
});
}
}
// Using MS-Test
[TestClass]
public class MsTestAsyncExample
{
[TestMethod]
public async Task TestLongRunningOperation()
{
var sut = new SystemUnderTest();
var result = await sut.LongRunningOperation();
Assert.AreEqual("Hello there", result);
}
}
// Using xUnit.net
public class xUnitExample
{
[Fact]
public async Task TestLongRunningOperation()
{
var sut = new SystemUnderTest();
var result = await sut.LongRunningOperation();
Assert.Equal("Hello there", result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment