public void CreateService_TypeActivatesImplementationType() { // Arrange var value = "Some value"; var uri = new Uri("http://www.asp.net"); var serviceProvider = new ServiceCollection() .AddSingleton(value) .AddSingleton(uri) .BuildServiceProvider(); var typeFilter = new TypeFilterAttribute(typeof(TestFilter)); // Act var filter = typeFilter.CreateInstance(serviceProvider); // Assert var testFilter = Assert.IsType <TestFilter>(filter); Assert.Same(value, testFilter.Value); Assert.Same(uri, testFilter.Uri); }
public void CreateService_UnwrapsFilterFactory() { // Arrange var value = "Some value"; var uri = new Uri("http://www.asp.net"); var serviceProvider = new ServiceCollection() .AddSingleton("Value in DI") .AddSingleton(uri) .BuildServiceProvider(); var typeFilter = new TypeFilterAttribute(typeof(TestFilterFactory)) { Arguments = new[] { value, } }; // Act var filter = typeFilter.CreateInstance(serviceProvider); // Assert var testFilter = Assert.IsType <TestFilter>(filter); Assert.Same(value, testFilter.Value); Assert.Same(uri, testFilter.Uri); }