public async Task Must_Update_Valid_Customer() { await AuthanticateAccountAsync(); var customer = await CreateCustomer(); //Arrange var customerViewModel = new CustomerViewModel { Id = customer.Id, CompanyName = "Updated CompanyName", ContactName = customer.ContactName, ContactTitle = customer.ContactTitle, Address = customer.Address, City = customer.City, Country = customer.Country, Phone = customer.Phone, Email = customer.Email, PostalCode = customer.PostalCode }; //Act var httpResponseMessage = _httpTestClient.PutAsJsonAsync("/api/customer/update", customerViewModel).Result; //Assert httpResponseMessage.StatusCode.Should().Be(HttpStatusCode.OK); var updatedCustomer = await _customersRepository.FindById(customerViewModel.Id); updatedCustomer.CompanyName.Should().Be(customerViewModel.CompanyName); }
public async Task <CommandResponse> Handle(CustomerUpdateCommand request, CancellationToken cancellationToken) { if (!request.IsValid()) { return(request.CommandResponse); } var customer = new Customer(request.Id, request.CompanyName, request.ContactName, request.ContactTitle, request.Email, request.Address, request.City, request.PostalCode, request.Country, request.Phone); var customerData = await _customersRepository.FindById(customer.Id); if (customerData != null && customerData.Email != request.Email) { if (await _customersRepository.GetByEmail(request.Email) != null) { request.CommandResponse.ValidationResult.Errors.Add(new ValidationFailure("Email", "E-Mail Alreadt Exist")); return(request.CommandResponse); } } // TODO Here will Add to Domain Event.... customer.Apply(new CustomerUpdateEvent(customer.Id, customer.CompanyName, customer.ContactName, customer.ContactTitle, customer.Email, customer.Address, customer.City, customer.PostalCode, customer.Country, customer.Phone)); _customersRepository.Update(customer); await _eventStoreRepository.SaveAsync <Customer>(customer); return(await Commit(_customersRepository.UnitOfWork)); }
public CustomerDto GetCustomerById(Guid id) { var customer = customersRepository.FindById(id); if (customer == null) { throw new HttpException("Customer not found.", HttpStatusCode.NotFound); } return(mapper.Map <CustomerDto>(customer)); }
public void FindById() { // Act var abc = _customersRepository.FindById("1"); var def = _customersRepository.FindById("2"); var ghi = _customersRepository.FindById("3"); // Assert Assert.IsNotNull(abc); Assert.IsNotNull(def); Assert.IsNull(ghi); Assert.AreEqual("abc", abc.CompanyName); Assert.AreEqual("def", def.CompanyName); }
public async Task <CommandResponse> Handle(OrderAddCommand request, CancellationToken cancellationToken) { if (!request.IsValid()) { return(request.CommandResponse); } var checkCustomer = await _customerRepository.FindById(request.CustomerID); var checkEmployee = await _employeeRepository.FindById(request.EmployeeID); if (checkCustomer == null || checkEmployee == null) { if (checkCustomer == null) { request.CommandResponse.ValidationResult.Errors.Add(new ValidationFailure(null, "Invalid Customer ID")); } else { request.CommandResponse.ValidationResult.Errors.Add(new ValidationFailure(null, "Invalid Employee ID")); } return(request.CommandResponse); } var order = new Order(Guid.NewGuid(), checkCustomer, checkEmployee, request.RequiredDate, request.ShipName, request.ShipAddress, request.ShipCity, request.ShipPostalCode, request.ShipCountry, request.ShipVia); order.Apply(new OrderAddEvent(order.Id, order.CustomerID, order.EmployeeID, order.OrderDate, order.RequiredDate, order.ShippedDate, order.ShipName, order.ShipAddress, order.ShipCity, order.ShipPostalCode, order.ShipCountry, order.ShipVia)); await _orderRepository.Add(order); await _eventStoreRepository.SaveAsync <Order>(order); return(await Commit(_orderRepository.UnitOfWork)); }
public Customers GetById(int customerId) { return(_customersRepository.FindById(customerId)); }