Exemple #1
0
        public void UseModules_ValidatesArguments()
        {
            // Arrange
            var builder = new TestWebHostBuilder();

            // Act

            // Assert
            Assert.Throws <ArgumentNullException>(() => ModuleWebHostBuilderExtensions.UseModules(null /* builder */, (IModule[])null /* modules */));
            Assert.Throws <ArgumentNullException>(() => ModuleWebHostBuilderExtensions.UseModules(builder, (IModule[])null /* modules */));
        }
Exemple #2
0
        public void UseModules_AddsPartManager_ToServiceCollection()
        {
            // Arrange
            var builder = new TestWebHostBuilder();

            // Act
            ModuleWebHostBuilderExtensions.UseModules(builder);

            // Assert
            var descriptor = builder.Services.FirstOrDefault(sd => sd.ServiceType == typeof(IPartManager));

            Assert.NotNull(descriptor);
        }
Exemple #3
0
        public void UseModules_AddsModuleProvider_ToServiceCollection_WithProvidedModules()
        {
            // Arrange
            var builder = new TestWebHostBuilder();
            var module  = new TestModule();


            // Act
            ModuleWebHostBuilderExtensions.UseModules(builder, module);

            // Assert
            var descriptor = builder.Services.FirstOrDefault(sd => sd.ServiceType == typeof(IModuleProvider));

            Assert.NotNull(descriptor);

            var provider = (IModuleProvider)descriptor.ImplementationInstance;

            Assert.Equal(1, provider.Modules.Count);
            Assert.Contains(provider.Modules, m => m == module);
        }
Exemple #4
0
        public void UseModules_AddsPartManager_ToServiceCollection_WithProvidedModuleAssemblyParts()
        {
            // Arrange
            var builder = new TestWebHostBuilder();
            var module  = new TestModule();

            // Act
            ModuleWebHostBuilderExtensions.UseModules(builder, module);

            // Assert
            var descriptor = builder.Services.FirstOrDefault(sd => sd.ServiceType == typeof(IPartManager));

            Assert.NotNull(descriptor);

            var manager = (IPartManager)descriptor.ImplementationInstance;

            Assert.Equal(1, manager.Parts.Count);

            var assemblyPart = (AssemblyPart)manager.Parts[0];

            Assert.Equal(GetType().Assembly, assemblyPart.Assembly);
        }