I'm writing a unit test with Xunit and Moq on a ServiceStack microservice.
I can get a unit test of a GET route to work with one class, but with a different class it refuses to work. I'm moq'ing the ServiceStack.JsonHttpClient.GET in this route:
public SampleResponse Get(SampleRequest request)
{
var myServiceRequest = new SampleService.myRequest() { PrimaryId = request.PrimaryId };
using (client = ClientFactory.CreateSampleService()) // client is extension of ServiceStack.JsonHttpClient
{
// This code runs on local but throws the exception with unit testing
SampleService.myResponse myResponse = client.Get(myServiceRequest);
...
}
}
And here is the test:
// Arrange
var myServiceRequest = new SampleService.myRequest { PrimaryId = 1234 };
var myServiceResponse = new SampleService.myResponse { ... };
// assigning the request with the desired response
mockService.MockGet(myServiceRequest, myServiceResponse);
// Act
var request = new ServiceModel.SampleRequest { PrimaryId = 1234 };
// This calls the above function and fails
var response = frontEndService.Get(request);
// Assert
Assert.NotEmpty(response.Items);
Assert.Equal(3, response.Items.ANumber);
But I get this Exception and InnerException:
ServiceStack.WebException: 'Not Found'
Inner Exception
SerializationException: Type definitions should start with a '{', expecting serialized type 'ErrorResponse', got string starting with: MOCK FOR URL NOT FOUND
I did an almost identical setup for a simpler class and it works, but this class refuses to unit test correctly. It DOES run fine when ran locally.
This Exception occurs when the JSON doesn’t match the Type you’re trying to deserialize into.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With