Example #1
0
        public decimal CustomerBalance(Customer customer)
        {
            //assume
            Dictionary <Account, Role> accounts = new Dictionary <Account, Role>();

            accounts.Add(new Account {
                Id = 1, Balance = 100
            }, new Role());
            accounts.Add(new Account {
                Id = 2, Balance = -200
            }, new Role());

            PexAssume.Implies(customer != null, () => customer.RelatedAccounts = accounts);

            //arrange
            SIRepository         repository                 = new SIRepository();
            SICustomerRepository customerRepository         = new SICustomerRepository();
            SIAccountServices    accountServices            = new SIAccountServices();
            IDtoCreator <Customer, CustomerDto> custCreator = new CustomerDtoCreator();

            accountServices.BalanceAccount = (x) => x.Balance;

            CustomerServices services = new CustomerServices(customerRepository, repository, accountServices, custCreator);
            var result = services.CustomerBalance(customer);

            PexAssert.Case(customer.RelatedAccounts == accounts).Implies(() => result == -100);
            return(result);
        }
        public void CreateIndividualCustomer(string firstName, string lastName, string email, string phoneNumber)
        {
            SIRepository repository = new SIRepository();
            SICustomerRepository customerRepository = new SICustomerRepository();
            SIAccountServices accountServices = new SIAccountServices();
            IDtoCreator<Customer, CustomerDto> custCreator = new CustomerDtoCreator();

            CustomerServices customerServices = new CustomerServices(customerRepository, repository,accountServices,custCreator);
            customerServices.CreateCustomer( firstName,  lastName,  email, phoneNumber);
        }
Example #3
0
        public void CreateIndividualCustomer(string firstName, string lastName, string email, string phoneNumber)
        {
            SIRepository         repository                 = new SIRepository();
            SICustomerRepository customerRepository         = new SICustomerRepository();
            SIAccountServices    accountServices            = new SIAccountServices();
            IDtoCreator <Customer, CustomerDto> custCreator = new CustomerDtoCreator();

            CustomerServices customerServices = new CustomerServices(customerRepository, repository, accountServices, custCreator);

            customerServices.CreateCustomer(firstName, lastName, email, phoneNumber);
        }
Example #4
0
        public void SaveCustomer(CustomerDto customerDto)
        {
            SIRepository repository = new SIRepository();

            repository.GetObject((x) => { return(new Customer()); });
            SIAccountServices accountServices = new SIAccountServices();
            IDtoCreator <Customer, CustomerDto> custCreator = new CustomerDtoCreator();

            SICustomerRepository customerRepository = new SICustomerRepository();
            CustomerServices     services           = new CustomerServices(customerRepository, repository, accountServices, custCreator);

            services.SaveCustomer(customerDto);
        }
Example #5
0
        public CustomerDto GetCustomerById(int id)
        {
            var repository         = new SIRepository();
            var customerRepository = new SICustomerRepository();
            var accountServices    = new SIAccountServices();
            var custCreator        = new CustomerDtoCreator();

            repository.GetObject <Customer>((x) => _customers.SingleOrDefault(c => c.Id == (int)x));

            CustomerServices services = new CustomerServices(customerRepository, repository, accountServices, custCreator);
            var result = services.GetCustomerById(id);

            //asert

            PexAssert.Case(id == _customers[0].Id).Implies(() => result.Email == _customers[0].Email);
            return(result);
        }
Example #6
0
        public IList <CustomerDto> GetCustomersForAdvisor(int advisorID)
        {
            SIRepository         repository                 = new SIRepository();
            SICustomerRepository customerRepository         = new SICustomerRepository();
            SIAccountServices    accountServices            = new SIAccountServices();
            IDtoCreator <Customer, CustomerDto> custCreator = new CustomerDtoCreator();


            repository.GetObject <Advisor>((x) => _advisors.SingleOrDefault(a => a.Id == (int)x));

            //act
            CustomerServices    customerServices = new CustomerServices(customerRepository, repository, accountServices, custCreator);
            IList <CustomerDto> result           = customerServices.GetCustomersForAdvisor(advisorID);

            PexAssert.Case(advisorID == _advisors[0].Id).Implies(() => result.Count == _advisors[0].Customers.Count);
            return(result);
        }
Example #7
0
        public CustomerDto GetCustomerByCode(string code)
        {
            //arrange
            SIRepository         repository                 = new SIRepository();
            SICustomerRepository customerRepository         = new SICustomerRepository();
            SIAccountServices    accountServices            = new SIAccountServices();
            IDtoCreator <Customer, CustomerDto> custCreator = new CustomerDtoCreator();

            customerRepository.GetCustomerByCodeString = (x) => _customers.SingleOrDefault(a => a.Code == x);
            //act
            CustomerServices custonerServices = new CustomerServices(customerRepository, repository, accountServices, custCreator);
            CustomerDto      result           = custonerServices.GetCustomerByCode(code);

            //assert
            PexAssert.Case(code == _customers[0].Code).Implies(() => result.Email == _customers[0].Email);
            return(result);
        }
Example #8
0
        public CustomerDto GetCustomerByIdentity(string identity)
        {
            //arrange
            SIRepository         repository                 = new SIRepository();
            SICustomerRepository customerRepository         = new SICustomerRepository();
            SIAccountServices    accountServices            = new SIAccountServices();
            IDtoCreator <Customer, CustomerDto> custCreator = new CustomerDtoCreator();


            customerRepository.GetCustomerByIdentityString = (x) => _customers.SingleOrDefault(c => c.Identification == x);

            //act
            CustomerServices services = new CustomerServices(customerRepository, repository, accountServices, custCreator);
            var result = services.GetCustomerByIdentity(identity);

            //assert
            PexAssert.Case(identity == _customers[0].Identification).Implies(() => result.Email == _customers[0].Email);
            return(result);
        }
        public decimal CustomerBalance(Customer customer)
        {
            //assume
            Dictionary<Account, Role> accounts = new Dictionary<Account, Role>();
            accounts.Add(new Account { Id = 1, Balance = 100 }, new Role());
            accounts.Add(new Account { Id = 2, Balance = -200 }, new Role());

            PexAssume.Implies(customer != null, () => customer.RelatedAccounts = accounts);

            //arrange
            SIRepository repository = new SIRepository();
            SICustomerRepository customerRepository = new SICustomerRepository();
            SIAccountServices accountServices = new SIAccountServices();
            IDtoCreator<Customer,CustomerDto> custCreator = new CustomerDtoCreator();

            accountServices.BalanceAccount = (x) => x.Balance;

            CustomerServices services = new CustomerServices(customerRepository, repository, accountServices,custCreator);
            var result = services.CustomerBalance(customer);
            PexAssert.Case(customer.RelatedAccounts == accounts).Implies(() => result == -100);
            return result;
        }
        public CustomerDto GetCustomerByCode(string code)
        {
            //arrange
            SIRepository repository = new SIRepository();
            SICustomerRepository customerRepository = new SICustomerRepository();
            SIAccountServices accountServices = new SIAccountServices();
            IDtoCreator<Customer, CustomerDto> custCreator = new CustomerDtoCreator();

            customerRepository.GetCustomerByCodeString = (x) => _customers.SingleOrDefault(a => a.Code == x);
            //act
            CustomerServices custonerServices = new CustomerServices(customerRepository, repository,accountServices,custCreator);
            CustomerDto result = custonerServices.GetCustomerByCode(code);

            //assert
            PexAssert.Case(code == _customers[0].Code).Implies(()=>result.Email == _customers[0].Email);
            return result;
        }
        public void SaveCustomer(CustomerDto customerDto)
        {
            SIRepository repository = new SIRepository();
            repository.GetObject((x) => { return new Customer(); });
            SIAccountServices accountServices = new SIAccountServices();
            IDtoCreator<Customer, CustomerDto> custCreator = new CustomerDtoCreator();

            SICustomerRepository customerRepository = new SICustomerRepository();
            CustomerServices services = new CustomerServices(customerRepository, repository, accountServices, custCreator);
            services.SaveCustomer(customerDto);
        }
        public IList<CustomerDto> GetCustomersForAdvisor(int advisorID)
        {
            SIRepository repository = new SIRepository();
            SICustomerRepository customerRepository = new SICustomerRepository();
            SIAccountServices accountServices = new SIAccountServices();
            IDtoCreator<Customer, CustomerDto> custCreator = new CustomerDtoCreator();

            repository.GetObject<Advisor>((x) => _advisors.SingleOrDefault(a => a.Id == (int)x));

            //act
            CustomerServices customerServices = new CustomerServices(customerRepository, repository,accountServices,custCreator);
            IList<CustomerDto> result = customerServices.GetCustomersForAdvisor(advisorID);

            PexAssert.Case(advisorID == _advisors[0].Id).Implies(() => result.Count == _advisors[0].Customers.Count);
            return result;
        }
        public CustomerDto GetCustomerByIdentity(string identity)
        {
            //arrange
            SIRepository repository = new SIRepository();
            SICustomerRepository customerRepository = new SICustomerRepository();
            SIAccountServices accountServices = new SIAccountServices();
            IDtoCreator<Customer, CustomerDto> custCreator = new CustomerDtoCreator();

            customerRepository.GetCustomerByIdentityString = (x) => _customers.SingleOrDefault(c=>c.Identification == x);

            //act
            CustomerServices services = new CustomerServices(customerRepository, repository,accountServices,custCreator);
            var result = services.GetCustomerByIdentity(identity);

            //assert
            PexAssert.Case(identity == _customers[0].Identification).Implies(()=>result.Email == _customers[0].Email);
            return result;
        }
        public CustomerDto GetCustomerById(int id)
        {
            var repository = new SIRepository();
            var customerRepository = new SICustomerRepository();
            var accountServices = new SIAccountServices();
            var custCreator = new CustomerDtoCreator();

            repository.GetObject<Customer>((x) => _customers.SingleOrDefault(c=>c.Id == (int)x));

            CustomerServices services = new CustomerServices(customerRepository, repository,accountServices,custCreator);
            var result = services.GetCustomerById(id);
            //asert

            PexAssert.Case(id == _customers[0].Id).Implies(() => result.Email == _customers[0].Email);
            return result;
        }