Ejemplo n.º 1
0
        public void UpdateCustomerTaskFailExceptionNotFoundCustomer()
        {
            // Arrange

            UpdateCustomerCommandHandler commandHandler = new UpdateCustomerCommandHandler(_unitOfWork, _bus, _notifications);
            Guid customerId = new Guid("30A38AC8-EAA9-4DF0-981F-2685882C7C45");
            // not found xD

            UpdateCustomerCommand command = new UpdateCustomerCommand()
            {
                Id             = customerId,
                FirstName      = "Franky",
                LastName       = "Quintero",
                Telephone      = "573004436932",
                Company        = "UPC",
                Email          = "*****@*****.**",
                AddressCity    = "La Jagua de Ibirico",
                AddressZipCode = "203020",
                AddressLine1   = "B.Santander",
                AddressLine2   = "",
                CountryId      = new Guid("32BB805F-40A4-4C37-AA96-B7945C8C385C")
            };

            _validator.Validate(command).IsValid.ShouldBeTrue();

            // Act + Assert
            Should.Throw <NotFoundException>(async() =>
            {
                Unit responseUnit = await commandHandler.Handle(command, CancellationToken.None);
            });
        }
Ejemplo n.º 2
0
        public async Task UpdateAsync()
        {
            var dataAccess = new CustomerDataAccess(this.Context);

            //Act
            var sutCreate    = new CreateCustomerCommandHandler(dataAccess);
            var resultCreate = await sutCreate.Handle(new CreateCustomerCommand
            {
                Data = CustomerTestData.CustomerDataDTO
            }, CancellationToken.None);

            //Act
            var sutUpdate    = new UpdateCustomerCommandHandler(dataAccess);
            var resultUpdate = await sutUpdate.Handle(new UpdateCustomerCommand
            {
                Id   = resultCreate.Data.Id,
                Data = new Common.DTO.CustomerDataDTO
                {
                    Phone = "0721230000"
                }
            }, CancellationToken.None);

            //Assert
            Assert.IsTrue(resultUpdate.Succeeded);
        }
Ejemplo n.º 3
0
        public async Task Handle_GivenValidRequest_ShouldReturnCustomerId()
        {
            // Arrange
            var command = new UpdateCustomerCommand
            {
                Id          = 1,
                FirstName   = "Gosho",
                LastName    = "Petkov",
                Gender      = "Female",
                PhoneNumber = "12345",
                Status      = "Inactive"
            };

            var sut = new UpdateCustomerCommandHandler(this.deletableEntityRepository);

            // Act
            var id = await sut.Handle(command, It.IsAny <CancellationToken>());

            // Assert
            var customer = await this.dbContext.Customers.SingleOrDefaultAsync(x => x.Id == id);

            customer.ShouldNotBeNull();
            customer.FirstName.ShouldBe("Gosho");
            customer.LastName.ShouldBe("Petkov");
            customer.Gender.ShouldBe("Female");
            customer.PhoneNumber.ShouldBe("12345");
            customer.Status.ShouldBe("Inactive");
        }
Ejemplo n.º 4
0
 public UpdateCustomerHandlerTests()
 {
     _mapper        = new Mock <IMapper>();
     _customer      = _fixture.Create <Entity.Concrete.Customer>();
     _repository    = new Mock <IGenericRepository <Entity.Concrete.Customer> >();
     _updateCommand = _fixture.Create <UpdateCustomerCommand>();
     _sut           = new UpdateCustomerCommandHandler(_repository.Object, _mapper.Object);
 }
Ejemplo n.º 5
0
        public async Task Handle_GivenNullRequest_ShouldThrowArgumentNullException()
        {
            // Arrange
            var sut = new UpdateCustomerCommandHandler(this.deletableEntityRepository);

            // Act & Assert
            await Should.ThrowAsync <ArgumentNullException>(sut.Handle(null, It.IsAny <CancellationToken>()));
        }
Ejemplo n.º 6
0
        public UpdateCustomerCommandHandlerTests()
        {
            _repository = A.Fake <IRepository <Customer> >();
            _testee     = new UpdateCustomerCommandHandler(_repository);

            _customer = new Customer
            {
                FirstName = "Yoda"
            };
        }
Ejemplo n.º 7
0
        public UpdateCustomerCommandHandlerTests()
        {
            this.repositoryMock      = new Mock <ICustomersRepository>();
            this.identityServiceMock = new Mock <IIdentityService>();

            this.handler = new UpdateCustomerCommandHandler(
                this.repositoryMock.Object,
                this.identityServiceMock.Object);

            this.fixture = new Fixture();
        }
        public UpdateCustomerCommandHandlerTests()
        {
            _customerRepository   = A.Fake <ICustomerRepository>();
            _customerUpdateSender = A.Fake <ICustomerUpdateSender>();
            _testee = new UpdateCustomerCommandHandler(_customerUpdateSender, _customerRepository);

            _customer = new Customer
            {
                FirstName = "Yoda"
            };
        }
Ejemplo n.º 9
0
        public async Task Handle_ExistingCustomer_ReturnUpdatedCustomer(
            [Frozen] Mock <IRepository <Entities.Customer> > customerRepoMock,
            UpdateCustomerCommandHandler sut,
            UpdateCustomerCommand command
            )
        {
            //Act
            var result = await sut.Handle(command, CancellationToken.None);

            //Assert
            result.Should().NotBeNull();
            customerRepoMock.Verify(x => x.UpdateAsync(
                                        It.IsAny <Entities.Customer>(),
                                        It.IsAny <CancellationToken>()
                                        ));
        }
Ejemplo n.º 10
0
        public async void CreateProductCommand_ProductCreated()
        {
            //Arange
            var mediator = new Mock <IMediator>();

            Products.Handlers.Create     command = new Products.RequestModels.Create(new Infrastructure.AppDbContext.MyStoreDbContext());
            UpdateCustomerCommandHandler handler = new UpdateCustomerCommandHandler(mediator.Object);

            //Act
            Unit x = await handler.Handle(command, new System.Threading.CancellationToken());

            //Asert
            //Do the assertion

            //something like:
            mediator.Verify(x => x.Publish(It.IsAny <CustomersChanged>()));
        }
Ejemplo n.º 11
0
        public async Task Handle_GivenInvalidRequest_ShouldThrowNotFoundException()
        {
            // Arrange
            var command = new UpdateCustomerCommand
            {
                Id          = 5,
                FirstName   = "Gosho",
                LastName    = "Petkov",
                Gender      = "Female",
                PhoneNumber = "12345",
                Status      = "Inactive"
            };

            var sut = new UpdateCustomerCommandHandler(this.deletableEntityRepository);

            // Act & Assert
            await Should.ThrowAsync <NotFoundException>(sut.Handle(command, It.IsAny <CancellationToken>()));
        }
Ejemplo n.º 12
0
        public async Task UpdateCustomerTaskOk()
        {
            // Arrange

            UpdateCustomerCommandHandler commandHandler = new UpdateCustomerCommandHandler(_unitOfWork, _bus, _notifications);
            Guid customerId = new Guid("43A38AC8-EAA9-4DF0-981F-2685882C7C45");
            // "Jhon", "Jhon", "+34617", "company", "*****@*****.**",spainCountry, new Address("Madrid", "280181", "Paseo de La finca", ""

            UpdateCustomerCommand command = new UpdateCustomerCommand()
            {
                Id             = customerId,
                FirstName      = "Franky",
                LastName       = "Quintero",
                Telephone      = "573004436932",
                Company        = "UPC",
                Email          = "*****@*****.**",
                AddressCity    = "La Jagua de Ibirico",
                AddressZipCode = "203020",
                AddressLine1   = "B.Santander",
                AddressLine2   = "",
                CountryId      = new Guid("32BB805F-40A4-4C37-AA96-B7945C8C385C")
            };

            _validator.Validate(command).IsValid.ShouldBeTrue();
            // Act
            Unit responseUnit = await commandHandler.Handle(command, CancellationToken.None);

            Customer customer = _unitOfWork.Repository.CustomerRepository.SingleOrDefault(e => e.Id == customerId);

            // Assert
            customer.ShouldNotBeNull();
            customer.Id.ShouldBe(customerId);
            customer.FirstName.ShouldBe("Franky");
            customer.LastName.ShouldBe("Quintero");
            customer.Telephone.ShouldBe("573004436932");
            customer.Company.ShouldBe("UPC");
            customer.Email.ShouldBe("*****@*****.**");
            customer.Address.City.ShouldBe("La Jagua de Ibirico");
            customer.Address.ZipCode.ShouldBe("203020");
            customer.Address.AddressLine1.ShouldBe("B.Santander");
            customer.Address.AddressLine2.ShouldBe("");
            customer.CountryId.ShouldBe(new Guid("32BB805F-40A4-4C37-AA96-B7945C8C385C"));
        }
Ejemplo n.º 13
0
        public void Handle_CustomerDoesNotExist_ThrowArgumentNullException(
            [Frozen] Mock <IRepository <Entities.Customer> > customerRepoMock,
            UpdateCustomerCommandHandler sut,
            UpdateCustomerCommand command
            )
        {
            // Arrange
            customerRepoMock.Setup(x => x.GetBySpecAsync(
                                       It.IsAny <GetCustomerSpecification>(),
                                       It.IsAny <CancellationToken>()
                                       ))
            .ReturnsAsync((Entities.Customer)null);

            //Act
            Func <Task> func = async() => await sut.Handle(command, CancellationToken.None);

            //Assert
            func.Should().Throw <ArgumentNullException>()
            .WithMessage("Value cannot be null. (Parameter 'customer')");
        }