public void GetServices_NotPass_EmptyDatabase() { //Arrange var expected = false; var actual = false; ICollection <ServiceDisplayResp> registeredServices; var option = new DbContextOptionsBuilder <ApiGatewayContext>() .UseInMemoryDatabase(databaseName: "ServiceDiscoveryService.GetServices_Empty_database") .Options; //Act using (var context = new ApiGatewayContext(option)) { var serviceDiscoverService = new ServiceDiscoveryService(context); registeredServices = serviceDiscoverService.GetServices(GenerateRandomKey(Int32.Parse(Environment.GetEnvironmentVariable("APIKeyInputLength", EnvironmentVariableTarget.User)))); } //Since input is invalid, the registeredServices should be null if (registeredServices != null) { actual = true; } //Assert Assert.AreEqual(expected, actual); }
/// <summary> /// Get a list of available services for a client based on the clientId /// </summary> /// <param name="clientId">the clientId from front end that login to the system to view services</param> /// <returns>resultSet a list of services that are open to the client based on clientId</returns> public ICollection <ServiceDisplayResp> GetAvailableServices(string clientId) { ICollection <ServiceDisplayResp> resultSet = null; if (String.IsNullOrWhiteSpace(clientId) || clientId.Length != Constants.clientIdLength) { return(null); } if (_serviceDiscoveryService.IfClientExist(clientId)) { resultSet = _serviceDiscoveryService.GetServices(clientId); } return(resultSet); }
public void GetServices_NotPass_WhiteSpaceInput() { //Arrange var expected = false; var actual = false; ICollection <ServiceDisplayResp> registeredServices; //Act using (var context = new ApiGatewayContext()) { var serviceDiscoverService = new ServiceDiscoveryService(context); registeredServices = serviceDiscoverService.GetServices(""); } //Since input is invalid, the registeredServices should be null if (registeredServices != null) { actual = true; } //Assert Assert.AreEqual(expected, actual); }
public void GetServices_InMemory_Pass() { //Arrange var expected = true; var actual = false; var option = new DbContextOptionsBuilder <ApiGatewayContext>() .UseInMemoryDatabase(databaseName: "ServiceDiscoveryService.GetServices_Pass_Database") .Options; ICollection <ServiceDisplayResp> registeredServices; //Act using (var context = new ApiGatewayContext(option)) { // Create a team first var teamForTesting = new Team(); var randomId = GenerateRandomKey(Int32.Parse(Environment.GetEnvironmentVariable("APIKeyInputLength", EnvironmentVariableTarget.User))); teamForTesting.ClientId = randomId; teamForTesting.WebsiteUrl = "testingWebSiteUrl"; teamForTesting.Secret = "testingSecret"; teamForTesting.CallbackUrl = "testingCallBackUrl"; teamForTesting.Digest = "testingDigest"; teamForTesting.Username = "******"; context.Team.Add(teamForTesting); //Service var serviceForTesting = new Service(); serviceForTesting.Endpoint = "testingEndPoint"; serviceForTesting.Owner = randomId;//need to be the same as team's ClineId serviceForTesting.Id = 12345678; serviceForTesting.Input = "int"; serviceForTesting.Output = "int"; serviceForTesting.Dataformat = "xml"; serviceForTesting.Description = "Some description for testing"; context.Service.Add(serviceForTesting); //Configuration var configForTesting = new Configuration(); configForTesting.EndPoint = "testingEndPoint";//need to be the same as service configForTesting.OpenTo = randomId; configForTesting.Steps = "some steps for testing"; context.Configuration.Add(configForTesting); context.SaveChanges(); var serviceDiscoverService = new ServiceDiscoveryService(context); registeredServices = serviceDiscoverService.GetServices(randomId); if (registeredServices.Count > 0) { actual = true; } } foreach (var service in registeredServices) { Trace.WriteLine(service.Endpoint + " " + service.Username + " " + service.Input + " " + service.Output + " " + service.Dataformat + " " + service.Description + Environment.NewLine); } //Assert Assert.AreEqual(expected, actual); }
public async Task <IEnumerable <Service> > Get() => await serviceDiscoveryService.GetServices();