Example #1
0
        public void UseAspNet()
        {
            var webHostBuildReturned = Mock.Of <IWebHostBuilder>();

            var serviceCollection = new ServiceCollection();

            var builder = new Mock <IWebHostBuilder>(MockBehavior.Strict);

            builder.Setup(b => b.ConfigureServices(It.IsAny <Action <IServiceCollection> >()))
            .Callback((Action <IServiceCollection> configureServices) =>
            {
                configureServices(serviceCollection);
            })
            .Returns(webHostBuildReturned);

            WebHostBuilderAspNetExtensions.UseAspNet(builder.Object, options => { options.Routes.Add("The route"); }).Should().BeSameAs(webHostBuildReturned);

            var serviceDescriptor = serviceCollection.Single(sd => sd.ServiceType == typeof(IServer));

            serviceDescriptor.ImplementationType.Should().BeSameAs(typeof(AspNetServer));
            serviceDescriptor.Lifetime.Should().Be(ServiceLifetime.Singleton);

            var optionsBuilt = serviceCollection.BuildServiceProvider().GetService <IOptions <AspNetServerOptions> >().Value;

            optionsBuilt.Routes.Should().Equal("The route");
        }
Example #2
0
        public void UseAspNet_WithNullOptions_ExceptionThrown()
        {
            Action act = () =>
            {
                WebHostBuilderAspNetExtensions.UseAspNet(Mock.Of <IWebHostBuilder>(), null);
            };

            act.Should().ThrowExactly <ArgumentNullException>()
            .And.ParamName.Should().Be("options");
        }
Example #3
0
        public void UseAspNet_WithNullBuilder_ExceptionThrown()
        {
            Action act = () =>
            {
                WebHostBuilderAspNetExtensions.UseAspNet(null, null);
            };

            act.Should().ThrowExactly <ArgumentNullException>()
            .And.ParamName.Should().Be("builder");
        }