private static HttpClient GetClient(DependencyInjectionModel instance) { HttpConfiguration config = new[] { typeof(DependencyInjectionModelsController) }.GetHttpConfiguration(); IEdmModel model = GetEdmModel(); config.MapODataServiceRoute("odata", "odata", builder => builder.AddService(ServiceLifetime.Singleton, sp => instance) .AddService(ServiceLifetime.Singleton, sp => model) .AddService <IEnumerable <IODataRoutingConvention> >(ServiceLifetime.Singleton, sp => ODataRoutingConventions.CreateDefaultWithAttributeRouting("odata", config))); return(new HttpClient(new HttpServer(config))); }
public void CanAccessContainer_InODataController() { // Arrange const string Uri = "http://localhost/odata/DependencyInjectionModels"; int randomId = new Random().Next(); DependencyInjectionModel instance = new DependencyInjectionModel { Id = randomId }; HttpClient client = GetClient(instance); // Act HttpResponseMessage response = client.GetAsync(Uri).Result; // Assert Assert.True(response.IsSuccessStatusCode); var result = JObject.Parse(response.Content.ReadAsStringAsync().Result); Assert.Equal("http://localhost/odata/$metadata#DependencyInjectionModels/$entity", result["@odata.context"]); Assert.Equal(randomId, result["Id"]); }