Пример #1
0
        public void ConfigureServicesTest()
        {
            var hostBuilder = new HostBuilder();

            StartupLoader.ConfigureServices(hostBuilder, new EmptyStartup());

            Assert.Throws <InvalidOperationException>(() => StartupLoader.ConfigureServices(hostBuilder, new ConfigureServicesTestStartup0()));

            StartupLoader.ConfigureServices(hostBuilder, new ConfigureServicesTestStartup1());

            Assert.Throws <InvalidOperationException>(() => StartupLoader.ConfigureServices(hostBuilder, new ConfigureServicesTestStartup2()));

            StartupLoader.ConfigureServices(hostBuilder, new ConfigureServicesTestStartup3());

            StartupLoader.ConfigureServices(hostBuilder, new ConfigureServicesTestStartup4());

            Assert.Throws <InvalidOperationException>(() => StartupLoader.ConfigureServices(hostBuilder, new ConfigureServicesTestStartup5()));

            Assert.Throws <InvalidOperationException>(() => StartupLoader.ConfigureServices(hostBuilder, new ConfigureServicesTestStartup6()));

            Assert.Throws <InvalidOperationException>(() => StartupLoader.ConfigureServices(hostBuilder, new ConfigureServicesTestStartup7()));

            Assert.Throws <InvalidOperationException>(() => StartupLoader.ConfigureServices(hostBuilder, new ConfigureServicesTestStartup8()));

            var services = hostBuilder.Build().Services;

            Assert.NotNull(services.GetService <ConfigureServicesTestStartup1>());
            Assert.NotNull(services.GetService <ConfigureServicesTestStartup3>());
            Assert.NotNull(services.GetService <ConfigureServicesTestStartup4>());
        }