Example #1
0
        public async Task Handle_ExistingCustomerAndContact_DeleteContact(
            [Frozen] Mock <IRepository <Entities.StoreCustomer> > customerRepoMock,
            Entities.StoreCustomer customer,
            DeleteStoreCustomerContactCommandHandler sut,
            DeleteStoreCustomerContactCommand command
            )
        {
            // Arrange
            customer.AddContact(new Entities.StoreCustomerContact(
                                    command.CustomerContact.ContactType,
                                    new Entities.Person(
                                        command.CustomerContact.ContactPerson.Title,
                                        command.CustomerContact.ContactPerson.Name
                                        )
                                    ));

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

            //Act
            var result = await sut.Handle(command, CancellationToken.None);

            //Assert
            result.Should().NotBeNull();
            customerRepoMock.Verify(x => x.UpdateAsync(
                                        It.IsAny <Entities.StoreCustomer>(),
                                        It.IsAny <CancellationToken>()
                                        ));
        }
        public async Task Handle_CustomerExists_ReturnCustomer(
            [Frozen] Mock <IRepository <Entities.Customer> > customerRepoMock,
            GetCustomerQueryHandler sut,
            GetCustomerQuery query,
            Entities.StoreCustomer customer
            )
        {
            //Arrange
            customerRepoMock.Setup(_ => _.GetBySpecAsync(
                                       It.IsAny <GetCustomerSpecification>(),
                                       It.IsAny <CancellationToken>()
                                       ))
            .ReturnsAsync(customer);

            //Act
            var result = await sut.Handle(query, CancellationToken.None);

            //Assert
            result.Should().NotBeNull();
            customerRepoMock.Verify(x => x.GetBySpecAsync(
                                        It.IsAny <GetCustomerSpecification>(),
                                        It.IsAny <CancellationToken>()
                                        ));

            result.Should().BeEquivalentTo(customer, opt => opt
                                           .Excluding(_ => _.SelectedMemberPath.EndsWith("Id", StringComparison.InvariantCultureIgnoreCase))
                                           );
        }
            public async Task GetPreferredShippingAddress_NoAddressFound_ReturnAddress(
                [Frozen] Mock <IRepository <Entities.Customer> > customerRepoMock,
                GetPreferredAddressQueryHandler sut,
                GetPreferredAddressQuery query,
                Entities.StoreCustomer customer
                )
            {
                //Arrange
                query.AddressType = "Shipping";

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

                //Act
                var result = await sut.Handle(query, CancellationToken.None);

                //Assert
                result.Should().BeNull();

                customerRepoMock.Verify(x => x.GetBySpecAsync(
                                            It.IsAny <GetCustomerAddressesSpecification>(),
                                            It.IsAny <CancellationToken>()
                                            ));
            }
        public void TestValidate_AddressAlreadyExists_ValidationError(
            [Frozen] Mock <IRepository <Entities.Customer> > customerRepoMock,
            Entities.StoreCustomer customer,
            UpdateCustomerAddressCommandValidator sut,
            UpdateCustomerAddressCommand command,
            Entities.CustomerAddress customerAddress
            )
        {
            //Arrange
            customer.AddAddress(customerAddress);

            command.AccountNumber = "1";
            var address = customer.Addresses.ToList()[0];

            command.CustomerAddress.AddressType               = address.AddressType;
            command.CustomerAddress.Address.AddressLine1      = address.Address.AddressLine1;
            command.CustomerAddress.Address.AddressLine2      = address.Address.AddressLine2;
            command.CustomerAddress.Address.PostalCode        = address.Address.PostalCode;
            command.CustomerAddress.Address.City              = address.Address.City;
            command.CustomerAddress.Address.StateProvinceCode = address.Address.StateProvinceCode;
            command.CustomerAddress.Address.CountryRegionCode = address.Address.CountryRegionCode;

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

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

            //Assert
            result.ShouldHaveValidationErrorFor(command => command)
            .WithErrorMessage("Address must be unique");
        }
        public async Task Handle_CustomerAndContactExist_UpdateStoreCustomerContact(
            [Frozen] Mock <IRepository <Entities.StoreCustomer> > customerRepoMock,
            Entities.StoreCustomer customer,
            UpdateStoreCustomerContactCommandHandler sut,
            Entities.Person contactPerson,
            string accountNumber,
            string contactType
            )
        {
            //Arrange
            var command = new UpdateStoreCustomerContactCommand
            {
                AccountNumber   = accountNumber,
                CustomerContact = new StoreCustomerContactDto
                {
                    ContactType   = contactType,
                    ContactPerson = new PersonDto
                    {
                        EmailAddresses = new List <EmailAddressDto>
                        {
                            new EmailAddressDto
                            {
                                EmailAddress = EmailAddress.Create("*****@*****.**").Value
                            }
                        }
                    }
                }
            };

            customer.AddContact(
                new Entities.StoreCustomerContact(
                    command.CustomerContact.ContactType,
                    contactPerson
                    )
                );

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

            //Act
            var result = await sut.Handle(command, CancellationToken.None);

            //Assert
            result.Should().NotBeNull();
            customerRepoMock.Verify(x => x.UpdateAsync(
                                        It.IsAny <Entities.StoreCustomer>(),
                                        It.IsAny <CancellationToken>()
                                        ));
        }
Example #6
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);
        }
            public async Task GetPreferredShippingAddress_HomeAddressExists_ReturnAddress(
                [Frozen] Mock <IRepository <Entities.Customer> > customerRepoMock,
                GetPreferredAddressQueryHandler sut,
                GetPreferredAddressQuery query,
                Entities.StoreCustomer customer,
                Entities.Address address
                )
            {
                //Arrange
                query.AddressType = "Shipping";
                customer.AddAddress(
                    new Entities.CustomerAddress(
                        "Home",
                        address
                        )
                    );

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

                //Act
                var result = await sut.Handle(query, CancellationToken.None);

                //Assert
                result.Should().BeEquivalentTo(
                    address,
                    opt => opt.Excluding(_ => _.SelectedMemberPath.EndsWith("Id", StringComparison.InvariantCultureIgnoreCase))
                    );

                customerRepoMock.Verify(x => x.GetBySpecAsync(
                                            It.IsAny <GetCustomerAddressesSpecification>(),
                                            It.IsAny <CancellationToken>()
                                            ));
            }