public void ConfigureServices_is_noop_when_not_found()
        {
            var startup = CreateStartupInvoker(MockAssembly.Create());

            var services = startup.ConfigureServices();

            Assert.NotNull(services);
        }
Пример #2
0
        public void ConfigureDesignTimeServices_is_noop_when_not_found()
        {
            var startup = CreateStartupInvoker(
                MockAssembly.Create(),
                "Unknown");

            startup.ConfigureDesignTimeServices(new ServiceCollection());
        }
Пример #3
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 ConfigureServices_works()
        {
            var startup = CreateStartupInvoker(MockAssembly.Create(typeof(StartupDevelopment)));

            var services = startup.ConfigureServices();

            var service = services.GetRequiredService <TestService>();

            Assert.Equal("Development", service.Value);
        }
Пример #5
0
        public void CreateContext_get_service()
        {
            var assembly   = MockAssembly.Create(typeof(Startup));
            var operations = new DbContextOperations(
                new TestOperationReporter(),
                assembly,
                assembly);

            operations.CreateContext(typeof(TestContext).FullName);
        }
        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>());
        }
Пример #7
0
        public void ConfigureServices_injects_services()
        {
            var assembly = MockAssembly.Create(typeof(StartupInjected));
            var startup  = new StartupInvoker(assembly, "Injected", @"C:\The\Right\Path");

            var services = startup.ConfigureServices();
            var service  = services.GetRequiredService <TestService>();

            Assert.Equal("Injected", service.Value);
        }
        public void CreateContext_gets_service()
        {
            var assembly   = MockAssembly.Create(typeof(TestProgram), typeof(TestContext));
            var operations = new TestDbContextOperations(
                new TestOperationReporter(),
                assembly,
                assembly,
                new TestAppServiceProviderFactory(assembly, typeof(TestProgram)));

            operations.CreateContext(typeof(TestContext).FullName);
        }
 public ModelBuilderAssemblyScanTest()
 {
     _mockEntityTypeAssembly = MockAssembly.Create(
         typeof(ScannerCustomerEntityConfiguration), typeof(ScannerCustomerEntityConfiguration2),
         typeof(AbstractCustomerEntityConfiguration), typeof(AbstractCustomerEntityConfigurationImpl));
     _mockQueryTypeAssembly = MockAssembly.Create(
         typeof(ScannerCustomerQueryConfiguration), typeof(ScannerCustomerQueryConfiguration2),
         typeof(AbstractCustomerQueryConfiguration), typeof(AbstractCustomerEntityQueryConfigurationImpl));
     _mockMixedTypeAssembly = MockAssembly.Create(
         typeof(ScannerCustomerEntityConfiguration), typeof(ScannerCustomer2QueryConfiguration));
 }
Пример #10
0
        public void ConfigureDesignTimeServices_works_on_IStartup_implementations()
        {
            var startup = CreateStartupInvoker(
                MockAssembly.Create(typeof(MyStartup)),
                environment: null);

            var services = startup.ConfigureServices();
            var service  = services.GetRequiredService <TestService>();

            Assert.Equal("MyStartup", service.Value);
        }
Пример #11
0
        private static TestDbContextOperations CreateOperations(Type testProgramType)
        {
            var assembly = MockAssembly.Create(testProgramType, typeof(TestContext));

            return(new TestDbContextOperations(
                       new TestOperationReporter(),
                       assembly,
                       assembly,
                       /* args: */ Array.Empty <string>(),
                       new TestAppServiceProviderFactory(assembly)));
        }
        public void ConfigureDesignTimeServices_works_on_IDesignTimeServices_implementations()
        {
            var services = new ServiceCollection();
            var startup  = CreateStartupInvoker(MockAssembly.Create(typeof(DesignTimeServices)));

            startup.ConfigureDesignTimeServices(services);

            var service = services.BuildServiceProvider().GetRequiredService <TestService>();

            Assert.Equal("DesignTimeServices", service.Value);
        }
Пример #13
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>());
        }
        public void ConfigureServices_injects_services()
        {
            var assembly = MockAssembly.Create(typeof(StartupInjected));
            var startup  = new StartupInvoker(
                new TestOperationReporter(),
                assembly);

            var services = startup.ConfigureServices();
            var service  = services.GetRequiredService <TestService>();

            Assert.Equal("Injected", service.Value);
        }
Пример #15
0
        public void ConfigureServices_invokes_method_with_alternative_signature()
        {
            var startup = CreateStartupInvoker(
                MockAssembly.Create(typeof(StartupAlternative)),
                "Alternative");

            var services = startup.ConfigureServices();

            var service = services.GetRequiredService <TestService>();

            Assert.Equal("Alternative", service.Value);
        }
Пример #16
0
        public void ConfigureServices_uses_Development_environment_when_unspecified()
        {
            var startup = CreateStartupInvoker(
                MockAssembly.Create(typeof(StartupDevelopment)),
                environment: null);

            var services = startup.ConfigureServices();

            var service = services.GetRequiredService <TestService>();

            Assert.Equal("Development", service.Value);
        }
Пример #17
0
        public void ConfigureServices_invokes_static_methods()
        {
            var startup = CreateStartupInvoker(
                MockAssembly.Create(typeof(StartupStatic)),
                "Static");

            var services = startup.ConfigureServices();

            var service = services.GetRequiredService <TestService>();

            Assert.Equal("Static", service.Value);
        }
Пример #18
0
        public void ConfigureDesignTimeServices_works_on_other_types()
        {
            var services = new ServiceCollection();
            var startup  = CreateStartupInvoker(
                MockAssembly.Create(typeof(NotStartup)),
                environment: null);

            startup.ConfigureDesignTimeServices(typeof(NotStartup), services);

            var service = services.BuildServiceProvider().GetRequiredService <TestService>();

            Assert.Equal("NotStartup", service.Value);
        }
Пример #19
0
        public void Can_pass_null_args()
        {
            // Even though newer versions of the tools will pass an empty array
            // older versions of the tools can pass null args.
            var assembly = MockAssembly.Create(typeof(TestContext));

            _ = new TestDbContextOperations(
                new TestOperationReporter(),
                assembly,
                assembly,
                args: null,
                new TestAppServiceProviderFactory(assembly));
        }
Пример #20
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>());
        }
Пример #21
0
        public void ConfigureDesignTimeServices_invokes_static_methods()
        {
            var services = new ServiceCollection();
            var startup  = CreateStartupInvoker(
                MockAssembly.Create(typeof(StartupStatic)),
                "Static");

            startup.ConfigureDesignTimeServices(services);

            var service = services.BuildServiceProvider().GetRequiredService <TestService>();

            Assert.Equal("Static", service.Value);
        }
Пример #22
0
        public void ConfigureDesignTimeServices_uses_Development_environment_when_unspecified()
        {
            var services = new ServiceCollection();
            var startup  = CreateStartupInvoker(
                MockAssembly.Create(typeof(StartupDevelopment)),
                environment: null);

            startup.ConfigureDesignTimeServices(services);

            var service = services.BuildServiceProvider().GetRequiredService <TestService>();

            Assert.Equal("Development", service.Value);
        }
Пример #23
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);
        }
Пример #24
0
        public void ConfigureServices_injects_services()
        {
            var assembly = MockAssembly.Create(typeof(StartupInjected));
            var startup  = new StartupInvoker(
                new LazyRef <ILogger>(() => new LoggerFactory().CreateLogger("Test")),
                assembly,
                "Injected",
                @"C:\The\Right\Path");

            var services = startup.ConfigureServices();
            var service  = services.GetRequiredService <TestService>();

            Assert.Equal("Injected", service.Value);
        }
Пример #25
0
        public void Can_pass_null_args()
        {
            // Even though newer versions of the tools will pass an empty array
            // older versions of the tools can pass null args.
            var assembly = MockAssembly.Create(typeof(TestContext));

            _ = new TestDatabaseOperations(
                new TestOperationReporter(),
                assembly,
                assembly,
                "projectDir",
                "RootNamespace",
                "C#",
                args: null);
        }
Пример #26
0
        public void GetConstructibleTypes_works()
        {
            var assembly = MockAssembly.Create(
                typeof(SomeAbstractClass),
                typeof(SomeGenericClass <>),
                typeof(SomeGenericClass <int>),
                typeof(SomeTypeWithoutDefaultCtor));

            var types = assembly.GetConstructibleTypes().Select(t => t.AsType()).ToList();

            Assert.DoesNotContain(typeof(SomeAbstractClass), types);
            Assert.DoesNotContain(typeof(SomeGenericClass <>), types);
            Assert.Contains(typeof(SomeGenericClass <int>), types);
            Assert.Contains(typeof(SomeTypeWithoutDefaultCtor), types);
        }
Пример #27
0
        private static TestDbContextOperations CreateOperations(Type testProgramType)
        {
            var assembly = MockAssembly.Create(testProgramType, typeof(TestContext));

            return(new TestDbContextOperations(
                       new TestOperationReporter(),
                       assembly,
                       assembly,
                       projectDir: "",
                       rootNamespace: null,
                       language: "C#",
                       nullable: false,
                       /* args: */ Array.Empty <string>(),
                       new TestAppServiceProviderFactory(assembly)));
        }
Пример #28
0
        public void Can_pass_null_args()
        {
            // Even though newer versions of the tools will pass an empty array
            // older versions of the tools can pass null args.
            var assembly = MockAssembly.Create(typeof(TestContext));

            _ = new TestDbContextOperations(
                new TestOperationReporter(),
                assembly,
                assembly,
                projectDir: "",
                rootNamespace: null,
                language: "C#",
                nullable: false,
                args: null,
                new TestAppServiceProviderFactory(assembly));
        }
        public void Invoke_warns_on_error()
        {
            var reporter = new TestOperationReporter();

            var startup = new StartupInvoker(
                reporter,
                MockAssembly.Create(typeof(BadStartup)));

            var services = startup.ConfigureServices();

            Assert.NotNull(services);
            Assert.Equal(
                "warn: " + DesignStrings.InvokeStartupMethodFailed(
                    "ConfigureServices",
                    nameof(BadStartup),
                    "Something went wrong."),
                reporter.Messages[0]);
        }
Пример #30
0
        public void CreateContext_uses_exact_factory_method()
        {
            var assembly   = MockAssembly.Create(typeof(BaseContext), typeof(DerivedContext), typeof(HierarchyContextFactory));
            var operations = new TestDbContextOperations(
                new TestOperationReporter(),
                assembly,
                assembly,
                args: Array.Empty <string>(),
                new TestAppServiceProviderFactory(assembly));

            var baseContext = Assert.IsType <BaseContext>(operations.CreateContext(nameof(BaseContext)));

            Assert.Equal(nameof(BaseContext), baseContext.FactoryUsed);

            var derivedContext = Assert.IsType <DerivedContext>(operations.CreateContext(nameof(DerivedContext)));

            Assert.Equal(nameof(DerivedContext), derivedContext.FactoryUsed);
        }