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")); }
public void ItShouldFailIfCustomerDoesNotExist() { Customer customer = null; var readStore = new Mock <ICustomerRepository>(); readStore.Setup(_ => _.GetCustomerById(It.IsAny <int>())).ReturnsAsync(customer); var sut = new UpdateCustomerCommandValidator(readStore.Object); var result = sut.Validate(new UpdateCustomerCommand { Id = 1 }); result.IsValid.ShouldBe(false); result.Errors[0].ErrorMessage.ShouldBe("Customer must exist to update"); }
public void ItShouldDeleteIfExistingCustomer() { var customer = new Customer { CustomerId = 1 }; var readStore = new Mock <ICustomerRepository>(); readStore.Setup(_ => _.GetCustomerById(It.IsAny <int>())).ReturnsAsync(customer); var sut = new UpdateCustomerCommandValidator(readStore.Object); var result = sut.Validate(new UpdateCustomerCommand { Id = 1 }); result.IsValid.ShouldBe(true); }