Testing plugins in ServiceStack

人盡茶涼 提交于 2019-12-23 22:48:42

问题


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)


回答1:


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.



来源:https://stackoverflow.com/questions/11710434/testing-plugins-in-servicestack

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!