public async Task GetContactDetailsByTargetIdReturnsExpectedContactDetails(bool hasValidDate)
        {
            DateTime?validDate = null;

            if (hasValidDate)
            {
                validDate = DateTime.UtcNow;
            }

            var entity = _fixture.Build <ContactDetailsEntity>()
                         .With(x => x.RecordValidUntil, validDate)
                         .With(x => x.IsActive, true)
                         .With(x => x.LastModified, validDate)
                         .Create();

            await InsertDataIntoDynamoDB(entity).ConfigureAwait(false);

            var query = new ContactQueryParameter {
                TargetId = entity.TargetId
            };
            var result = await _classUnderTest.GetContactDetailsByTargetId(query).ConfigureAwait(false);

            result.Should().HaveCount(1);
            result.First().Should().BeEquivalentTo(entity);
            _logger.VerifyExact(LogLevel.Debug, $"Calling IDynamoDBContext.QueryAsync for targetId {entity.TargetId}", Times.Once());
        }
Exemplo n.º 2
0
        public async Task GetContactDetailsByTargetIdWhenAddressLine1NotEmptyReturnsMultilineAddressFields()
        {
            // Arrange
            var contactInformation = _fixture.Create <ContactInformation>();

            var entity = _fixture.Build <ContactDetailsEntity>()
                         .With(x => x.ContactInformation, contactInformation)
                         .With(x => x.RecordValidUntil, DateTime.UtcNow)
                         .With(x => x.IsActive, true)
                         .With(x => x.LastModified, DateTime.UtcNow)
                         .Create();

            await InsertDataIntoDynamoDB(entity).ConfigureAwait(false);

            var query = new ContactQueryParameter {
                TargetId = entity.TargetId
            };

            // Act
            var result = await _classUnderTest.GetContactDetailsByTargetId(query).ConfigureAwait(false);

            // Assert
            result.First().ContactInformation.AddressExtended.AddressLine1.Should().NotBe(contactInformation.Value);

            result.Should().BeEquivalentTo(entity);
        }
        public async Task <List <ContactDetails> > GetContactDetailsByTargetId(ContactQueryParameter query)
        {
            _logger.LogDebug($"Calling IDynamoDBContext.QueryAsync for targetId {query.TargetId.Value}");

            List <ContactDetailsEntity> contactDetailsEntities = new List <ContactDetailsEntity>();
            DynamoDBOperationConfig     dbOperationConfig      = null;

            if (!query.IncludeHistoric)
            {
                List <ScanCondition> scanConditions = new List <ScanCondition>
                {
                    new ScanCondition(nameof(ContactDetailsEntity.IsActive), ScanOperator.Equal, true)
                };
                dbOperationConfig = new DynamoDBOperationConfig()
                {
                    QueryFilter = scanConditions
                };
            }

            var queryResult = _dynamoDbContext.QueryAsync <ContactDetailsEntity>(query.TargetId.Value, dbOperationConfig);

            while (!queryResult.IsDone)
            {
                contactDetailsEntities.AddRange(await queryResult.GetNextSetAsync().ConfigureAwait(false));
            }

            return(contactDetailsEntities.ToDomain());
        }
Exemplo n.º 4
0
        public async Task GetContactDetailsByTargetIdWhenAddressLine1IsEmptyAndContactTypeIsAddressReturnsContentsOfValue()
        {
            // Arrange
            var addressExtended = _fixture.Build <AddressExtended>()
                                  .With(x => x.AddressLine1, string.Empty)
                                  .Create();

            var contactInformation = _fixture.Build <ContactInformation>()
                                     .With(x => x.AddressExtended, addressExtended)
                                     .With(x => x.ContactType, ContactDetailsApi.V1.Domain.ContactType.address)
                                     .Create();

            var entity = _fixture.Build <ContactDetailsEntity>()
                         .With(x => x.ContactInformation, contactInformation)
                         .With(x => x.RecordValidUntil, DateTime.UtcNow)
                         .With(x => x.IsActive, true)
                         .With(x => x.LastModified, DateTime.UtcNow)
                         .Create();

            await InsertDataIntoDynamoDB(entity).ConfigureAwait(false);

            var query = new ContactQueryParameter {
                TargetId = entity.TargetId
            };

            // Act
            var result = await _classUnderTest.GetContactDetailsByTargetId(query).ConfigureAwait(false);

            // Assert
            result.First().ContactInformation.AddressExtended.AddressLine1.Should().Be(contactInformation.Value);

            result.First().Should().BeEquivalentTo(entity, config => config.Excluding(x => x.ContactInformation));
            result.First().ContactInformation.Should().BeEquivalentTo(contactInformation, config => config.Excluding(x => x.AddressExtended));
        }
Exemplo n.º 5
0
        public void QueryShouldErrorWithNullTargetId()
        {
            var query  = new ContactQueryParameter();
            var result = _sut.TestValidate(query);

            result.ShouldHaveValidationErrorFor(x => x.TargetId);
        }
        public async Task GetContactDetailsByTargetIdReturnsEmptyIfEntityDoesntExist()
        {
            var targetId = Guid.NewGuid();
            var query    = new ContactQueryParameter {
                TargetId = targetId
            };
            var response = await _classUnderTest.GetContactDetailsByTargetId(query).ConfigureAwait(false);

            _logger.VerifyExact(LogLevel.Debug, $"Calling IDynamoDBContext.QueryAsync for targetId {targetId}", Times.Once());
            response.Should().BeEmpty();
        }
        public async Task <IActionResult> GetContactDetailsByTargetId([FromQuery] ContactQueryParameter queryParam)
        {
            var contacts = await _getContactDetailsByTargetIdUseCase.Execute(queryParam).ConfigureAwait(false);

            if (contacts == null || !contacts.Any())
            {
                return(NotFound(queryParam.TargetId));
            }

            return(Ok(new GetContactDetailsResponse(contacts)));
        }
        public async Task GetByIdUseCaseShouldBeEmpty()
        {
            var queryParam = new ContactQueryParameter
            {
                TargetId = Guid.NewGuid()
            };

            _mockGateway.Setup(x => x.GetContactDetailsByTargetId(queryParam)).ReturnsAsync((List <ContactDetails>)null);

            var response = await _classUnderTest.Execute(queryParam).ConfigureAwait(false);

            response.Should().BeEmpty();
        }
        public void GetContactByIdThrowsException()
        {
            var queryParam = new ContactQueryParameter
            {
                TargetId = Guid.NewGuid()
            };
            var exception = new ApplicationException("Test Exception");

            _mockGateway.Setup(x => x.GetContactDetailsByTargetId(queryParam)).ThrowsAsync(exception);

            Func <Task <List <ContactDetailsResponseObject> > > func = async() => await _classUnderTest.Execute(queryParam).ConfigureAwait(false);

            func.Should().Throw <ApplicationException>().WithMessage(exception.Message);
        }
        public async Task GetContactByIdReturnsOkResponse()
        {
            var queryParam = new ContactQueryParameter
            {
                TargetId = Guid.NewGuid()
            };
            var contact = _fixture.Create <List <ContactDetails> >();

            _mockGateway.Setup(x => x.GetContactDetailsByTargetId(queryParam)).ReturnsAsync(contact);

            var response = await _classUnderTest.Execute(queryParam).ConfigureAwait(false);

            response.Should().BeEquivalentTo(contact.ToResponse());
        }
Exemplo n.º 11
0
        public void GetContactDetailsByTargetIdThrowsException()
        {
            var targetId   = Guid.NewGuid();
            var queryParam = new ContactQueryParameter
            {
                TargetId = targetId
            };
            var exception = new ApplicationException("Test Exception");

            _mockGetByIdUseCase.Setup(x => x.Execute(queryParam)).ThrowsAsync(exception);

            Func <Task <IActionResult> > func = async() => await _classUnderTest.GetContactDetailsByTargetId(queryParam).ConfigureAwait(false);

            func.Should().Throw <ApplicationException>().WithMessage(exception.Message);
        }
Exemplo n.º 12
0
        public async Task GetContactDetailsByTargetIdReturnsOkResponse()
        {
            var queryParam = new ContactQueryParameter
            {
                TargetId = Guid.NewGuid()
            };
            var contactResponse = _fixture.Create <List <ContactDetailsResponseObject> >();

            _mockGetByIdUseCase.Setup(x => x.Execute(queryParam)).ReturnsAsync((contactResponse));

            var response = await _classUnderTest.GetContactDetailsByTargetId(queryParam).ConfigureAwait(false);

            response.Should().BeOfType(typeof(OkObjectResult));
            (response as OkObjectResult).Value.Should().BeEquivalentTo(new GetContactDetailsResponse(contactResponse));
        }
Exemplo n.º 13
0
        public async Task GetContactDetailsByTargetIdNotFoundReturnsNotFound()
        {
            // Arrange
            var cqp = new ContactQueryParameter
            {
                TargetId = Guid.NewGuid()
            };

            _mockGetByIdUseCase.Setup(x => x.Execute(cqp)).ReturnsAsync((List <ContactDetailsResponseObject>)null);

            // Act
            var response = await _classUnderTest.GetContactDetailsByTargetId(cqp).ConfigureAwait(false);

            // Assert
            response.Should().BeOfType(typeof(NotFoundObjectResult));
            (response as NotFoundObjectResult).Value.Should().Be(cqp.TargetId);
        }
        public async Task <List <ContactDetails> > GetContactDetailsByTargetId(ContactQueryParameter query)
        {
            _logger.LogDebug($"Calling IDynamoDBContext.QueryAsync for targetId {query.TargetId.Value}");

            List <ContactDetailsEntity> contactDetailsEntities = new List <ContactDetailsEntity>();
            DynamoDBOperationConfig     dbOperationConfig      = null;

            if (!query.IncludeHistoric)
            {
                dbOperationConfig = CreateConfigForOnlyActiveContactDetails();
            }

            var search = _dynamoDbContext.QueryAsync <ContactDetailsEntity>(query.TargetId.Value, dbOperationConfig);

            do
            {
                var newResults = await search.GetNextSetAsync().ConfigureAwait(false);

                contactDetailsEntities.AddRange(newResults);
            } while (!search.IsDone);

            return(contactDetailsEntities.ToDomain());
        }
Exemplo n.º 15
0
        public async Task <List <ContactDetailsResponseObject> > Execute(ContactQueryParameter query)
        {
            var contact = await _gateway.GetContactDetailsByTargetId(query).ConfigureAwait(false);

            return(contact.ToResponse());
        }