Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing plugins in ServiceStack

Tags:

servicestack

Im looking at the source code for unit testing in ServiceStackTestHostBase.cs - and got it running with my own project. How would i go around enabling my plugins when unit testing without actually starting a listener? For examples i would like to test that my web service validates correctly, so i add the following code to Configure in TestHostBase.cs.

Plugins.Add(new ValidationFeature());
container.RegisterValidators(typeof(CustomerModelValidator).Assembly);

But when calling base.send with a Customer object which violates a validation rule no validation are done. (Note: Validation works allright when i start my webservice with a listener)

like image 986
Johnny Avatar asked Dec 28 '25 04:12

Johnny


1 Answers

Since Plugins can mutate any part of an AppHost (i.e. Add Routes, ContentTypes, Request/Response Filters, CatchAll Handlers, etc). They're not possible to test its integration with your services without starting a HttpListener (or ASP.NET host).

Of course if your Plugin is testable, you can unit test it in isolation, separate from your services.

like image 186
mythz Avatar answered Dec 30 '25 23:12

mythz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!