Пример #1
0
        public static IEnumerable <object[]> GetLoadArgumentNullExceptionData()
        {
            var            pluginEnumerator = new TestBotPluginEnumerator();
            var            services         = new ServiceCollection();
            IConfiguration configuration    = new ConfigurationBuilder().Build();

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

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

            yield return(new object[]
            {
                "configuration",
                (IBotPluginEnumerator)pluginEnumerator,
                (IServiceCollection)services,
                (IConfiguration)null
            });
        }
Пример #2
0
 public void Load_Throws_ArgumentNullException(
     string paramName,
     TestBotPluginEnumerator pluginEnumerator,
     IServiceCollection services,
     IConfiguration configuration)
 {
     Assert.Throws <ArgumentNullException>(
         paramName,
         () => new BotPluginDefinition().Load(pluginEnumerator, services, configuration));
 }
Пример #3
0
        public void Load_Throws_NameMissing(string name)
        {
            var pluginEnumerator = new TestBotPluginEnumerator();
            var services         = new ServiceCollection();
            var configuration    = new ConfigurationBuilder().Build();

            Assert.Throws <ArgumentNullException>(
                "pluginName",
                () => new BotPluginDefinition
            {
                Name = name
            }.Load(pluginEnumerator, services, configuration));
        }
Пример #4
0
        public void Load_Succeeds_Services()
        {
            var plugins = new Dictionary <string, ICollection <IBotPlugin> >(StringComparer.OrdinalIgnoreCase)
            {
                {
                    "TestPlugin", new[]
                    {
                        new TestBotPlugin(loadAction: (context) =>
                        {
                            Assert.NotNull(context.Services);
                            Assert.Empty(context.Services);
                            context.Services.AddSingleton <IStorage, MemoryStorage>();
                        }),
                        new TestBotPlugin(loadAction: (context) =>
                        {
                            Assert.NotNull(context.Services);
                            Assert.Empty(context.Services);
                            context.Services.AddSingleton <IChannelProvider, SimpleChannelProvider>();
                        })
                    }
                }
            };

            var            pluginEnumerator = new TestBotPluginEnumerator(plugins);
            var            services         = new ServiceCollection();
            IConfiguration configuration    = new ConfigurationBuilder().Build();

            new BotPluginDefinition
            {
                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);
        }
Пример #5
0
        public void Load_Succeeds_Configuration(
            IConfiguration configuration,
            string settingsPrefix,
            Action <IBotPluginLoadContext> loadAction)
        {
            var plugins = new Dictionary <string, ICollection <IBotPlugin> >(StringComparer.OrdinalIgnoreCase)
            {
                {
                    "TestPlugin", new[] { new TestBotPlugin(loadAction) }
                }
            };

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

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