コード例 #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);
        }
コード例 #2
0
        public string Transfer(
            Account debitAccount,
            Account creditAccount,
            decimal amount,
            string motif
            )
        {
            MGuid.NewGuid = () => new Guid("64d80a10-4f21-4acb-9d3d-0332e68c4394");

            PexAssume.IsNotNull(debitAccount);
            PexAssume.IsNotNull(creditAccount);
            PexAssume.IsTrue(creditAccount != debitAccount);
            var repository          = new SIRepository();
            var operationRepository = new SIOperationRepository();
            var operationCreator    = new OperationDtoCreator();

            //act
            var operationServices = new OperationServices(operationRepository, repository, operationCreator);

            operationServices.Transfer(debitAccount, creditAccount, amount, motif);

            string result = operationServices.Transfer(debitAccount, creditAccount, amount, motif);

            PexAssert.IsNotNullOrEmpty(result);
            return(result);
        }
コード例 #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);
        }
コード例 #4
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);
        }
コード例 #5
0
        public decimal Balance(Account account)
        {
            SIRepository repository = new SIRepository();
            SIAccountRepository accountRepository = new SIAccountRepository();
            SICustomerRepository customerRepository = new SICustomerRepository();
            IDtoCreator<Account, AccountDto> accountCreator = new AccountDtoCreator();

            //act
            var accountServices = new AccountServices(repository, accountRepository, customerRepository, accountCreator);
            var result = accountServices.Balance(account);
            return result;
        }
コード例 #6
0
        public decimal Balance(Account account)
        {
            SIRepository         repository                  = new SIRepository();
            SIAccountRepository  accountRepository           = new SIAccountRepository();
            SICustomerRepository customerRepository          = new SICustomerRepository();
            IDtoCreator <Account, AccountDto> accountCreator = new AccountDtoCreator();

            //act
            var accountServices = new AccountServices(repository, accountRepository, customerRepository, accountCreator);
            var result          = accountServices.Balance(account);

            return(result);
        }
コード例 #7
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);
        }
コード例 #8
0
        internal AdvisorDto GetAdvisorById(int id)
        {
            SIAdvisorRepository advisorRepository = new SIAdvisorRepository();
            SIRepository        repository        = new SIRepository();
            IDtoCreator <Advisor, AdvisorDto> advisorDtoCreator = new AdvisorDtoCreator();

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

            AdvisorServices advisorServices = new AdvisorServices(repository, advisorRepository, advisorDtoCreator);
            var             result          = advisorServices.GetAdvisorById(id);

            return(result);
        }
コード例 #9
0
        public void MakeTransfer(int debitAccountId, int creditAccountId, decimal amount, string motif)
        {
            PexAssume.IsTrue(amount > 100);

            var repository = new SIRepository();
            repository.GetObject<Account>((x) => _accounts.SingleOrDefault(a => a.Id == (int)x));

            var operationRepository = new SIOperationRepository();
            var operationCreator = new OperationDtoCreator();

            //act
            var operationServices = new OperationServices(operationRepository, repository, operationCreator);
            operationServices.MakeTransfer(debitAccountId, creditAccountId, amount, motif);
        }
コード例 #10
0
        internal AdvisorDto GetAdvisorByIdentity(string identity)
        {
            //arrange
            SIAdvisorRepository advisorRepository = new SIAdvisorRepository();
            SIRepository        repository        = new SIRepository();
            IDtoCreator <Advisor, AdvisorDto> advisorDtoCreator = new AdvisorDtoCreator();

            advisorRepository.GetAdvisorByIdentityString = (x) => _advisors.SingleOrDefault(a => a.Identification == x);

            //act
            AdvisorServices services = new AdvisorServices(repository, advisorRepository, advisorDtoCreator);
            AdvisorDto      result   = services.GetAdvisorByIdentity(identity);

            return(result);
        }
コード例 #11
0
        public void MakeTransfer(int debitAccountId, int creditAccountId, decimal amount, string motif)
        {
            PexAssume.IsTrue(amount > 100);

            var repository = new SIRepository();

            repository.GetObject <Account>((x) => _accounts.SingleOrDefault(a => a.Id == (int)x));

            var operationRepository = new SIOperationRepository();
            var operationCreator    = new OperationDtoCreator();

            //act
            var operationServices = new OperationServices(operationRepository, repository, operationCreator);

            operationServices.MakeTransfer(debitAccountId, creditAccountId, amount, motif);
        }
コード例 #12
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);
        }
コード例 #13
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);
        }
コード例 #14
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);
        }
コード例 #15
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);
        }
コード例 #16
0
        public UserIdentityDto AuthenticateIndividualCustomer(string identity, string password)
        {
            var repository = new SIRepository();
            var customerRepository = new SICustomerRepository();
            var userRepository = new SIUserRepository();
            var hashProvider = new SIHashProvider();

            IDtoCreator<UserIdentity, UserIdentityDto> identityCreator = new UserIdentityDtoCreator();
            hashProvider.HashString = (x) => x;

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

            //act
            UserServices userServices = new UserServices(customerRepository, repository,null,hashProvider, identityCreator);
            UserIdentityDto result = userServices.AuthenticateUser(identity, password);

            //assert
            PexAssert.Case(identity == _customers[0].Identification && password == _customers[0].Password)
                    .Implies(() => result.Email == _customers[0].Email);
            return result;
        }
コード例 #17
0
        public UserIdentityDto AuthenticateIndividualCustomer(string identity, string password)
        {
            var repository         = new SIRepository();
            var customerRepository = new SICustomerRepository();
            var userRepository     = new SIUserRepository();
            var hashProvider       = new SIHashProvider();

            IDtoCreator <UserIdentity, UserIdentityDto> identityCreator = new UserIdentityDtoCreator();

            hashProvider.HashString = (x) => x;

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

            //act
            UserServices    userServices = new UserServices(customerRepository, repository, null, hashProvider, identityCreator);
            UserIdentityDto result       = userServices.AuthenticateUser(identity, password);

            //assert
            PexAssert.Case(identity == _customers[0].Identification && password == _customers[0].Password)
            .Implies(() => result.Email == _customers[0].Email);
            return(result);
        }
コード例 #18
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;
        }
コード例 #19
0
        public string Transfer(
            Account debitAccount,
            Account creditAccount,
            decimal amount,
            string motif
        )
        {
            MGuid.NewGuid = () => new Guid("64d80a10-4f21-4acb-9d3d-0332e68c4394");

            PexAssume.IsNotNull(debitAccount);
            PexAssume.IsNotNull(creditAccount);
            PexAssume.IsTrue(creditAccount != debitAccount);
            var repository = new SIRepository();
            var operationRepository = new SIOperationRepository();
            var operationCreator = new OperationDtoCreator();

            //act
            var operationServices = new OperationServices(operationRepository, repository, operationCreator);
            operationServices.Transfer(debitAccount, creditAccount, amount, motif);

            string result = operationServices.Transfer(debitAccount, creditAccount, amount, motif);
            PexAssert.IsNotNullOrEmpty(result);
            return result;
        }
コード例 #20
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;
        }
コード例 #21
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);
        }
コード例 #22
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;
        }
コード例 #23
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;
        }
コード例 #24
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;
        }