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.");
 }
Пример #2
0
        public AddressItem Convert(AddressItemData data)
        {
            if (data == null)
            {
                return(null);
            }
            PrimitiveMapper mapper = new PrimitiveMapper();
            AddressItem     item   = new AddressItem();

            if (!String.IsNullOrWhiteSpace(data.AddressItemId))
            {
                item.AddressItemId = mapper.ToGuid(data.AddressItemId);
            }
            item.CustomerId = mapper.ToGuid(data.CustomerId);
            item.Key        = data.Key;
            item.Value      = data.Key;
            return(item);
        }
 public IEnumerable<AddressItemData> GetAddressItems(string customerId)
 {
     PrimitiveMapper mapper = new PrimitiveMapper();
     Customer customer = customerRepository.GetCustomer(mapper.ToGuid(customerId));
     if (customer == null)
     {
         throw new AdapterException(HttpStatusCode.NotFound, "A customer with the given ID was not found.");
     }
     return itemRepository.GetAddressItems(customer).Select(s => AddressItemMapper.Convert(s)).ToArray();
 }
 public void ShouldThrowAdapterExceptionForInvalidGuid()
 {
     try
     {
         PrimitiveMapper mapper = new PrimitiveMapper();
         mapper.ToGuid("123");
         Assert.Fail("The invalid GUID should have caused an exception to be thrown.");
     }
     catch (AdapterException exception)
     {
         Assert.AreEqual(HttpStatusCode.BadRequest, exception.StatusCode, "The wrong status code was sent.");
     }
 }
 public Customer Convert(CustomerData viewModel)
 {
     if (viewModel == null)
     {
         return null;
     }
     PrimitiveMapper mapper = new PrimitiveMapper();
     Customer customer = new Customer();
     if (!String.IsNullOrWhiteSpace(viewModel.CustomerId))
     {
         customer.CustomerId = mapper.ToGuid(viewModel.CustomerId);
     }
     customer.Name = viewModel.Name;
     customer.BirthDate = mapper.ToDateTime(viewModel.BirthDate);
     customer.Height = viewModel.Height;
     return customer;
 }
        public Customer Convert(CustomerData viewModel)
        {
            if (viewModel == null)
            {
                return(null);
            }
            PrimitiveMapper mapper   = new PrimitiveMapper();
            Customer        customer = new Customer();

            if (!String.IsNullOrWhiteSpace(viewModel.CustomerId))
            {
                customer.CustomerId = mapper.ToGuid(viewModel.CustomerId);
            }
            customer.Name      = viewModel.Name;
            customer.BirthDate = mapper.ToDateTime(viewModel.BirthDate);
            customer.Height    = viewModel.Height;
            return(customer);
        }
 public void RemoveAddressItem(string settingId)
 {
     PrimitiveMapper mapper = new PrimitiveMapper();
     AddressItem item = itemRepository.GetAddressItem(mapper.ToGuid(settingId));
     if (item == null)
     {
         throw new AdapterException(HttpStatusCode.NotFound, "An address item with the given ID was not found.");
     }
     itemRepository.Remove(item);
 }
 private Customer getCustomer(string customerId)
 {
     PrimitiveMapper mapper = new PrimitiveMapper();
     Guid customerGuid = mapper.ToGuid(customerId);
     Customer customer = customerRepository.GetCustomer(customerGuid);
     if (customer == null)
     {
         throw new AdapterException(HttpStatusCode.NotFound, "A customer with the given ID was not found.");
     }
     return customer;
 }