public void FromModules_ValidatesArguments()
        {
            // Arrange

            // Act

            // Assert
            Assert.Throws <ArgumentNullException>(() => FrameworkInitialiser.FromModules(null /* modules */, null /* configuration */));
            Assert.Throws <ArgumentNullException>(() => FrameworkInitialiser.FromModules(Array.Empty <IModule>(), null /* configuration */));
        }
        public void FromModules_CreatesFeatureStateProvider()
        {
            // Arrange
            var module        = new TestModule();
            var configuration = new ConfigurationBuilder().Build();

            // Act
            var init = FrameworkInitialiser.FromModules(new IModule[] { module }, configuration);

            // Assert
            Assert.NotNull(init);
            Assert.NotNull(init.FeatureStateProvider);
        }
        public void AddServices_AddsFeatureStateProvider()
        {
            // Arrange
            var module        = new TestModule();
            var configuration = new ConfigurationBuilder().Build();
            var init          = FrameworkInitialiser.FromModules(new IModule[] { module }, configuration);
            var services      = new ServiceCollection();

            // Act
            init.AddServices(services);

            // Assert
            Assert.Contains(services, sd => sd.ServiceType == typeof(IFeatureStateProvider) && sd.Lifetime == ServiceLifetime.Singleton);
        }
        public void AddServices_AddsServicesFromFeatures()
        {
            // Arrange
            var module        = new TestModule();
            var configuration = new ConfigurationBuilder().Build();
            var init          = FrameworkInitialiser.FromModules(new IModule[] { module }, configuration);
            var services      = new ServiceCollection();

            // Act
            init.AddServices(services);

            // Assert
            Assert.Contains(services, sd => sd.ServiceType == typeof(FeatureService));
        }
        public void FromModules_CreatesPartManager()
        {
            // Arrange
            var module        = new TestModule();
            var configuration = new ConfigurationBuilder().Build();

            // Act
            var init = FrameworkInitialiser.FromModules(new IModule[] { module }, configuration);

            // Assert
            Assert.NotNull(init);
            Assert.NotNull(init.PartManager);
            Assert.Contains(init.PartManager.PartFeatureProviders, pfp => pfp is ModulePartFeatureProvider);
            Assert.Contains(init.PartManager.Parts, p => p is AssemblyPart && ((AssemblyPart)p).Assembly == typeof(TestModule).Assembly);
        }
        public void ExtendConfiguration_AddsFeatureConfiguration()
        {
            // Arrange
            var module        = new TestModule();
            var configuration = new ConfigurationBuilder().Build();
            var init          = FrameworkInitialiser.FromModules(new IModule[] { module }, configuration);
            var builder       = new ConfigurationBuilder();
            var context       = new WebHostBuilderContext();

            // Act
            init.ExtendConfiguration(context, builder);

            // Assert
            Assert.Contains(builder.Sources, cs => cs is FeatureConfigurationSource);
        }