public CustomerData Convert(Customer customer)
 {
     if (customer == null)
     {
         return null;
     }
     PrimitiveMapper mapper = new PrimitiveMapper();
     CustomerData viewModel = new CustomerData();
     viewModel.CustomerId = mapper.ToString(customer.CustomerId);
     viewModel.Name = customer.Name;
     viewModel.BirthDate = mapper.ToString(customer.BirthDate);
     viewModel.Height = customer.Height;
     return viewModel;
 }
Esempio n. 2
0
        public AddressItemData Convert(AddressItem item)
        {
            if (item == null)
            {
                return(null);
            }
            PrimitiveMapper mapper = new PrimitiveMapper();
            AddressItemData data   = new AddressItemData();

            data.AddressItemId = mapper.ToString(item.AddressItemId);
            data.CustomerId    = mapper.ToString(item.CustomerId);
            data.Key           = item.Key;
            data.Value         = item.Value;
            return(data);
        }
        public CustomerData Convert(Customer customer)
        {
            if (customer == null)
            {
                return(null);
            }
            PrimitiveMapper mapper    = new PrimitiveMapper();
            CustomerData    viewModel = new CustomerData();

            viewModel.CustomerId = mapper.ToString(customer.CustomerId);
            viewModel.Name       = customer.Name;
            viewModel.BirthDate  = mapper.ToString(customer.BirthDate);
            viewModel.Height     = customer.Height;
            return(viewModel);
        }
 public void ShouldCovertValidStringToDate()
 {
     PrimitiveMapper mapper = new PrimitiveMapper();
     DateTime original = DateTime.Today;  // date only
     DateTime actual = mapper.ToDateTime(mapper.ToString(original));
     Assert.AreEqual(original, actual, "The date/time was not parsed correctly.");
 }
 public void ShouldConvertValidStringIntoGuid()
 {
     PrimitiveMapper mapper = new PrimitiveMapper();
     Guid guid = Guid.NewGuid();
     Guid actual = mapper.ToGuid(mapper.ToString(guid));
     Assert.AreEqual(guid, actual, "The GUID was not parsed correctly.");
 }
        public void ShouldConvertViewModelToDataObjectIgnoringMissingCustomerId()
        {
            CustomerData viewModel = new CustomerData()
            {
                CustomerId = null,
                Name = "Bob",
                Height = 123,
                BirthDate = "12/31/2012"
            };

            CustomerMapper mapper = new CustomerMapper();
            Customer customer = mapper.Convert(viewModel);

            PrimitiveMapper primitiveMapper = new PrimitiveMapper();
            Assert.AreEqual(viewModel.BirthDate, primitiveMapper.ToString(customer.BirthDate), "The birth date was not mapped.");
            Assert.AreEqual(viewModel.Height, customer.Height, "The height was not mapped.");
            Assert.AreEqual(viewModel.Name, customer.Name, "The name was not mapped.");
        }
        public void ShouldConvertViewModelToDataObject()
        {
            CustomerData viewModel = new CustomerData()
            {
                CustomerId = Guid.NewGuid().ToString("N"),
                Name = "Bob",
                Height = 123,
                BirthDate = "12/31/2012"
            };

            CustomerMapper mapper = new CustomerMapper();
            Customer customer = mapper.Convert(viewModel);

            PrimitiveMapper primitiveMapper = new PrimitiveMapper();
            Assert.AreEqual(viewModel.BirthDate, primitiveMapper.ToString(customer.BirthDate), "The birth date was not mapped.");
            Assert.AreEqual(Guid.Parse(viewModel.CustomerId), customer.CustomerId, "The customer ID was not mapped.");
            Assert.AreEqual(viewModel.Height, customer.Height, "The height was not mapped.");
            Assert.AreEqual(viewModel.Name, customer.Name, "The name was not mapped.");
        }
        public void ShouldMapCustomerToViewModel()
        {
            ICustomerRepository repository = Substitute.For<ICustomerRepository>();
            Customer dto = new Customer();
            setReturnedCustomer(repository, dto);

            ICustomerMapper mapper = Substitute.For<ICustomerMapper>();
            CustomerData viewModel = new CustomerData();
            mapper.Convert(dto).Returns(viewModel);

            CustomerAdapter adapter = new CustomerAdapter(repository) { CustomerMapper = mapper };
            PrimitiveMapper primitiveMapper = new PrimitiveMapper();
            CustomerData data = adapter.GetCustomer(primitiveMapper.ToString(Guid.Empty));

            repository.Received().GetCustomer(dto.CustomerId);
            mapper.Received().Convert(dto);

            Assert.IsNotNull(data, "The returned view model was null.");
        }