Beispiel #1
0
        public void ShouldConvertReturnedAddressItemsToViewModel()
        {
            ICustomerRepository customerRepository = Substitute.For <ICustomerRepository>();
            Customer            customer           = new Customer();

            customerRepository.GetCustomer(Arg.Any <Guid>()).Returns(customer);

            IAddressItemRepository itemRepository = Substitute.For <IAddressItemRepository>();

            AddressItem[] items = new AddressItem[] { new AddressItem() };
            itemRepository.GetAddressItems(customer).Returns(items);

            IAddressItemMapper mapper = Substitute.For <IAddressItemMapper>();

            mapper.Convert(Arg.Any <AddressItem>()).Returns(new AddressItemData());

            AddressItemAdapter adapter = new AddressItemAdapter(customerRepository, itemRepository);

            adapter.AddressItemMapper = mapper;
            string customerId = Guid.Empty.ToString("N");
            IEnumerable <AddressItemData> models = adapter.GetAddressItems(customerId);

            Assert.AreEqual(1, models.Count(), "The wrong number of view models were returned.");
            customerRepository.Received(1).GetCustomer(Arg.Any <Guid>());
            itemRepository.Received(1).GetAddressItems(customer);
            mapper.Received(1).Convert(Arg.Any <AddressItem>());
        }
Beispiel #2
0
        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());
        }