Ejemplo n.º 1
0
        public void IfClientExist_InMemory_Pass()
        {   //Arrange
            var expected = true;
            var actual   = false;
            var option   = new DbContextOptionsBuilder <ApiGatewayContext>()
                           .UseInMemoryDatabase(databaseName: "ServiceDiscoveryService.IfClientExist_Pass_database")
                           .Options;

            //Act
            using (var context = new ApiGatewayContext(option))
            {
                var teamForTesting = new Team();
                var randomKey      = GenerateRandomKey(Int32.Parse(Environment.GetEnvironmentVariable("APIKeyInputLength", EnvironmentVariableTarget.User)));
                teamForTesting.ClientId    = randomKey;
                teamForTesting.WebsiteUrl  = "testingWebSiteUrl";
                teamForTesting.Secret      = "testingSecret";
                teamForTesting.CallbackUrl = "testingCallBackUrl";
                teamForTesting.Digest      = "testingDigest";
                teamForTesting.Username    = "******";
                context.Team.Add(teamForTesting);
                context.SaveChanges();

                var serviceDiscoverService = new ServiceDiscoveryService(context);

                //Different from GetServices, check if a team exist need the same random key
                actual = serviceDiscoverService.IfClientExist(randomKey);
            }

            //Assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 2
0
        public void IfClientExist_WhiteSpaceInput()
        {   //Arrange
            var expected = false;
            var actual   = false;

            //Act
            using (var context = new ApiGatewayContext())
            {
                var serviceDiscoverService = new ServiceDiscoveryService(context);
                actual = serviceDiscoverService.IfClientExist("");
            }

            //Assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 3
0
        /// <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);
        }
Ejemplo n.º 4
0
        public void IfClientExist_InMemory_EmptyDatabase()
        {   //Arrange
            var expected = false;
            var actual   = false;
            var option   = new DbContextOptionsBuilder <ApiGatewayContext>()
                           .UseInMemoryDatabase(databaseName: "ServiceDiscoveryService.IfClientExist_NotPass_database")
                           .Options;

            //Act
            using (var context = new ApiGatewayContext(option))
            {
                var serviceDiscoverService = new ServiceDiscoveryService(context);
                var inputClientId          = GenerateRandomKey(Int32.Parse(Environment.GetEnvironmentVariable("APIKeyInputLength", EnvironmentVariableTarget.User)));

                actual = serviceDiscoverService.IfClientExist(inputClientId);
            }

            //Assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 5
0
        public void IfClientExist_InMemory_ClientDoesnotMatch()
        {   //Arrange
            var expected = false;
            var actual   = false;
            var option   = new DbContextOptionsBuilder <ApiGatewayContext>()
                           .UseInMemoryDatabase(databaseName: "ServiceDiscoveryService.IfClientExist_NotPass_database")
                           .Options;

            //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);

                var serviceDiscoverService = new ServiceDiscoveryService(context);
                var inputClientId          = GenerateRandomKey(Int32.Parse(Environment.GetEnvironmentVariable("APIKeyInputLength", EnvironmentVariableTarget.User)));

                //Make sure the second random generated clientId is different from the first one
                while (inputClientId == randomId)
                {
                    inputClientId = GenerateRandomKey(Int32.Parse(Environment.GetEnvironmentVariable("APIKeyInputLength", EnvironmentVariableTarget.User)));
                }

                actual = serviceDiscoverService.IfClientExist(inputClientId);
            }

            //Assert
            Assert.AreEqual(expected, actual);
        }