I am trying to run a unit test from OData controllers, however the APIs are changed and the previously recommended methods that I tried do not work - currently I get
A route route without OData is not registered.
when trying to create an instance of ODataQueryOptions to pass to the controller's Get method
My current code (based on answers like this ):
[TestMethod()] public void RankingTest() { var serviceMock = new Mock<IVendorService>(); serviceMock.SetReturnsDefault<IEnumerable<Vendor>>(new List<Vendor>() { new Vendor() { id = "1" } }); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/odata/Vendor"); ODataModelBuilder builder = new ODataConventionModelBuilder(); builder.EntitySet<Vendor>("Vendor"); var model = builder.GetEdmModel(); HttpRouteCollection routes = new HttpRouteCollection(); HttpConfiguration config = new HttpConfiguration(routes) { IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always };
Thanks for any ideas or pointers!
c # unit-testing odata asp.net-web-api2
kerray
source share