public void CustomerEnumerableToCustomerListDTOListAdapt()
        {
            //Arrange



            var country = new Country("Spain", "es-ES");
            country.GenerateNewIdentity();

            var address = new Address("Monforte", "27400", "AddressLine1", "AddressLine2");

            var customer = CustomerFactory.CreateCustomer("Jhon", "El rojo", "617404929", "Spirtis", country, address);
            var picture = new Picture { RawPhoto = new byte[0] { } };

            customer.ChangeTheCurrentCredit(1000M);
            customer.ChangePicture(picture);
            customer.SetTheCountryForThisCustomer(country);

            IEnumerable<Customer> customers = new List<Customer>() { customer };

            //Act
            ITypeAdapter adapter = TypeAdapterFactory.CreateAdapter();

            var dtos = adapter.Adapt<IEnumerable<Customer>, List<CustomerListDTO>>(customers);

            //Assert

            Assert.IsNotNull(dtos);
            Assert.IsTrue(dtos.Any());
            Assert.IsTrue(dtos.Count == 1);

            CustomerListDTO dto = dtos[0];

            Assert.AreEqual(customer.Id, dto.Id);
            Assert.AreEqual(customer.FirstName, dto.FirstName);
            Assert.AreEqual(customer.LastName, dto.LastName);
            Assert.AreEqual(customer.Company, dto.Company);
            Assert.AreEqual(customer.Telephone, dto.Telephone);
            Assert.AreEqual(customer.CreditLimit, dto.CreditLimit);
            Assert.AreEqual(customer.Address.City, dto.AddressCity);
            Assert.AreEqual(customer.Address.ZipCode, dto.AddressZipCode);
            Assert.AreEqual(customer.Address.AddressLine1, dto.AddressAddressLine1);
            Assert.AreEqual(customer.Address.AddressLine2, dto.AddressAddressLine2);


        }
      public void CustomerToCustomerDtoAdapt()
      {
         //Arrange

         var country = new Country("Spain", "es-ES");
         country.GenerateNewIdentity();

         var address = new Address("Monforte", "27400", "AddressLine1", "AddressLine2");

         var customer = CustomerFactory.CreateCustomer("Jhon", "El rojo", "617404929", "Spirtis", country, address);
         var picture = new Picture
         {
            RawPhoto = new byte[0]
            {
            }
         };

         customer.ChangeTheCurrentCredit(1000M);
         customer.ChangePicture(picture);
         customer.SetTheCountryForThisCustomer(country);

         //Act

         var adapter = TypeAdapterFactory.CreateAdapter();
         var dto = adapter.Adapt<Customer, CustomerDto>(customer);

         //Assert

         Assert.AreEqual(customer.Id, dto.Id);
         Assert.AreEqual(customer.FirstName, dto.FirstName);
         Assert.AreEqual(customer.LastName, dto.LastName);
         Assert.AreEqual(customer.Company, dto.Company);
         Assert.AreEqual(customer.Telephone, dto.Telephone);
         Assert.AreEqual(customer.CreditLimit, dto.CreditLimit);

         Assert.AreEqual(customer.Country.CountryName, dto.CountryCountryName);
         Assert.AreEqual(country.Id, dto.CountryId);

         Assert.AreEqual(customer.Address.City, dto.AddressCity);
         Assert.AreEqual(customer.Address.ZipCode, dto.AddressZipCode);
         Assert.AreEqual(customer.Address.AddressLine1, dto.AddressAddressLine1);
         Assert.AreEqual(customer.Address.AddressLine2, dto.AddressAddressLine2);
      }
Example #3
0
      /// <summary>
      ///    Create a new transient customer
      /// </summary>
      /// <param name="firstName">The customer firstName</param>
      /// <param name="lastName">The customer lastName</param>
      /// <param name="country">The associated country to this customer</param>
      /// <returns>A valid customer</returns>
      public static Customer CreateCustomer(
         string firstName,
         string lastName,
         string telephone,
         string company,
         Country country,
         Address address)
      {
         //create new instance and set identity
         var customer = new Customer();

         customer.GenerateNewIdentity();

         //set data

         customer.FirstName = firstName;
         customer.LastName = lastName;

         customer.Company = company;
         customer.Telephone = telephone;

         //set address
         customer.Address = address;

         //customer is enabled by default
         customer.Enable();

         //TODO: By default this is the limit for customer credit, you can set this 
         //parameter customizable via configuration or other system
         customer.ChangeTheCurrentCredit(1000M);

         //set default picture
         var picture = new Picture();
         picture.ChangeCurrentIdentity(customer.Id);

         customer.ChangePicture(picture);

         //set the country for this customer
         customer.SetTheCountryForThisCustomer(country);

         return customer;
      }
Example #4
0
 /// <summary>
 ///    change the picture for this customer
 /// </summary>
 /// <param name="picture">the new picture for this customer</param>
 public void ChangePicture(Picture picture)
 {
    if (picture != null && !picture.IsTransient()) { this.Picture = picture; }
 }
      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;
      }
        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 current = CustomerFactory.CreateCustomer(customerDTO.FirstName,
                                                         customerDTO.LastName,
                                                         customerDTO.Telephone,
                                                         customerDTO.Company,
                                                         customerDTO.CountryId,
                                                         address);

            //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;
        }