Exemplo n.º 1
0
        public void It_should_create_mr_green_customers()
        {
            // Arrange

            var customers = new Domain.Customer.Customer[]
            {
                new MrGreenCustomer("Green 1", "Green", "12345-222", _address),
                new MrGreenCustomer("Green 2", "Red", "12345-222", _address),
            };

            // Act

            var result = _customerResponseFactory.Create(customers);

            // Assert

            Assert.AreEqual(customers.Length, result.Length);

            for (var i = 0; i < customers.Length; i++)
            {
                var customer       = customers[i] as MrGreenCustomer;
                var mappedCustomer = result[i] as MrGreenCustomerDto;

                Assert.IsNotNull(customer);
                Assert.IsNotNull(mappedCustomer);
                Assert.IsInstanceOf <MrGreenCustomer>(customer);
                Assert.IsInstanceOf <MrGreenCustomerDto>(mappedCustomer);
                Assert.AreEqual(customer.FirstName, mappedCustomer.FirstName);
                Assert.AreEqual(customer.LastName, mappedCustomer.LastName);
                Assert.AreEqual(customer.Address.Street, mappedCustomer.Address.Street);
                Assert.AreEqual(customer.PersonalNumber.IdentificationNumber, mappedCustomer.PersonalNumber);
            }
        }
Exemplo n.º 2
0
        public void It_should_create_red_bet_customers()
        {
            // Arrange

            var customers = new Domain.Customer.Customer[]
            {
                new RedBetCustomer("Red 1", "Red", "MC", _address),
                new RedBetCustomer("Red 2", "Red", "MU", _address),
            };

            // Act

            var result = _customerResponseFactory.Create(customers);

            // Assert

            Assert.AreEqual(customers.Length, result.Length);

            for (var i = 0; i < customers.Length; i++)
            {
                var customer       = customers[i] as RedBetCustomer;
                var mappedCustomer = result[i] as RedBetCustomerDto;

                Assert.IsNotNull(customer);
                Assert.IsNotNull(mappedCustomer);
                Assert.IsInstanceOf <RedBetCustomer>(customer);
                Assert.IsInstanceOf <RedBetCustomerDto>(mappedCustomer);
                Assert.AreEqual(customer.FirstName, mappedCustomer.FirstName);
                Assert.AreEqual(customer.LastName, mappedCustomer.LastName);
                Assert.AreEqual(customer.Address.Street, mappedCustomer.Address.Street);
                Assert.AreEqual(customer.FavoriteFootballClub.Club, mappedCustomer.FavoriteFootballTeam);
            }
        }
Exemplo n.º 3
0
        private static BaseCustomerDto GetCustomer(Domain.Customer.Customer customer)
        {
            var address = customer.Address;

            var addressDto = new CustomerAddressDto
            {
                Street  = address.Street,
                City    = address.City,
                ZipCode = address.ZipCode,
                Number  = address.Number
            };

            return(customer switch
            {
                MrGreenCustomer mrGreenCustomer => new MrGreenCustomerDto
                {
                    Id = mrGreenCustomer.Id,
                    FirstName = mrGreenCustomer.FirstName,
                    LastName = mrGreenCustomer.LastName,
                    PersonalNumber = mrGreenCustomer.PersonalNumber,
                    Address = addressDto
                },
                RedBetCustomer redBetCustomer => new RedBetCustomerDto
                {
                    Id = redBetCustomer.Id,
                    FirstName = redBetCustomer.FirstName,
                    LastName = redBetCustomer.LastName,
                    FavoriteFootballTeam = redBetCustomer.FavoriteFootballClub,
                    Address = addressDto
                },
                _ => throw new InvalidOperationException("Customer Type is not supported")
            });
Exemplo n.º 4
0
        public void It_should_throw_invalid_operation_exception()
        {
            // Arrange

            var customers = new Domain.Customer.Customer[]
            {
                new FakeCustomer("Fake 1", "Green", _address),
            };

            // Assert

            Assert.Catch <InvalidOperationException>(() => _customerResponseFactory.Create(customers));
        }
        public CustomerDTO.WithRelations Create(CustomerDTO.WithRelations customer)
        {
            var dbCustomer = new Domain.Customer.Customer(customer);

            customer.Phones.ForEach(cp => dbCustomer.Phones.Add(new CustomerPhone(cp)));
            customer.Emails.ForEach(ce => dbCustomer.Emails.Add(new CustomerEmail(ce)));

            _customerRepository.Add(dbCustomer);

            _unitOfWork.Commit();

            return(_mapper.Map <CustomerDTO.WithRelations>(dbCustomer));
        }
Exemplo n.º 6
0
        public void It_should_return_empty_list()
        {
            // Arrange

            var customers = new Domain.Customer.Customer[0];

            // Act

            var result = _customerResponseFactory.Create(customers);

            // Assert

            Assert.IsEmpty(result);
        }
Exemplo n.º 7
0
 public void Standard(Domain.Customer.Customer customer)
 => ViewModel = new OkObjectResult(new CustomerResponse(customer.Id, customer.Name, customer.Age, customer.Email));
 public async Task Register(Domain.Customer.Customer customer)
 {
     await _unitOfWork.Save(customer);
 }
Exemplo n.º 9
0
 public BaseCustomerDto Create(Domain.Customer.Customer customer)
 {
     return(GetCustomer(customer));
 }
Exemplo n.º 10
0
 public CustomerSaveRequest(Guid id, string name, int age, string email)
 {
     Customer = new Domain.Customer.Customer(id, name, age, email);
 }
Exemplo n.º 11
0
 public CustomerSaveRequest(string name, int age, string email)
 {
     Customer = new Domain.Customer.Customer(Guid.NewGuid(), name, age, email);
 }