public void ThrowsException_WithErrorConstructor()
        {
            var options     = new StartupModulesOptions();
            var ex          = Assert.Throws <InvalidOperationException>(() => options.AddStartupModule <StartupModuleWithErrorCtor>());
            var expectedMsg = $"Failed to create instance for {nameof(IStartupModule)} type '{typeof(StartupModuleWithErrorCtor).Name}'.";

            Assert.Equal(expectedMsg, ex.Message);
        }
        public void ThrowsException_WhenNoParameterlessConstructor()
        {
            var options     = new StartupModulesOptions();
            var ex          = Assert.Throws <InvalidOperationException>(() => options.AddStartupModule <StartupModuleWithCtor>());
            var expectedMsg = $"创建实例未 {nameof(IStartupModule)}的实例失败 name: '{typeof(StartupModuleWithCtor).Name}'.";

            Assert.Equal(expectedMsg, ex.Message);
        }
        public void ThrowsException_WhenTypeNotIStartupModule()
        {
            var options    = new StartupModulesOptions();
            var ex         = Assert.Throws <ArgumentException>("type", () => options.AddStartupModule(typeof(decimal)));
            var expectedEx = new ArgumentException($"Specified startup module '{typeof(decimal).Name}' does not implement {nameof(IStartupModule)}.", "type");

            Assert.Equal(expectedEx.Message, ex.Message);
        }
        public void ThrowsException_WithErrorConstructor()
        {
            var options     = new StartupModulesOptions();
            var ex          = Assert.Throws <InvalidOperationException>(() => options.AddStartupModule <StartupModuleWithErrorCtor>());
            var expectedMsg = $"创建实例未 {nameof(IStartupModule)}的实例失败 name: '{typeof(StartupModuleWithErrorCtor).Name}'.";

            //$"Specified startup module '{type.Name}' does not implement {nameof(IStartupModule)}."
            Assert.Equal(expectedMsg, ex.Message);
        }
        public void AddStartupModule_FromInstance()
        {
            var options = new StartupModulesOptions();

            options.AddStartupModule(new FooStartupModule());

            var module = Assert.Single(options.StartupModules);

            Assert.IsType <FooStartupModule>(module);
        }
        public void AddStartupModule_FromGenericType()
        {
            var options = new StartupModulesOptions();

            options.AddStartupModule <FooStartupModule>();

            var module = Assert.Single(options.StartupModules);

            Assert.IsType <FooStartupModule>(module);
        }
示例#7
0
    public void Configures()
    {
        // Arrange
        var options       = new StartupModulesOptions();
        var startupModule = new MyStartupModule();

        options.AddStartupModule(startupModule);
        var runner = new StartupModuleRunner(options);

        // Act
        runner.Configure(new ApplicationBuilder(new ServiceCollection().BuildServiceProvider()), null, null);

        // Assert
        Assert.True(startupModule.Configured);
    }
示例#8
0
    public void ConfiguresServices()
    {
        // Arrange
        var options = new StartupModulesOptions();

        options.AddStartupModule <MyStartupModule>();
        var runner   = new StartupModuleRunner(options);
        var services = new ServiceCollection();

        // Act
        runner.ConfigureServices(services, null, null);

        // Assert
        var sd = Assert.Single(services);

        Assert.Equal(typeof(MyStartupModule.MyService), sd.ImplementationType);
    }