10
votes

I'm very new to ServiceStack. So far, I've had good fortune in getting a basic API up and working (the Northwind example was particularly helpful for me). However, I'm stumbling when trying to build unit and integration tests.

I've found a recent gist from another ServiceStack user who illustrated a few (possibly incorrect) examples of unit and integration tests, but I cannot get those working.

Here is the reference I've been using: https://github.com/ServiceStack/ServiceStack/issues/435

Here is my attempt at a basic unit test, using mostly borrowed code from the other user's gist: https://gist.github.com/anonymous/4957788

When I attempt to run the test case in HelloWorldTest, a System.NotImplementedException is thrown, stating "Unable to resolve service 'HelloWorldName'".

This is confusing to me, as I'm passing it a request DTO, not a service, which seems to agree with the ExecuteService() method I'm calling. But the exception suggests that ServiceStack is treating my DTO as a service.

Could somebody possibly send me to a good, canonical example of how to correctly write unit and integration tests for ServiceStack? I should mention that I'm also new to .NET development in general, so perhaps my ignorance is shining through.

Many thanks.

1
Thanks, mythz. A question about integration tests. With an end-to-end integration test, I need to have the service actually running in order to connect to it with a JsonServiceClient instance. How do I go about that? - Jay Vanderhought
provided some links in answer below. - mythz

1 Answers

5
votes

Look at the testing docs and this earlier question and answer for a simple example on how to create a Unit and Integration test.

Also most of the tests in ServiceStack.WebHost.Endpoints.Tests are stand-alone integration tests that just use a self-hosted HttpListener AppHost. Some examples: