Beispiel #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);
        }
        public void Create_works()
        {
            var factory = new TestAppServiceProviderFactory(
                MockAssembly.Create(typeof(Program)));

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

            Assert.NotNull(services.GetRequiredService <TestService>());
        }
    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>());
    }
    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>());
    }
Beispiel #5
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);
        }