Example #1
0
        public void GetApiKeyTests_WhenGettingTheApiKeyShouldWorkWithFilesAndDirectKeyData()
        {
            var apiKeyOrFile   = TestContext.DataRow["ApiKeyOrFile"].ToString();
            var passFullPath   = bool.Parse(TestContext.DataRow["PassFullPath"].ToString());
            var apiKeyValue    = TestContext.DataRow["ApiKeyValue"].ToString();
            var expectedResult = bool.Parse(TestContext.DataRow["ExpectedResult"].ToString());

            var getApiKey = new GetApiKey();

            string result;

            if (passFullPath && !string.IsNullOrWhiteSpace(apiKeyOrFile))
            {
                apiKeyOrFile = Path.Combine(TestContext.DeploymentDirectory, apiKeyOrFile);
            }

            var keyValueReturned = getApiKey.ExtractApiKey(apiKeyOrFile, TestContext.DeploymentDirectory, out result);

            if (expectedResult)
            {
                Assert.AreEqual(apiKeyValue, keyValueReturned);
            }
            else
            {
                Assert.AreEqual(string.Empty, keyValueReturned);
            }
        }
        public void GetApiKeyTests_WhenGettingTheApiKeyShouldWorkWithFilesAndDirectKeyData()
        {
            var apiKeyOrFile = TestContext.DataRow["ApiKeyOrFile"].ToString();
            var passFullPath = bool.Parse(TestContext.DataRow["PassFullPath"].ToString());
            var apiKeyValue = TestContext.DataRow["ApiKeyValue"].ToString();
            var expectedResult = bool.Parse(TestContext.DataRow["ExpectedResult"].ToString());

            var getApiKey = new GetApiKey();

            string result;
            if (passFullPath && !string.IsNullOrWhiteSpace(apiKeyOrFile))
            {
                apiKeyOrFile = Path.Combine(TestContext.DeploymentDirectory, apiKeyOrFile);
            }

            var keyValueReturned = getApiKey.ExtractApiKey(apiKeyOrFile, TestContext.DeploymentDirectory, out result);

            if (expectedResult)
            {
                Assert.AreEqual(apiKeyValue, keyValueReturned);
            }
            else
            {
                Assert.AreEqual(string.Empty, keyValueReturned);
            }
        }
Example #3
0
        public async void should_Be_able_to_fetch_existing_key_by_id()
        {
            var query = new GetApiKey(_existingEntity.Id);

            var sut    = new GetApiKeyHandler(_uow);
            var result = await sut.ExecuteAsync(query);

            AssertionExtensions.Should((object)result).NotBeNull();
            AssertionExtensions.Should((string)result.GeneratedKey).Be(_existingEntity.GeneratedKey);
            AssertionExtensions.Should((string)result.ApplicationName).Be(_existingEntity.ApplicationName);
            AssertionExtensions.Should((int)result.AllowedApplications[0].ApplicationId).Be(_application.Id);
            AssertionExtensions.Should((string)result.AllowedApplications[0].ApplicationName).Be(_application.Name);
        }
Example #4
0
        public async void Should_Be_able_to_fetch_existing_key_by_id()
        {
            var query   = new GetApiKey(_existingEntity.Id);
            var context = Substitute.For <IMessageContext>();

            GetApiKeyResult result;

            using (var uow = CreateUnitOfWork())
            {
                var sut = new GetApiKeyHandler(uow);
                result = await sut.HandleAsync(context, query);

                uow.SaveChanges();
            }

            result.Should().NotBeNull();
            result.GeneratedKey.Should().Be(_existingEntity.GeneratedKey);
            result.ApplicationName.Should().Be(_existingEntity.ApplicationName);
            result.AllowedApplications[0].ApplicationId.Should().Be(_application.Id);
            result.AllowedApplications[0].ApplicationName.Should().Be(_application.Name);
        }