Exemplo n.º 1
0
        public async Task WhenTheRequestIsUnauthorizedThenAnUnauthorizedExceptionIsThrown()
        {
            var request = new GetNextUnsignedEmployerAgreementRequest();

            _validator.Setup(x => x.ValidateAsync(request)).ReturnsAsync(new ValidationResult {
                IsUnauthorized = true
            });

            Assert.ThrowsAsync <UnauthorizedAccessException>(() => _handler.Handle(request));
        }
Exemplo n.º 2
0
        public async Task WhenTheRequestIsInvalidThenAValidationExceptionIsThrown()
        {
            var request = new GetNextUnsignedEmployerAgreementRequest();

            _validator.Setup(x => x.ValidateAsync(request)).ReturnsAsync(new ValidationResult {
                ValidationDictionary = new Dictionary <string, string> {
                    { "A", "B" }
                }
            });

            Assert.ThrowsAsync <InvalidRequestException>(() => _handler.Handle(request));
        }
        public async Task ThenShouldReturnUnauthorisedIfTheUserIsAssociatedToTheAccount()
        {
            var request = new GetNextUnsignedEmployerAgreementRequest {
                HashedAccountId = "ABC123", ExternalUserId = Guid.NewGuid().ToString()
            };

            _membershipRepository.Setup(x => x.GetCaller(request.HashedAccountId, request.ExternalUserId)).ReturnsAsync((MembershipView)null);

            //Act
            var result = await _validator.ValidateAsync(request);

            //Assert
            Assert.IsTrue(result.IsUnauthorized);
        }
Exemplo n.º 4
0
        public async Task WhenThereIsNoPendingAgreementThenNullIsReturned()
        {
            var accountId = 1234;

            var request = new GetNextUnsignedEmployerAgreementRequest {
                HashedAccountId = "ABC123"
            };

            _hashingService.Setup(x => x.DecodeValue(request.HashedAccountId)).Returns(accountId);

            _accountLegalEntity.AccountId = accountId;

            var response = await _handler.Handle(request);

            Assert.IsNull(response.HashedAgreementId);
        }
Exemplo n.º 5
0
        public async Task ThenTheHashedAgreementIdIsReturned()
        {
            var accountId         = 1234;
            var agreementId       = 324345;
            var hashedAgreementId = "ABC345";

            var request = new GetNextUnsignedEmployerAgreementRequest {
                HashedAccountId = "ABC123"
            };

            _hashingService.Setup(x => x.DecodeValue(request.HashedAccountId)).Returns(accountId);

            _accountLegalEntity.AccountId          = accountId;
            _accountLegalEntity.PendingAgreementId = agreementId;
            _hashingService.Setup(x => x.HashValue(agreementId)).Returns(hashedAgreementId);

            var response = await _handler.Handle(request);

            Assert.AreEqual(hashedAgreementId, response.HashedAgreementId);
        }