private static HttpClient GetClient(DependencyInjectionModel instance) { var config = RoutingConfigurationFactory.CreateWithTypes(new[] { typeof(DependencyInjectionModelsController) }); 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 async Task 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 = await client.GetAsync(Uri); // Assert Assert.True(response.IsSuccessStatusCode); var result = JObject.Parse(await response.Content.ReadAsStringAsync()); Assert.Equal("http://localhost/odata/$metadata#DependencyInjectionModels/$entity", result["@odata.context"]); Assert.Equal(randomId, result["Id"]); }