Skip to content

Instantly share code, notes, and snippets.

@mythz
Created January 15, 2011 18:35
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 mythz/781127 to your computer and use it in GitHub Desktop.
Save mythz/781127 to your computer and use it in GitHub Desktop.
Passing tests for ServiceStack.NET's new C# Async Web Service Clients
[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