コード例 #1
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,Country country,Address address)
        {
            //create the customer instance
            var customer = new Customer()
            {
                FirstName = firstName,
                LastName = lastName
            };

            //set customer address
            customer.Address = address;

            //set default picture relation with no data
            customer.Picture = new Picture();

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

            //Associate country
            customer.SetCountry(country);

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

            return customer;
        }
コード例 #2
0
        public void CustomerCannotAssociateTransientCountry()
        {
            //Arrange
            Country country = new Country()
            {
                CountryName ="Spain"
            };

            //Act
            Customer customer = new Customer();
            customer.SetCountry(country);
        }
コード例 #3
0
        public void CustomerEnumerableToCustomerListDTOListAdapt()
        {
            //Arrange
            Guid idCustomer = IdentityGenerator.NewSequentialGuid();
            Guid idCountry = IdentityGenerator.NewSequentialGuid();
            Customer customer = new Customer()
            {
                Id = idCustomer,
                FirstName = "Unai",
                LastName = "Zorrilla",
                CreditLimit = 1000M,
                Telephone = "617404929",
                Company = "Spirtis",
                Address = new Address("Monforte", "27400", "AddressLine1", "AddressLine2"),
                Picture = new Picture() { Id = idCustomer, RawPhoto = new byte[0] { } }
            };

            customer.SetCountry(new Country() { Id = idCountry, CountryName = "Spain", CountryISOCode = "es-ES" });

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

            //Act
            ITypeAdapter adapter = PrepareTypeAdapter();

            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(idCustomer, 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);
        }
コード例 #4
0
        public void CustomerSetCountryFixCountryId()
        {
            //Arrange
            Country country = new Country();
            country.Id = IdentityGenerator.NewSequentialGuid();

            //Act
            Customer customer = new Customer();
            customer.SetCountry(country);

            //Assert
            Assert.AreEqual(country.Id, customer.CountryId);
        }
コード例 #5
0
        public void CustomerToCustomerDTOAdapt()
        {
            //Arrange

            Guid idCustomer = IdentityGenerator.NewSequentialGuid();
            Guid idCountry = IdentityGenerator.NewSequentialGuid();
            Customer customer = new Customer()
            {
                Id = idCustomer,
                FirstName = "Jhon",
                LastName = "El rojo",
                CreditLimit = 1000M,
                Telephone = "617404929",
                Company = "Spirtis",
                Address = new Address("Monforte", "27400", "AddressLine1", "AddressLine2"),
                Picture = new Picture() { Id = idCustomer, RawPhoto = new byte[0]{} }
            };

            customer.SetCountry(new Country() { Id = idCountry, CountryName = "Spain", CountryISOCode = "es-ES" });

            //Act

            ITypeAdapter adapter = PrepareTypeAdapter();
            var dto = adapter.Adapt<Customer, CustomerDTO>(customer);

            //Assert

            Assert.AreEqual(idCustomer, 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(idCountry, dto.CountryId);

            Assert.AreEqual(customer.Picture.RawPhoto, dto.PictureRawPhoto);

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