Esempio n. 1
0
        public void GetServices_NotPass_NullInput()
        {   //Arrange
            var expected = false;
            var actual   = false;
            ICollection <ServiceDisplayResp> registeredServices;

            //Act
            using (var context = new ApiGatewayContext())
            {
                var serviceDiscoveryService = new ServiceDiscoveryService(context);
                var serviceDiscoveryManager = new ServiceDiscoveryManager(serviceDiscoveryService);
                registeredServices = serviceDiscoveryManager.GetAvailableServices(null);
            }



            //Since input is invalid, the registeredServices should be null
            if (registeredServices != null)
            {
                actual = true;
            }

            //Assert
            Assert.AreEqual(expected, actual);
        }
Esempio n. 2
0
        public void GetServices_NotPass_EmptyDatabase()
        {   //Arrange
            var expected = false;
            var actual   = false;
            ICollection <ServiceDisplayResp> registeredServices;
            var option = new DbContextOptionsBuilder <ApiGatewayContext>()
                         .UseInMemoryDatabase(databaseName: "ServiceDiscoveryManager.GetServices_Empty_database")
                         .Options;

            //Act
            using (var context = new ApiGatewayContext(option))
            {
                var serviceDiscoveryService = new ServiceDiscoveryService(context);
                var serviceDiscoveryManager = new ServiceDiscoveryManager(serviceDiscoveryService);
                registeredServices = serviceDiscoveryManager.GetAvailableServices(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);
        }
Esempio n. 3
0
        //Fail condition for ServiceDiscoveryManager.GetAvailableServices(), when input is too short, return no data
        public void GetServices_NotPass_InputTooShort()
        {   //Arrange
            var expected = false;
            var actual   = false;
            ICollection <ServiceDisplayResp> registeredServices;

            //Act
            using (var context = new ApiGatewayContext())
            {
                var serviceDiscoveryService = new ServiceDiscoveryService(context);
                var serviceDiscoveryManager = new ServiceDiscoveryManager(serviceDiscoveryService);
                //Generate a key that is shorter than requirement
                var randomId = GenerateRandomKey(Constants.clientIdLength - 1);
                registeredServices = serviceDiscoveryManager.GetAvailableServices(randomId);
            }

            //Since input is invalid, the registeredServices should be null
            if (registeredServices != null)
            {
                actual = true;
            }

            //Assert
            Assert.AreEqual(expected, actual);
        }
        public IActionResult DisplayServices(string clientId)

        {
            try
            {
                return(Ok(_serviceDiscoveryManager.GetAvailableServices(clientId)));
            }
            catch {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Esempio n. 5
0
        public void GetAvailableServices_InMemory_Pass()
        {   //Arrange
            var expected = true;
            var actual   = false;
            var option   = new DbContextOptionsBuilder <ApiGatewayContext>()
                           .UseInMemoryDatabase(databaseName: "ServiceDiscoveryManager.GetAvailableServices_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 serviceDiscoveryService = new ServiceDiscoveryService(context);
                var serviceDiscoveryManager = new ServiceDiscoveryManager(serviceDiscoveryService);

                registeredServices = serviceDiscoveryManager.GetAvailableServices(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);
        }