public RepositoryCommandHandler(IRepository repository)
 {
     this.repository                 = repository;
     addCustomerCommandHandler       = new AddCustomerCommandHandler(repository);
     addOrderCommandHandler          = new AddOrderCommandHandler(repository);
     addProductCommandHandler        = new AddProductCommandHandler(repository);
     addProductToOrderCommandHandler = new AddProductToOrderCommandHandler(repository);
 }
        [DynamicData(nameof(InvalidCustomers))]    //this unit test will run against each object
        public async Task ShouldNotInsertInvalidCustomer(Customer customer)
        {
            //Arrange
            var command = new AddCustomerCommand(customer.FirstName, customer.LastName, customer.Email, customer.Address, customer.Age);
            var handler = new AddCustomerCommandHandler(_customerRepository, _uow, _mapper);

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

            //Assert
            Assert.IsTrue(!result.Success);
            Assert.AreEqual(_inMemoryContext.Customers.Count(), 0);
        }
Exemplo n.º 3
0
 public CustomerController(
     AddCustomerCommandHandler addCustomerCommandHandler,
     EditCustomerCommandHandler editCustomerCommandHandler,
     GetByDocumentCustomerQueryHandler getByDocumentQueryHandler,
     GetByIdCustomerQueryHandler getByIdCustomerQueryHandler,
     GetAllCustomerQueryHandler getAllQueryHandler)
 {
     _addCustomerCommandHandler         = addCustomerCommandHandler;
     _editCustomerCommandHandler        = editCustomerCommandHandler;
     _getByDocumentCustomerQueryHandler = getByDocumentQueryHandler;
     _getByIdCustomerQueryHandler       = getByIdCustomerQueryHandler;
     _getAllCustomerQueryHandler        = getAllQueryHandler;
 }
        public async Task ShouldNotInsertInvalidCustomer(Customer customer)
        {
            //Arrange
            _customerRepository.Setup(cr => cr.Add(It.IsAny <Customer>())).Verifiable();
            var command = new AddCustomerCommand(customer.FirstName, customer.LastName, customer.Email, customer.Address, customer.Age);
            var handler = new AddCustomerCommandHandler(_customerRepository.Object, _uow.Object, _mapper);

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

            //Assert
            Assert.True(!result.Success);
            _customerRepository.Verify(cr => cr.Add(It.IsAny <Customer>()), Times.Never);
        }
        public async Task ShouldInsertValidCustomer()
        {
            //Arrange
            _customerRepository.Setup(cr => cr.Add(It.IsAny <Customer>())).Verifiable();
            var command = new AddCustomerCommand("Rafael", "Baptista", "*****@*****.**", "Nenhum", 26);
            var handler = new AddCustomerCommandHandler(_customerRepository.Object, _uow.Object, _mapper);

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

            //Assert
            Assert.True(result.Success == true);
            _customerRepository.Verify(cr => cr.Add(It.IsAny <Customer>()), Times.Once);
        }
        public async Task ShouldInsertValidCustomer()
        {
            var command = new AddCustomerCommand("Rafael", "Baptista", "*****@*****.**", "Nenhum", 26);
            var handler = new AddCustomerCommandHandler(_customerRepository, _uow, _mapper);

            var result = await handler.Handle(command, CancellationToken.None);

            var customer = _inMemoryContext.Customers.FirstOrDefault();

            Assert.AreEqual(_inMemoryContext.Customers.Count(), 1);
            Assert.IsTrue(result.Success == true);
            Assert.IsTrue(customer.Id != 0);
            Assert.AreEqual(command.FirstName, customer.FirstName);
            Assert.AreEqual(command.Age, customer.Age);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        public void Handler_NewCustomerNoAddress_CustomerInsertedInDatabase()
        {
            Mock <ICustomerRepository> mockRep = new Mock <ICustomerRepository>();
            AddCustomerCommand         command = new AddCustomerCommand()
            {
                CustomerIdentity = 1,
                Gender           = 'M',
                LastName         = "Calisto",
                MiddleName       = "Cesar",
                Name             = "Caio"
            };
            AddCustomerCommandHandler handler = new AddCustomerCommandHandler(mockRep.Object);
            Task t = Task.Run(() => handler.Handle(command, CancellationToken.None));

            mockRep.Verify(m => m.Insert(It.IsAny <Domain.Aggregate.Customer>()), Times.Once());
        }
 public AddCustomerCommandHandlerTests()
 {
     _customerRepository = A.Fake <ICustomerRepository>();
     _sut     = new AddCustomerCommandHandler(new AddCustomerCommandValidator(), _customerRepository);
     _fixture = new Fixture();
 }