public void AddNewCustomerReturnAdaptedDto() { //Arrange var countryRepository = new StubICountryRepository(); countryRepository.GetGuid = (guid) => { var country = new Country("Spain", "es-ES"); ; country.ChangeCurrentIdentity(guid); return country; }; var customerRepository = new StubICustomerRepository(); customerRepository.AddCustomer = (customer) => { }; customerRepository.UnitOfWorkGet = () => { var uow = new StubIUnitOfWork(); uow.Commit = () => { }; return uow; }; var customerManagementService = new CustomerAppService(countryRepository, customerRepository); var customerDto = new CustomerDto() { CountryId = Guid.NewGuid(), FirstName = "Jhon", LastName = "El rojo" }; //act var result = customerManagementService.AddNewCustomer(customerDto); //Assert Assert.IsNotNull(result); Assert.IsTrue(result.Id != Guid.Empty); Assert.AreEqual(result.FirstName, customerDto.FirstName); Assert.AreEqual(result.LastName, customerDto.LastName); }
public void CustomerRepositoryAddNewItemSaveItem() { //Arrange var unitOfWork = new MainBcUnitOfWork(); var customerRepository = new CustomerRepository(unitOfWork); var country = new Country("spain", "es-ES"); country.ChangeCurrentIdentity(new Guid("32BB805F-40A4-4C37-AA96-B7945C8C385C")); var customer = CustomerFactory.CreateCustomer( "Felix", "Trend", "+3434", "company", country, new Address("city", "zipCode", "addressLine1", "addressLine2")); customer.SetTheCountryReference(country.Id); //Act customerRepository.Add(customer); unitOfWork.Commit(); }
public void CustomerRepositoryRemoveItemDeleteIt() { //Arrange var unitOfWork = new MainBCUnitOfWork(); var customerRepository = new CustomerRepository(unitOfWork); var country = new Country("Spain","es-ES"); country.ChangeCurrentIdentity(new Guid("32BB805F-40A4-4C37-AA96-B7945C8C385C")); var address = new Address("city", "zipCode", "addressline1", "addressline2"); var customer = CustomerFactory.CreateCustomer("Frank", "Frank","+3444","company", country,address); customer.SetTheCountryReference(country.Id); customerRepository.Add(customer); unitOfWork.Commit(); //Act customerRepository.Remove(customer); unitOfWork.Commit(); var result = customerRepository.Get(customer.Id); //Assert Assert.IsNull(result); }
private Customer MaterializeCustomerFromDto(CustomerDto customerDto) { //create the current instance with changes from customerDTO var address = new Address( customerDto.AddressCity, customerDto.AddressZipCode, customerDto.AddressAddressLine1, customerDto.AddressAddressLine2); var country = new Country("Spain", "es-ES"); country.ChangeCurrentIdentity(customerDto.CountryId); var current = CustomerFactory.CreateCustomer( customerDto.FirstName, customerDto.LastName, customerDto.Telephone, customerDto.Company, country, address); current.SetTheCountryReference(customerDto.Id); //set credit current.ChangeTheCurrentCredit(customerDto.CreditLimit); //set picture var picture = new Picture { RawPhoto = customerDto.PictureRawPhoto }; picture.ChangeCurrentIdentity(current.Id); current.ChangePicture(picture); //set identity current.ChangeCurrentIdentity(customerDto.Id); return current; }