public void ShouldFindOriginalAndPassModifiedToRepository()
        {
            ICustomerRepository repository = Substitute.For <ICustomerRepository>();
            Customer            original   = new Customer();

            setReturnedCustomer(repository, original);

            ICustomerMapper mapper    = Substitute.For <ICustomerMapper>();
            Customer        modified  = new Customer();
            CustomerData    viewModel = new CustomerData()
            {
                CustomerId = Guid.Empty.ToString("N")
            };

            mapper.Convert(Arg.Any <CustomerData>()).Returns(modified);

            CustomerAdapter adapter = new CustomerAdapter(repository)
            {
                CustomerMapper = mapper
            };

            adapter.UpdateCustomer(viewModel);

            repository.Received().GetCustomer(Arg.Any <Guid>());
            mapper.Received().Convert(viewModel);
            repository.Received().Update(original, modified);
        }
        public void ShouldAddConvertedCustomerToRepositoryAndReturnUpdated()
        {
            ICustomerRepository repository      = Substitute.For <ICustomerRepository>();
            ICustomerMapper     mapper          = Substitute.For <ICustomerMapper>();
            Customer            dto             = new Customer();
            CustomerData        viewModelInput  = new CustomerData();
            CustomerData        viewModelOutput = new CustomerData();

            mapper.Convert(viewModelInput).Returns(dto);
            mapper.Convert(dto).Returns(viewModelOutput);

            CustomerAdapter adapter = new CustomerAdapter(repository)
            {
                CustomerMapper = mapper
            };

            CustomerData result = adapter.AddCustomer(viewModelInput);

            Assert.AreSame(viewModelOutput, result, "The updated view model was not returned.");

            mapper.Received().Convert(viewModelInput);
            repository.Received().Add(dto);
            mapper.Received().Convert(dto);
        }
        public void ShouldGetCustomersFromRepository()
        {
            ICustomerRepository repository = Substitute.For <ICustomerRepository>();

            Customer[] customers = new Customer[] { new Customer() };
            repository.GetCustomers().Returns(customers);

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

            mapper.Convert(Arg.Any <Customer>()).Returns(new CustomerData());

            CustomerAdapter adapter = new CustomerAdapter(repository)
            {
                CustomerMapper = mapper
            };
            IEnumerable <CustomerData> results = adapter.GetCustomers();

            repository.Received().GetCustomers();
            mapper.Received(1).Convert(customers[0]);

            Assert.IsNotNull(results, "Null was returned by the adapter.");
            Assert.AreEqual(1, results.Count(), "The wrong number of view models were returned.");
        }
        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.");
        }