Exemplo n.º 1
0
        public void Create_works_when_no_BuildWebHost()
        {
            var factory = new TestAppServiceProviderFactory(
                MockAssembly.Create(typeof(ProgramWithoutBuildWebHost)));

            var services = factory.Create(Array.Empty <string>());

            Assert.NotNull(services);
        }
Exemplo n.º 2
0
        private static void TestCreateServices(Type programType)
        {
            var factory = new TestAppServiceProviderFactory(
                MockAssembly.Create(programType));

            Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", null);
            Environment.SetEnvironmentVariable("DOTNET_ENVIRONMENT", null);
            var services = factory.Create(new[] { "arg1" });

            Assert.NotNull(services.GetRequiredService <TestService>());
        }
Exemplo n.º 3
0
        public void Create_with_no_builder_method()
        {
            var factory = new TestAppServiceProviderFactory(
                MockAssembly.Create(
                    new[] { typeof(ProgramWithNoHostBuilder) },
                    new MockMethodInfo(typeof(ProgramWithNoHostBuilder), InjectHostIntoDiagnostics)));

            Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", null);
            Environment.SetEnvironmentVariable("DOTNET_ENVIRONMENT", null);
            var services = factory.Create(new[] { "arg1" });

            Assert.NotNull(services.GetRequiredService <TestService>());
        }
Exemplo n.º 4
0
        public void Create_works_when_BuildWebHost_throws()
        {
            var reporter = new TestOperationReporter();
            var factory  = new TestAppServiceProviderFactory(
                MockAssembly.Create(typeof(ProgramWithThrowingBuildWebHost)),
                reporter);

            var services = factory.Create(Array.Empty <string>());

            Assert.NotNull(services);
            Assert.Contains(
                "warn: " + DesignStrings.InvokeCreateHostBuilderFailed("This is a test."),
                reporter.Messages);
        }