public async Task DisconnectService_UsingNameAndType() { var config = await BotConfiguration.LoadAsync(TestBotFileName); var config2 = new BotConfiguration(); foreach (var service in config.Services) { config2.ConnectService(service); } // Choose a duplicated service and remove the correct one. // We should have at least an ABS and generic service with the name "testAbs". const string name = "testAbs"; var duplicateServices = config2.Services.Where(s => s.Name.Equals(name)).ToArray(); Assert.IsTrue(duplicateServices.Length > 1, "Should have at least two services with this name."); var botService = config2.DisconnectServiceByNameOrId <BotService>(name); Assert.IsNotNull(botService, "Should have removed an ABS service."); // Make sure this operation is not order dependent. config2.ConnectService(botService); var genericService = config2.DisconnectServiceByNameOrId <GenericService>(name); Assert.IsNotNull(genericService, "Should have removed a generic service."); }
public void CanGetOptionalService() { var configuration = new BotConfiguration(); configuration.ConnectService(new LuisService() { AppId = Guid.NewGuid().ToString(), Name = "Production", Region = "WestEurope", SubscriptionKey = Guid.NewGuid().ToString() }); var serviceInstance = configuration.GetService <LuisService>("Production"); Assert.NotNull(serviceInstance); }
public void ReturnsNullForNonExistingOptionalService() { var configuration = new BotConfiguration(); configuration.ConnectService(new LuisService() { AppId = Guid.NewGuid().ToString(), Name = "Production", Region = "WestEurope", SubscriptionKey = Guid.NewGuid().ToString() }); var serviceInstance = configuration.GetService <LuisService>("Development"); Assert.Null(serviceInstance); }
public void CanGetNamedRequiredService() { var configuration = new BotConfiguration(); configuration.ConnectService(new LuisService() { AppId = Guid.NewGuid().ToString(), Name = "Development-luis", Region = "WestEurope", SubscriptionKey = Guid.NewGuid().ToString() }); var serviceInstance = configuration.GetRequiredService <LuisService>("Development", "luis"); Assert.NotNull(serviceInstance); }
public void RaisesExceptionForNonExistingRequiredService() { var configuration = new BotConfiguration(); configuration.ConnectService(new LuisService() { AppId = Guid.NewGuid().ToString(), Name = "Production", Region = "WestEurope", SubscriptionKey = Guid.NewGuid().ToString() }); Assert.Throws <KeyNotFoundException>(() => { configuration.GetRequiredService <LuisService>("Development"); }); }
public void CanLoadLuisService() { var configuration = new BotConfiguration(); var hostingEnvironment = CreateHostingEnvironment(); configuration.ConnectService(new LuisService() { AppId = Guid.NewGuid().ToString(), Name = "luis", Region = "WestEurope", SubscriptionKey = Guid.NewGuid().ToString() }); var botServices = new BotServices(configuration, hostingEnvironment); Assert.Single(botServices.IntentRecognizers); }
public async Task DisconnectByNameOrId_UsingName() { var config = await BotConfiguration.LoadAsync(@"..\..\test.bot"); var config2 = new BotConfiguration(); foreach (var service in config.Services) { config2.ConnectService(service); } var serviceNames = config2.Services.Select(s => s.Name).ToArray(); foreach (var name in serviceNames) { config2.DisconnectServiceByNameOrId(name); } Assert.AreEqual(config2.Services.Count, 0, "didn't remove all services"); }
public void CanLoadQnaMakerService() { var configuration = new BotConfiguration(); var hostingEnvironment = CreateHostingEnvironment(); configuration.ConnectService(new QnAMakerService { SubscriptionKey = Guid.NewGuid().ToString(), EndpointKey = Guid.NewGuid().ToString(), Hostname = "http://localhost", KbId = Guid.NewGuid().ToString(), Name = "knowledgebase" }); var botServices = new BotServices(configuration, hostingEnvironment); Assert.Single(botServices.Knowledgebases); }
public async Task DisconnectServicesByNameOrId_UsingId() { var config = await BotConfiguration.LoadAsync(TestBotFileName); var config2 = new BotConfiguration(); foreach (var service in config.Services) { config2.ConnectService(service); } var servicesIds = config2.Services.Select(s => s.Id).ToArray(); foreach (var id in servicesIds) { config2.DisconnectServiceByNameOrId(id); } Assert.AreEqual(config2.Services.Count, 0, "didn't remove all services"); }
public async Task DisconnectServicesById() { var config = await BotConfiguration.LoadAsync(@"..\..\test.bot"); var config2 = new BotConfiguration(); foreach (var service in config.Services) { config2.ConnectService(service); } var servicesIds = config2.Services.Select(s => s.Id).ToArray(); foreach (var key in servicesIds) { config2.DisconnectService(key); } Assert.AreEqual(config2.Services.Count, 0, "didn't remove all services"); }
public async Task ConnectAssignsUniqueIds() { var config = await BotConfiguration.LoadAsync(@"..\..\test.bot"); var config2 = new BotConfiguration(); foreach (var service in config.Services) { service.Id = "1"; config2.ConnectService(service); } HashSet <string> hashset = new HashSet <string>(); foreach (var service in config2.Services) { Assert.IsFalse(hashset.Contains(service.Id), "the id assigned is not unique for the collection"); hashset.Add(service.Id); } }
public async Task DisconnectServicesByNameOrId_UsingId() { var config = await BotConfiguration.LoadAsync(testBotFileName); var config2 = new BotConfiguration(); foreach (var service in config.Services) { config2.ConnectService(service); } var servicesIds = config2.Services.Select(s => s.Id).ToArray(); foreach (var id in servicesIds) { config2.DisconnectServiceByNameOrId(id); } Assert.Empty(config2.Services); }
public async Task ConnectAssignsUniqueIds() { var config = await BotConfiguration.LoadAsync(testBotFileName); var config2 = new BotConfiguration(); foreach (var service in config.Services) { service.Id = string.Empty; config2.ConnectService(service); } var hashset = new HashSet <string>(); foreach (var service in config2.Services) { Assert.DoesNotContain(service.Id, hashset); hashset.Add(service.Id); } }
public async Task DisconnectByNameOrId_UsingName_WithDuplicates() { // We have a least one duplicate name in the config. var config = await BotConfiguration.LoadAsync(TestBotFileName); var config2 = new BotConfiguration(); var uniqueNames = new List <string>(); var duplicatedNames = new List <string>(); foreach (var service in config.Services) { config2.ConnectService(service); var name = service.Name; if (uniqueNames.Contains(name)) { duplicatedNames.Add(name); } else { uniqueNames.Add(name); } } Assert.IsTrue(duplicatedNames.Count > 0, "The config file should have at least one duplicated service name."); foreach (var name in uniqueNames) { config2.DisconnectServiceByNameOrId(name); } Assert.AreEqual(config2.Services.Count, duplicatedNames.Count, "Extra services (with a duplicated name) should still be connected."); foreach (var name in duplicatedNames) { config2.DisconnectServiceByNameOrId(name); } Assert.AreEqual(config2.Services.Count, 0, "Didn't remove remaining services."); }
public async Task DisconnectByNameOrId_UsingName_WithDuplicates() { // We have a least one duplicate name in the config. var config = await BotConfiguration.LoadAsync(testBotFileName); var config2 = new BotConfiguration(); var uniqueNames = new List <string>(); var duplicatedNames = new List <string>(); foreach (var service in config.Services) { config2.ConnectService(service); var name = service.Name; if (uniqueNames.Contains(name)) { duplicatedNames.Add(name); } else { uniqueNames.Add(name); } } Assert.True(duplicatedNames.Count > 0, "The config file should have at least one duplicated service name."); foreach (var name in uniqueNames) { config2.DisconnectServiceByNameOrId(name); } Assert.Equal(config2.Services.Count, duplicatedNames.Count); foreach (var name in duplicatedNames) { config2.DisconnectServiceByNameOrId(name); } Assert.Empty(config2.Services); }