Exemple #1
0
        public static IEnumerable <object[]> GetLoadArgumentNullExceptionData()
        {
            var            pluginEnumerator = new TestBotComponentEnumerator();
            var            services         = new ServiceCollection();
            IConfiguration configuration    = new ConfigurationBuilder().Build();

            yield return(new object[]
            {
                "pluginEnumerator",
                (IBotComponentEnumerator)null,
                (IServiceCollection)services,
                (IConfiguration)configuration
            });

            yield return(new object[]
            {
                "services",
                (IBotComponentEnumerator)pluginEnumerator,
                (IServiceCollection)null,
                (IConfiguration)configuration
            });

            yield return(new object[]
            {
                "configuration",
                (IBotComponentEnumerator)pluginEnumerator,
                (IServiceCollection)services,
                (IConfiguration)null
            });
        }
Exemple #2
0
 public void Load_Throws_ArgumentNullException(
     string paramName,
     TestBotComponentEnumerator pluginEnumerator,
     IServiceCollection services,
     IConfiguration configuration)
 {
     Assert.Throws <ArgumentNullException>(
         paramName,
         () => new BotComponentDefinition().Load(pluginEnumerator, services, configuration));
 }
Exemple #3
0
        public void Load_Throws_NameMissing(string name)
        {
            var pluginEnumerator = new TestBotComponentEnumerator();
            var services         = new ServiceCollection();
            var configuration    = new ConfigurationBuilder().Build();

            Assert.Throws <ArgumentNullException>(
                "componentName",
                () => new BotComponentDefinition
            {
                Name = name
            }.Load(pluginEnumerator, services, configuration));
        }
Exemple #4
0
        public void Load_Succeeds_Services()
        {
            var components = new Dictionary <string, ICollection <BotComponent> >(StringComparer.OrdinalIgnoreCase)
            {
                {
                    "TestPlugin", new[]
                    {
                        new TestBotComponent(loadAction: (services, configuration) =>
                        {
                            Assert.NotNull(services);
                            Assert.Empty(services);
                            services.AddSingleton <IStorage, MemoryStorage>();
                        }),
                        new TestBotComponent(loadAction: (services, configuration) =>
                        {
                            Assert.NotNull(services);
                            Assert.Empty(services);
                            services.AddSingleton <IChannelProvider, SimpleChannelProvider>();
                        })
                    }
                }
            };

            var            pluginEnumerator = new TestBotComponentEnumerator(components);
            var            services         = new ServiceCollection();
            IConfiguration configuration    = new ConfigurationBuilder().Build();

            new BotComponentDefinition
            {
                Name = "TestPlugin"
            }.Load(pluginEnumerator, services, configuration);

            IServiceProvider provider = services.BuildServiceProvider();

            Assertions.AssertService <IStorage, MemoryStorage>(
                services,
                provider,
                ServiceLifetime.Singleton);

            Assertions.AssertService <IChannelProvider, SimpleChannelProvider>(
                services,
                provider,
                ServiceLifetime.Singleton);
        }
Exemple #5
0
        public void Load_Succeeds_Configuration(
            IConfiguration configuration,
            string settingsPrefix,
            Action <IServiceCollection, IConfiguration> loadAction)
        {
            var plugins = new Dictionary <string, ICollection <BotComponent> >(StringComparer.OrdinalIgnoreCase)
            {
                {
                    "TestPlugin", new[] { new TestBotComponent(loadAction) }
                }
            };

            var pluginEnumerator = new TestBotComponentEnumerator(plugins);
            var services         = new ServiceCollection();

            new BotComponentDefinition
            {
                Name           = "TestPlugin",
                SettingsPrefix = settingsPrefix
            }.Load(pluginEnumerator, services, configuration);
        }