Created
January 15, 2011 18:35
-
-
Save mythz/781127 to your computer and use it in GitHub Desktop.
Passing tests for ServiceStack.NET's new C# Async Web Service Clients
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
[TestFixture] | |
public class AsyncServiceClientTests | |
{ | |
private const string ListeningOn = "http://localhost:82/"; | |
ExampleAppHostHttpListener appHost; | |
[TestFixtureSetUp] | |
public void OnTestFixtureSetUp() | |
{ | |
appHost = new ExampleAppHostHttpListener(); | |
appHost.Init(); | |
appHost.Start(ListeningOn); | |
} | |
private static void FailOnAsyncError<T>(T response, Exception ex) | |
{ | |
Assert.Fail(ex.Message); | |
} | |
[Test] | |
public void Can_call_GetAsync_on_JsonRestServiceClient() | |
{ | |
var jsonClient = new JsonRestServiceClient(ListeningOn); | |
GetFactorialResponse response = null; | |
jsonClient.GetAsync<GetFactorialResponse>("factorial/3", r => response = r, FailOnAsyncError); | |
Thread.Sleep(500); | |
Assert.That(response, Is.Not.Null, "No response received"); | |
Assert.That(response.Result, Is.EqualTo(GetFactorialService.GetFactorial(3))); | |
} | |
[Test] | |
public void Can_call_SendAsync_on_JsonServiceClient() | |
{ | |
var jsonClient = new JsonServiceClient(ListeningOn); | |
var request = new GetFactorial { ForNumber = 3 }; | |
GetFactorialResponse response = null; | |
jsonClient.SendAsync<GetFactorialResponse>(request, r => response = r, FailOnAsyncError); | |
Thread.Sleep(500); | |
Assert.That(response, Is.Not.Null, "No response received"); | |
Assert.That(response.Result, Is.EqualTo(GetFactorialService.GetFactorial(request.ForNumber))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment