Пример #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 async Task Handle_NewCustomer_ReturnCustomer(
            [Frozen] Mock <IRepository <Entities.Customer> > customerRepoMock,
            AddCustomerCommandHandler sut,
            string name,
            string contactType,
            List <CustomerAddressDto> addresses
            )
        {
            // Arrange
            var customer = new StoreCustomerDto
            {
                Name      = name,
                Addresses = addresses,
                Contacts  = new List <StoreCustomerContactDto>
                {
                    new StoreCustomerContactDto
                    {
                        ContactType   = contactType,
                        ContactPerson = new PersonDto
                        {
                            EmailAddresses = new List <PersonEmailAddressDto>
                            {
                                new PersonEmailAddressDto
                                {
                                    EmailAddress = EmailAddress.Create("*****@*****.**").Value
                                }
                            },
                            PhoneNumbers = new List <PersonPhoneDto>()
                        }
                    }
                }
            };

            //Act
            var result = await sut.Handle(
                new AddCustomerCommand { Customer = customer },
                CancellationToken.None
                );

            //Assert
            result.Should().NotBeNull();
            customerRepoMock.Verify(x => x.AddAsync(
                                        It.IsAny <Entities.Customer>(),
                                        It.IsAny <CancellationToken>()
                                        ));

            result.Should().BeEquivalentTo(customer);
        }