public void CoreBotAdapterRegistered() { // Setup IServiceCollection services = new ServiceCollection(); IConfiguration configuration = new ConfigurationBuilder().Build(); // We do this here since in asp.net core world this is done for us, but here we need to do it manually. services.AddSingleton(configuration); // Test services.AddBotRuntime(configuration); // Assert var provider = services.BuildServiceProvider(); // Core adapter should be register for as IBotFrameworkHttpAdapter for controllers Assertions.AssertService <IBotFrameworkHttpAdapter, CoreBotAdapter>(services, provider, ServiceLifetime.Singleton); // Core adapter should be register for as BotAdapter for Skill HttpClient Assertions.AssertService <BotAdapter, CoreBotAdapter>(services, provider, ServiceLifetime.Singleton); // Adapter settings should be registered for multi-adapter controllers. Assertions.AssertService <AdapterSettings>( services, provider, ServiceLifetime.Singleton, adapterSettings => { Assert.Equal("messages", adapterSettings.Route); Assert.Equal(typeof(CoreBotAdapter).FullName, adapterSettings.Name); Assert.True(adapterSettings.Enabled); }); }
public void AddBotRuntimeTelemetryEnabled() { // Setup IServiceCollection services = new ServiceCollection(); var telemetrySettings = new TelemetrySettings() { Options = new ApplicationInsightsServiceOptions() { ConnectionString = Guid.NewGuid().ToString() } }; IConfiguration configuration = new ConfigurationBuilder().AddRuntimeSettings(new RuntimeSettings() { Telemetry = telemetrySettings }).Build(); services.AddTransient <IHttpContextAccessor, HttpContextAccessor>(); #if NETCOREAPP2_1 services.AddTransient <IHostingEnvironment, HostingEnvironment>(); #elif NETCOREAPP3_1 services.AddTransient <IHostingEnvironment, TestHostingEnvironment>(); #endif // Test services.AddBotRuntimeTelemetry(configuration); // Assert IServiceProvider provider = services.BuildServiceProvider(); Assertions.AssertService <IMiddleware, TelemetryInitializerMiddleware>(services, provider, ServiceLifetime.Singleton); Assertions.AssertService <ITelemetryInitializer, OperationCorrelationTelemetryInitializer>( services, provider, ServiceLifetime.Singleton, searchOptions: ServiceDescriptorSearchOptions .SearchByImplementationType <OperationCorrelationTelemetryInitializer>()); Assertions.AssertService <ITelemetryInitializer, TelemetryBotIdInitializer>( services, provider, ServiceLifetime.Singleton, searchOptions: ServiceDescriptorSearchOptions .SearchByImplementationType <TelemetryBotIdInitializer>()); Assertions.AssertService <IBotTelemetryClient, BotTelemetryClient>( services, provider, ServiceLifetime.Singleton); }
public void AddBotRuntimeTelemetryDisabled(object settings) { // Setup IServiceCollection services = new ServiceCollection(); var telemetrySettings = settings as TelemetrySettings; // Test services.AddBotRuntimeTelemetry(telemetrySettings); // Assert IServiceProvider provider = services.BuildServiceProvider(); Assertions.AssertService <IBotTelemetryClient, NullBotTelemetryClient>(services, provider, ServiceLifetime.Singleton); }
public async Task AddBotRuntimeSkills(object settings, string appId, Type exceptionType) { // Setup IServiceCollection services = new ServiceCollection(); services.AddSingleton <IStorage, MemoryStorage>(); services.AddSingleton <SkillConversationIdFactoryBase, SkillConversationIdFactory>(); services.AddSingleton(sp => BotFrameworkAuthenticationFactory.Create()); services.AddSingleton <BotAdapter, CloudAdapter>(); services.AddSingleton <IBot, ActivityHandler>(); var skillSettings = settings as SkillSettings; IConfiguration configuration = new ConfigurationBuilder().AddRuntimeSettings(new RuntimeSettings() { Skills = skillSettings }).Build(); // Test services.AddBotRuntimeSkills(configuration); // Assert var provider = services.BuildServiceProvider(); Assertions.AssertService <SkillConversationIdFactoryBase, SkillConversationIdFactory>(services, provider, ServiceLifetime.Singleton); Assertions.AssertService <ChannelServiceHandlerBase, CloudSkillHandler>(services, provider, ServiceLifetime.Singleton); Assertions.AssertService <AuthenticationConfiguration>( services, provider, ServiceLifetime.Singleton, async authConfig => { var versionClaim = new Claim(AuthenticationConstants.VersionClaim, "1.0"); var appIdClaim = new Claim(AuthenticationConstants.AppIdClaim, appId); if (exceptionType == null) { await authConfig.ClaimsValidator.ValidateClaimsAsync(new Claim[] { versionClaim, appIdClaim }); } else { await Assert.ThrowsAsync(exceptionType, () => authConfig.ClaimsValidator.ValidateClaimsAsync(new Claim[] { versionClaim, appIdClaim })); } }); await Task.CompletedTask; }
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); }
public void AddBotRuntimeTelemetryDisabled(object settings) { // Setup IServiceCollection services = new ServiceCollection(); var telemetrySettings = settings as TelemetrySettings; IConfiguration configuration = new ConfigurationBuilder().AddRuntimeSettings(new RuntimeSettings() { Telemetry = telemetrySettings }).Build(); // Test services.AddBotRuntimeTelemetry(configuration); // Assert IServiceProvider provider = services.BuildServiceProvider(); Assertions.AssertService <IBotTelemetryClient, NullBotTelemetryClient>(services, provider, ServiceLifetime.Singleton); }
public void CoreBotAdapterRegistered() { // Setup IServiceCollection services = new ServiceCollection(); IConfiguration configuration = new ConfigurationBuilder().Build(); // We do this here since in asp.net core world this is done for us, but here we need to do it manually. services.AddSingleton(configuration); // Test services.AddBotRuntime(configuration); // Assert var provider = services.BuildServiceProvider(); // Core adapter should be register for as IBotFrameworkHttpAdapter for controllers Assertions.AssertService <IBotFrameworkHttpAdapter, CoreBotAdapter>(services, provider, ServiceLifetime.Singleton); // Core adapter should be register for as BotAdapter for Skill HttpClient Assertions.AssertService <BotAdapter, CoreBotAdapter>(services, provider, ServiceLifetime.Singleton); }