public void GetPlugins_Throws_InvalidAssemblyName()
        {
            var enumerator = new AssemblyBotComponentEnumerator(AssemblyLoadContext.Default);

            Assert.Throws <FileLoadException>(
                () => enumerator.GetComponents(componentName: "*//\\-_+!?#$").ToList());
        }
        public void GetPlugins_Throws_AssemblyNotFound()
        {
            var enumerator = new AssemblyBotComponentEnumerator(AssemblyLoadContext.Default);

            Assert.Throws <FileNotFoundException>(
                () => enumerator.GetComponents(componentName: "Fake.Assembly.Name").ToList());
        }
Example #3
0
        internal static void AddBotRuntimeComponents(this IServiceCollection services, IConfiguration configuration)
        {
            var componentDefinitions = configuration
                                       .GetSection($"{ConfigurationConstants.RuntimeSettingsKey}:components")
                                       .Get <List <BotComponentDefinition> >() ?? Enumerable.Empty <BotComponentDefinition>();

            var componentEnumerator = new AssemblyBotComponentEnumerator(AssemblyLoadContext.Default);

            var exceptions = new List <Exception>();

            // Iterate through configured components and load each one
            foreach (BotComponentDefinition component in componentDefinitions)
            {
                try
                {
                    component.Load(componentEnumerator, services, configuration);
                }
#pragma warning disable CA1031 // Do not catch general exception types. We want to capture all exceptions from components and throw them all at once.
                catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
                {
                    exceptions.Add(ex);
                }
            }

            if (exceptions.Any())
            {
                throw new AggregateException("Encountered exceptions while loading bot components.", exceptions);
            }

            // Load internal built-in components
            BuiltInBotComponents.LoadAll(services, configuration);
        }
        public void GetPlugins_Throws_ArgumentNullException(string pluginName)
        {
            var enumerator = new AssemblyBotComponentEnumerator(AssemblyLoadContext.Default);

            Assert.Throws <ArgumentNullException>(
                "componentName",
                () => enumerator.GetComponents(pluginName).ToList());
        }
        public void GetPlugins_Succeeds()
        {
            var enumerator = new AssemblyBotComponentEnumerator(AssemblyLoadContext.Default);

            IList <BotComponent> components = enumerator.GetComponents(Assembly.GetExecutingAssembly().FullName).ToList();

            Assert.Equal(4, components.Count);
            Assert.Contains(components, p => typeof(PublicBotComponent) == p.GetType());
            Assert.Contains(components, p => typeof(AdventureWorksAdapterComponent) == p.GetType());
            Assert.Contains(components, p => typeof(ContosoAdapterComponent) == p.GetType());
            Assert.Contains(components, p => typeof(PirateBotComponent) == p.GetType());
        }