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 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);
        }
Example #3
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);
        }
        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]);
        }
Example #5
0
        public DbContextOperations(
            [NotNull] ILoggerProvider loggerProvider,
            [NotNull] string assemblyName,
            [NotNull] string startupAssemblyName,
            [CanBeNull] string environment)
        {
            Check.NotNull(loggerProvider, nameof(loggerProvider));
            Check.NotEmpty(assemblyName, nameof(assemblyName));
            Check.NotEmpty(startupAssemblyName, nameof(startupAssemblyName));

            _loggerProvider      = loggerProvider;
            _assemblyName        = assemblyName;
            _startupAssemblyName = startupAssemblyName;
            _logger = new LazyRef <ILogger>(() => _loggerProvider.CreateCommandsLogger());

            var startup = new StartupInvoker(startupAssemblyName, environment);

            _runtimeServices = startup.ConfigureServices();
        }
Example #6
0
        public void Invoke_warns_on_error()
        {
            var log = new List <Tuple <LogLevel, string> >();

            var startup = new StartupInvoker(
                new LazyRef <ILogger>(() => new ListLoggerFactory(log).CreateLogger("Test")),
                MockAssembly.Create(typeof(BadStartup)),
                /*environment:*/ null,
                "Irrelevant");

            var services = startup.ConfigureServices();

            Assert.NotNull(services);
            Assert.Equal(
                DesignCoreStrings.InvokeStartupMethodFailed(
                    "ConfigureServices",
                    nameof(BadStartup),
                    "Something went wrong."),
                log[0].Item2);
        }
Example #7
0
        public DbContextOperations([NotNull] ILoggerProvider loggerProvider,
                                   [NotNull] Assembly assembly,
                                   [NotNull] Assembly startupAssembly,
                                   [CanBeNull] string environment,
                                   [NotNull] string contentRootPath)
        {
            Check.NotNull(loggerProvider, nameof(loggerProvider));
            Check.NotNull(assembly, nameof(assembly));
            Check.NotNull(startupAssembly, nameof(startupAssembly));
            Check.NotEmpty(contentRootPath, nameof(contentRootPath));

            _loggerProvider  = loggerProvider;
            _assembly        = assembly;
            _startupAssembly = startupAssembly;
            _environment     = environment;
            _contentRootPath = contentRootPath;
            _logger          = new LazyRef <ILogger>(() => _loggerProvider.CreateCommandsLogger());

            var startup = new StartupInvoker(_logger, startupAssembly, environment, contentRootPath);

            _runtimeServices = startup.ConfigureServices();
        }
        public DbContextOperations(
            [NotNull] ILoggerProvider loggerProvider,
            [NotNull] Assembly assembly,
            [NotNull] Assembly startupAssembly,
            [NotNull] string projectDir,
            [CanBeNull] string environment)
        {
            Check.NotNull(loggerProvider, nameof(loggerProvider));
            Check.NotNull(assembly, nameof(assembly));
            Check.NotNull(startupAssembly, nameof(startupAssembly));
            Check.NotEmpty(projectDir, nameof(projectDir));

            _loggerProvider  = loggerProvider;
            _assembly        = assembly;
            _startupAssembly = startupAssembly;
            _projectDir      = projectDir;
            _logger          = new LazyRef <ILogger>(() => _loggerProvider.CreateCommandsLogger());

            var startup = new StartupInvoker(startupAssembly, environment);

            _runtimeServices = startup.ConfigureServices();

            _servicesBuilder = new DesignTimeServicesBuilder(startup);
        }