예제 #1
0
        public void TestValidate_CustomerNotFound_ValidationError(
            [Frozen] Mock <IRepository <Entities.Customer> > customerRepoMock,
            UpdateCustomerCommandValidator sut,
            UpdateCustomerCommand command,
            string accountNumber,
            List <CustomerAddressDto> addresses,
            string contactType,
            List <PersonPhoneDto> phoneNumbers
            )
        {
            //Arrange
            var customerDto = new StoreCustomerDto
            {
                AccountNumber = accountNumber,
                Addresses     = addresses,
                Contacts      = new List <StoreCustomerContactDto>
                {
                    new StoreCustomerContactDto
                    {
                        ContactType   = contactType,
                        ContactPerson = new PersonDto
                        {
                            EmailAddresses = new List <PersonEmailAddressDto>
                            {
                                new PersonEmailAddressDto
                                {
                                    EmailAddress = EmailAddress.Create("*****@*****.**").Value
                                }
                            },
                            PhoneNumbers = phoneNumbers
                        }
                    }
                }
            };

            command.Customer = customerDto;
            command.Customer.AccountNumber = command.Customer.AccountNumber.Substring(0, 10);

            customerRepoMock.Setup(x => x.GetBySpecAsync(
                                       It.IsAny <GetCustomerSpecification>(),
                                       It.IsAny <CancellationToken>()
                                       ))
            .ReturnsAsync((Entities.StoreCustomer)null);

            //Act
            var result = sut.TestValidate(command);

            //Assert
            result.ShouldHaveValidationErrorFor(command => command.Customer.AccountNumber)
            .WithErrorMessage("Customer does not exist");
        }
예제 #2
0
        public void TestValidate_WithEmptyAccountNumber_ValidationError(
            UpdateCustomerCommandValidator sut,
            UpdateCustomerCommand command
            )
        {
            //Arrange
            command.Customer.AccountNumber = null;

            //Act
            var result = sut.TestValidate(command);

            //Assert
            result.ShouldHaveValidationErrorFor(command => command.Customer.AccountNumber)
            .WithErrorMessage("Account number is required");
        }
예제 #3
0
        public void TestValidate_WithAccountNumberTooLong_ValidationError(
            UpdateCustomerCommandValidator sut,
            UpdateCustomerCommand command
            )
        {
            //Arrange
            command.Customer.AccountNumber = "AW000000011";

            //Act
            var result = sut.TestValidate(command);

            //Assert
            result.ShouldHaveValidationErrorFor(command => command.Customer.AccountNumber)
            .WithErrorMessage("Account number must not exceed 10 characters");
        }
예제 #4
0
        public void TestValidate_ValidCommand_NoValidationError(
            [Frozen] Mock <IRepository <Entities.Customer> > customerRepoMock,
            Entities.StoreCustomer customer,
            UpdateCustomerCommandValidator sut,
            UpdateCustomerCommand command
            )
        {
            //Arrange
            command.Customer.AccountNumber = "1";

            customerRepoMock.Setup(x => x.GetBySpecAsync(
                                       It.IsAny <GetCustomerSpecification>(),
                                       It.IsAny <CancellationToken>()
                                       ))
            .ReturnsAsync(customer);

            //Act
            var result = sut.TestValidate(command);

            //Assert
            result.ShouldNotHaveValidationErrorFor(command => command.Customer);
            result.ShouldNotHaveValidationErrorFor(command => command.Customer.AccountNumber);
        }