Note that there are some explanatory texts on larger screens.

plurals
  1. POUnit test rest service without specifying URL
    text
    copied! <p>Using servicestack, there are examples of unit testing using types, etc. Here is an example: <a href="https://github.com/ServiceStack/ServiceStack.Examples/blob/master/tests/ServiceStack.Examples.Tests/GetFactorialTests.cs" rel="nofollow">GetFactorial</a></p> <p>I would like to test my REST style service with a test similar to the above. </p> <p>Here is an example REST unit test <a href="https://github.com/ServiceStack/ServiceStack.Examples/blob/master/src/RestFiles/RestFiles.Tests/SyncRestClientTests.cs#L118" rel="nofollow">FileService</a></p> <p>Notice how in the PUT unit test, the Path argument has to be specified in the URL text instead of in the class argument. Another example is <a href="https://github.com/ServiceStack/ServiceStack.Examples/blob/master/src/RestIntro/RestIntro.IntegrationTests/IntegrationTests.cs" rel="nofollow">here</a>, where we have perfectly good request models that have to be translated into the URL. For testing, I would like to get away from having to build the arguments in the url and use a system similar to the one above like this:</p> <pre class="lang-cs prettyprint-override"><code>var response = restClient.Put&lt;FilesResponse&gt;(new Files { TextContents = ReplacedFileContents, Path = "README.txt" }); </code></pre> <p>or</p> <pre class="lang-cs prettyprint-override"><code>var singleCustomer = restClient.Get&lt;Customer&gt;(new Customer {Id=1}; </code></pre> <p>Is this possible?</p> <p>Then there is the <a href="https://github.com/ServiceStack/ServiceStack/blob/master/tests/ServiceStack.WebHost.IntegrationTests/Tests/WebServicesTests.cs" rel="nofollow">DirectServiceClient</a>. Would that help? In the end, with servicestack, we get to write services and they can be called from many different type clients - I would like to write my unit test like that. </p> <p>Is this possible?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload