public void GivenCustomerId_WhenGetCustomerById_ThenCallToCustomerRepositoryWithThisId()
        {
            //Given
            CustomerDTO customerDTO = new CustomerDTO();

            customerDTO.Firstname        = "test";
            customerDTO.Lastname         = "test";
            customerDTO.AdressOfCustomer = new Adress(1820, "Perk", "kerkstraat", 5);
            customerDTO.Email            = "*****@*****.**";
            customerDTO.PhoneNumber      = "04/72123456";

            CustomerBuilder customerbuilder = new CustomerBuilder();
            Customer        customer        =
                customerbuilder.WithFirstName("test")
                .WithLastname("test")
                .WithAddress(
                    new Adress(1820, "Perk", "kerkstraat", 5))
                .WithPhoneNumber("04/721233456")
                .WithEmailAdress("*****@*****.**")
                .Build();

            _customerMapperStub.FromCustomerToCustomerDTO(customer).Returns(customerDTO);
            _customerRepositoryStub.GetCustomerById(customer.Id).Returns(customer);

            //When
            _customerService.GetCustomerById(customer.Id);

            //Then
            _customerRepositoryStub.Received().GetCustomerById(customer.Id);
        }
Example #2
0
        public CustomerDTO CreateNewCustomer(CustomerDTO newCustomerDTO)
        {
            foreach (var item in newCustomerDTO.GetType().GetProperties())
            {
                if (item.Name != "Id")
                {
                    if ((item.GetValue(newCustomerDTO) == null))
                    {
                        throw new CustomerInputException();
                    }
                }
                else
                {
                    if ((item.GetValue(newCustomerDTO).ToString() != "-1"))
                    {
                        throw new CustomerInputException();
                    }
                }
            }
            Customer newCustomer = _customerMapper.FromCustomerDTOToCustomer(newCustomerDTO);

            _customerRepository.AddNewCustomer(newCustomer);
            return(_customerMapper.FromCustomerToCustomerDTO(newCustomer));
        }