public void UseServiceProvider() { var application = new HttpApplicationMock(); var service = Mock.Of <IService>(); var serviceProvider = new Mock <IServiceProvider>(MockBehavior.Strict); serviceProvider.Setup(sp => sp.GetService(typeof(IService))) .Returns(service); var returnedApplication = HttpApplicationExtensions.UseServiceProvider(application, serviceProvider.Object); returnedApplication.Should().BeSameAs(application); // Checks the WebObjectActivator has been defined correctly HttpRuntime.WebObjectActivator.Should().BeOfType <ServiceProviderAdapter>(); // Checks the services HttpRuntime.WebObjectActivator.GetService(typeof(IService)).Should().BeSameAs(service); // Checks the next provider in the adapter has been defined correctly HttpRuntime.WebObjectActivator.GetFieldValue <IServiceProvider>("nextProvider").Should().BeSameAs(this.existingProvider); // Checks the adapter has been registered on the hosting environment infrastructure typeof(HostingEnvironment).GetStaticValue <object>("_theHostingEnvironment").GetFieldValue <Hashtable>("_registeredObjects").ContainsKey(HttpRuntime.WebObjectActivator); typeof(HostingEnvironment).GetStaticValue <object>("_theHostingEnvironment").GetFieldValue <Hashtable>("_registeredObjects").ContainsValue(HttpRuntime.WebObjectActivator); }
public void UseServiceProvider_WithNullServiceProvider_ExceptionThrown() { Action act = () => { HttpApplicationExtensions.UseServiceProvider(new HttpApplication(), null); }; act.Should().Throw <ArgumentNullException>() .And.ParamName.Should().Be("serviceProvider"); }