예제 #1
0
        public void Balance_CustomerOK()
        {
            //arrange
            Account account = new Account();
            Account account2 = new Account();
            Customer customer = new Customer();

            customer.RelatedAccounts.Add(account, new Role());
            customer.RelatedAccounts.Add(account2, new Role());

            IRepository repository = MockRepository.GenerateMock<IRepository>();
            ICustomerRepository customerRepository = MockRepository.GenerateMock<ICustomerRepository>();
            IAccountRepository accountRepository = MockRepository.GenerateMock<IAccountRepository>();
            IDtoCreator<Customer, CustomerDto> custCreator = new CustomerDtoCreator();

            IAccountServices accountServices = MockRepository.GenerateMock<IAccountServices>(); //(repository, accountRepository,customerRepository);
            accountServices.Expect(x => x.Balance(account2)).Return(-10);
            accountServices.Expect(x => x.Balance(account)).Return(-20);

            //act
            CustomerServices services = new CustomerServices(customerRepository, repository, accountServices, custCreator);
            decimal balance = services.CustomerBalance(customer);

            //assert
            Assert.AreEqual(balance, -30);
            accountServices.VerifyAllExpectations();
        }
예제 #2
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);
        }
예제 #3
0
        public void TestGetCustomersForAdvisor()
        {
            //arrange
            IRepository         repository                  = MockRepository.GenerateStub <IRepository>();
            ICustomerRepository customerRepository          = MockRepository.GenerateStub <ICustomerRepository>();
            IAccountServices    accountServices             = MockRepository.GenerateStub <IAccountServices>();
            IDtoCreator <Customer, CustomerDto> custCreator = new CustomerDtoCreator();

            Advisor advisor1 = new Advisor {
                Id = 1, FirstName = "Ad1"
            };
            Advisor advisor2 = new Advisor {
                Id = 2, FirstName = "Ad2"
            };
            List <Customer> customers = new List <Customer>();

            customers.Add(new Customer {
                Advisor = advisor1, Id = 1
            });
            customers.Add(new Customer {
                Advisor = advisor2, Id = 2
            });
            advisor1.Customers = customers;
            //repository.Expect(x=>x.GetAll<Customer>()).Return(customers);
            repository.Expect(x => x.Get <Advisor>(advisor1.Id)).Return(advisor1);

            //act
            CustomerServices   services = new CustomerServices(customerRepository, repository, accountServices, custCreator);
            List <CustomerDto> recieved = (List <CustomerDto>)services.GetCustomersForAdvisor(advisor1.Id);

            //assert
            Assert.AreEqual(recieved[0].Id, 1);
            repository.VerifyAllExpectations();
        }
예제 #4
0
        public void Balance_CustomerOK()
        {
            //arrange
            Account  account  = new Account();
            Account  account2 = new Account();
            Customer customer = new Customer();

            customer.RelatedAccounts.Add(account, new Role());
            customer.RelatedAccounts.Add(account2, new Role());

            IRepository         repository                  = MockRepository.GenerateMock <IRepository>();
            ICustomerRepository customerRepository          = MockRepository.GenerateMock <ICustomerRepository>();
            IAccountRepository  accountRepository           = MockRepository.GenerateMock <IAccountRepository>();
            IDtoCreator <Customer, CustomerDto> custCreator = new CustomerDtoCreator();


            IAccountServices accountServices = MockRepository.GenerateMock <IAccountServices>(); //(repository, accountRepository,customerRepository);

            accountServices.Expect(x => x.Balance(account2)).Return(-10);
            accountServices.Expect(x => x.Balance(account)).Return(-20);


            //act
            CustomerServices services = new CustomerServices(customerRepository, repository, accountServices, custCreator);
            decimal          balance  = services.CustomerBalance(customer);

            //assert
            Assert.AreEqual(balance, -30);
            accountServices.VerifyAllExpectations();
        }
예제 #5
0
        public void TestGetCustomersForAdvisor()
        {
            //arrange
            IRepository repository = MockRepository.GenerateStub<IRepository>();
            ICustomerRepository customerRepository = MockRepository.GenerateStub<ICustomerRepository>();
            IAccountServices accountServices = MockRepository.GenerateStub<IAccountServices>();
            IDtoCreator<Customer, CustomerDto> custCreator = new CustomerDtoCreator();

            Advisor advisor1 = new Advisor { Id = 1, FirstName = "Ad1"};
            Advisor advisor2 = new Advisor {Id=2,FirstName = "Ad2"};
            List<Customer> customers = new List<Customer>();
            customers.Add(new Customer { Advisor = advisor1, Id = 1});
            customers.Add(new Customer {Advisor = advisor2, Id = 2});
            advisor1.Customers = customers;
            //repository.Expect(x=>x.GetAll<Customer>()).Return(customers);
            repository.Expect(x => x.Get<Advisor>(advisor1.Id)).Return(advisor1);

            //act
            CustomerServices services = new CustomerServices(customerRepository, repository,accountServices,custCreator);
            List<CustomerDto> recieved = (List<CustomerDto>)services.GetCustomersForAdvisor(advisor1.Id);

            //assert
            Assert.AreEqual(recieved[0].Id, 1);
            repository.VerifyAllExpectations();
        }
예제 #6
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);
        }
예제 #7
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);
        }
예제 #8
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);
        }
예제 #9
0
        public void CreateIndividualCustomer_CustomerDtoOk()
        {
            //arrange
            ICustomerRepository thirdPartyRepository = MockRepository.GenerateMock<ICustomerRepository>();
            IRepository repository = MockRepository.GenerateMock<IRepository>();
            IAccountServices accountServices = MockRepository.GenerateStub<IAccountServices>();
            IDtoCreator<Customer, CustomerDto> custCreator = new CustomerDtoCreator();

            //act
            CustomerServices services = new CustomerServices(thirdPartyRepository, repository,accountServices,custCreator);
            services.CreateCustomer("toto", "titi", "email","123");

            //assert
            repository.AssertWasCalled(x => x.Save<Customer>(Arg<Customer>.Is.NotNull));
            repository.AssertWasCalled(x => x.Flush());
        }
예제 #10
0
        public void CreateIndividualCustomer_CustomerDtoOk()
        {
            //arrange
            ICustomerRepository thirdPartyRepository        = MockRepository.GenerateMock <ICustomerRepository>();
            IRepository         repository                  = MockRepository.GenerateMock <IRepository>();
            IAccountServices    accountServices             = MockRepository.GenerateStub <IAccountServices>();
            IDtoCreator <Customer, CustomerDto> custCreator = new CustomerDtoCreator();

            //act
            CustomerServices services = new CustomerServices(thirdPartyRepository, repository, accountServices, custCreator);

            services.CreateCustomer("toto", "titi", "email", "123");

            //assert
            repository.AssertWasCalled(x => x.Save <Customer>(Arg <Customer> .Is.NotNull));
            repository.AssertWasCalled(x => x.Flush());
        }
예제 #11
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);
        }
예제 #12
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);
        }
예제 #13
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);
        }
예제 #14
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);
        }
예제 #15
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;
        }
예제 #16
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;
        }
예제 #17
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);
        }
예제 #18
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;
        }
예제 #19
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;
        }
예제 #20
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;
        }