public void LockBankAccountReturnFalseIfBankAccountNotExist()
        {
            //Arrange
            SICustomerRepository customerRepository = new SICustomerRepository();
            IBankTransferService transferService = new BankTransferService();
            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();
            bankAccountRepository.UnitOfWorkGet = () =>
            {
                var uow = new SIUnitOfWork();
                uow.Commit = () => { };

                return uow;
            };
            bankAccountRepository.GetGuid = (guid) =>
            {
                return null;
            };

            IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService);

            //Act
            var result = bankingService.LockBankAccount(Guid.NewGuid());

            //Assert
            Assert.IsFalse(result);
        }
        public void AddNewCustomerReturnAdaptedDTO()
        {
            //Arrange
            var adapter = PrepareTypeAdapter();
            var countryRepository = new SICountryRepository();
            var customerRepository = new SICustomerRepository();
            customerRepository.AddCustomer = (customer) => { };
            customerRepository.UnitOfWorkGet = () =>
            {
                var uow = new SIUnitOfWork();
                uow.Commit = () => { };

                return uow;
            };

            var customerManagementService = new CustomerAppService(adapter, countryRepository, customerRepository);

            var customerDTO = new CustomerDTO()
            {
                CountryId = Guid.NewGuid(),
                FirstName = "Jhon",
                LastName = "El rojo"
            };

            //act
            var result = customerManagementService.AddNewCustomer(customerDTO);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Id != Guid.Empty);
            Assert.AreEqual(result.FirstName, customerDTO.FirstName);
            Assert.AreEqual(result.LastName, customerDTO.LastName);
        }
        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);
        }
        public void TestMethod(int customerId)
        {
            var repository = new SICustomerRepository();

            repository.InstanceBehavior = PexChooseBehavedBehavior.Instance;

            var discount = new Discount(repository);

            discount.CalculateCustomerDiscount(customerId);
        }
        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;
        }
        public void TestMethod1(int customerId)
        {
            var repository = new SICustomerRepository();

            repository.GetCustomerInt32 = (int custId) =>
                                              {
                                                  return new Customer(PexChoose.Value<Level>("level"), PexChoose.Value<int>("points"));
                                              };

            var discount = new Discount(repository);

            discount.CalculateCustomerDiscount(customerId);
        }
        public void AddNewCustomerThrowExceptionIfCustomerDtoIsNull()
        {
            //Arrange
            var countryRepository = new SICountryRepository();
            var customerRepository = new SICustomerRepository();

            var customerManagementService = new CustomerAppService(countryRepository, customerRepository);


            //act
            var result = customerManagementService.AddNewCustomer(null);

            //Assert
            Assert.IsNull(result);
        }
        public void FindOrdersInPageThrowArgumentExceptionWhenPageDataIsInvalid()
        {
            //Arrange
            
            var customerRepository = new SICustomerRepository();
            var productRepository = new SIProductRepository();
            var orderRepository = new SIOrderRepository();

            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            //act
            var resultInvalidPageIndex = salesManagement.FindOrders(-1, 1);
            
            //Assert
            Assert.IsNull(resultInvalidPageIndex);
        }
        public void AddNewCustomerThrowArgumentExceptionIfCustomerCountryInformationIsEmpty()
        {
            //Arrange
            var countryRepository = new SICountryRepository();
            var customerRepository = new SICustomerRepository();

            var customerManagementService = new CustomerAppService(countryRepository, customerRepository);

            var customerDTO = new CustomerDTO()
            {
                CountryId = Guid.Empty
            };

            //act
            var result = customerManagementService.AddNewCustomer(customerDTO);
        }
Exemple #10
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);
        }
Exemple #11
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);
        }
        public void AddBankAccountReturnDTOWhenSaveSucceed()
        {
            //Arrange
            IBankTransferService transferService = new BankTransferService();

            SICustomerRepository customerRepository = new SICustomerRepository();

            customerRepository.GetGuid = (guid) =>
            {
                var customer = new Customer()
                {
                    FirstName = "Jhon",
                    LastName  = "El rojo"
                };

                customer.ChangeCurrentIdentity(guid);

                return(customer);
            };

            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();

            bankAccountRepository.AddBankAccount = (ba) => { };
            bankAccountRepository.UnitOfWorkGet  = () =>
            {
                var uow = new SIUnitOfWork();
                uow.Commit = () => { };

                return(uow);
            };


            var dto = new BankAccountDTO()
            {
                CustomerId        = Guid.NewGuid(),
                BankAccountNumber = "BA"
            };

            IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService);

            //Act
            var result = bankingService.AddBankAccount(dto);

            //Assert
            Assert.IsNotNull(result);
        }
        public void AddBankAccountReturnNullWhenCustomerIdIsEmpty()
        {
            //Arrange
            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();
            SICustomerRepository    customerRepository    = new SICustomerRepository();
            IBankTransferService    transferService       = new BankTransferService();

            var dto = new BankAccountDTO()
            {
                CustomerId = Guid.Empty
            };

            IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService);

            //Act
            var result = bankingService.AddBankAccount(dto);
        }
Exemple #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);
        }
        public void FindBankAccountActivitiesReturnAllItems()
        {
            //Arrange
            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();

            bankAccountRepository.GetGuid = (guid) =>
            {
                var bActivity1 = new BankAccountActivity()
                {
                    Date = DateTime.Now, Amount = 1000
                };
                bActivity1.GenerateNewIdentity();

                var bActivity2 = new BankAccountActivity()
                {
                    Date = DateTime.Now, Amount = 1000
                };
                bActivity2.GenerateNewIdentity();

                var bankAccount = new BankAccount()
                {
                    BankAccountActivity = new HashSet <BankAccountActivity>()
                    {
                        bActivity1, bActivity2
                    }
                };
                bankAccount.GenerateNewIdentity();

                return(bankAccount);
            };

            SICustomerRepository customerRepository = new SICustomerRepository();
            IBankTransferService transferService    = new BankTransferService();

            IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService);

            //Act
            var result = bankingService.FindBankAccountActivities(Guid.NewGuid());


            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count == 2);
        }
        public void FindCountriesInPageReturnNullIfNotData()
        {
            //Arrange
            var customerRepository = new SICustomerRepository();
            var countryRepository  = new SICountryRepository();

            countryRepository.GetPagedInt32Int32ExpressionOfFuncOfCountryKPropertyBoolean <string>((index, count, order, ascending) =>
            {
                return(new List <Country>());
            });

            var customerManagementService = new CustomerAppService(countryRepository, customerRepository);

            //Act
            var result = customerManagementService.FindCountries(0, 1);

            //Assert
            Assert.IsNull(result);
        }
        public void FindCustomersInPageReturnNullIfNotData()
        {
            //Arrange
            var countryRepository  = new SICountryRepository();
            var customerRepository = new SICustomerRepository();

            customerRepository.GetEnabledInt32Int32 = (index, count) =>
            {
                return(new List <Customer>());
            };

            var customerManagementService = new CustomerAppService(countryRepository, customerRepository);

            //Act
            var result = customerManagementService.FindCustomers(0, 1);

            //Assert
            Assert.IsNull(result);
        }
        public void FindCountriesByFilterReturnNullIfNotData()
        {
            //Arrange
            var customerRepository = new SICustomerRepository();
            var countryRepository  = new SICountryRepository();

            countryRepository.AllMatchingISpecificationOfCountry = (spec) =>
            {
                return(new List <Country>());
            };

            var customerManagementService = new CustomerAppService(countryRepository, customerRepository);

            //Act
            var result = customerManagementService.FindCountries("filter");

            //Assert
            Assert.IsNull(result);
        }
Exemple #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);
        }
        public void AddNewBookReturnAddedBook()
        {
            //Arrange
            var adapter = PrepareTypeAdapter();
            var customerRepository = new SICustomerRepository();
            var orderRepository = new SIOrderRepository();
            var productRepository = new SIProductRepository();

            productRepository.UnitOfWorkGet = () =>
            {
                var uow = new SIUnitOfWork();
                uow.Commit = () => { };

                return uow;
            };

            productRepository.AddProduct = (product) => { };

            var salesManagement = new SalesAppService(adapter, productRepository, orderRepository,customerRepository);

            var dto = new BookDTO()
            {
                Title = "The title",
                Description = "description",
                Publisher = "license",
                ISBN = "isbn",
                AmountInStock = 10,
                UnitPrice = 10
            };

            //Act
            var result = salesManagement.AddNewBook(dto);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Id != Guid.Empty);
            Assert.AreEqual(result.Title, dto.Title);
            Assert.AreEqual(result.Description, dto.Description);
            Assert.AreEqual(result.Publisher, dto.Publisher);
            Assert.AreEqual(result.ISBN, dto.ISBN);
            Assert.AreEqual(result.AmountInStock, dto.AmountInStock);
            Assert.AreEqual(result.UnitPrice, dto.UnitPrice);
        }
Exemple #21
0
        public void FindOrdersWithInvalidPageIndexThrowException()
        {
            //Arrange

            var customerRepository = new SICustomerRepository();
            var productRepository  = new SIProductRepository();
            var orderRepository    = new SIOrderRepository();

            orderRepository.GetPagedInt32Int32ExpressionOfFuncOfOrderKPropertyBoolean <DateTime>((index, count, order, ascending) =>
            {
                return(new List <Order>());
            });


            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            //act
            var result = salesManagement.FindOrders(-1, 1);
        }
Exemple #22
0
        public void AddNewBookReturnAddedBook()
        {
            //Arrange
            var customerRepository = new SICustomerRepository();
            var orderRepository    = new SIOrderRepository();
            var productRepository  = new SIProductRepository();

            productRepository.UnitOfWorkGet = () =>
            {
                var uow = new SIUnitOfWork();
                uow.Commit = () => { };

                return(uow);
            };

            productRepository.AddProduct = (product) => { };


            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            var dto = new BookDTO()
            {
                Title         = "The title",
                Description   = "description",
                Publisher     = "license",
                ISBN          = "isbn",
                AmountInStock = 10,
                UnitPrice     = 10
            };

            //Act
            var result = salesManagement.AddNewBook(dto);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Id != Guid.Empty);
            Assert.AreEqual(result.Title, dto.Title);
            Assert.AreEqual(result.Description, dto.Description);
            Assert.AreEqual(result.Publisher, dto.Publisher);
            Assert.AreEqual(result.ISBN, dto.ISBN);
            Assert.AreEqual(result.AmountInStock, dto.AmountInStock);
            Assert.AreEqual(result.UnitPrice, dto.UnitPrice);
        }
Exemple #23
0
        public void FindOrderReturnNullIfCustomerIdIsEmpty()
        {
            //Arrange

            var customerRepository = new SICustomerRepository();
            var productRepository  = new SIProductRepository();
            var orderRepository    = new SIOrderRepository();

            orderRepository.GetFilteredExpressionOfFuncOfOrderBoolean = (expression) => null;

            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            //act
            var result = salesManagement.FindOrders(Guid.Empty);


            //Assert
            Assert.IsNull(result);
        }
        public void AddBankAccountReturnDTOWhenSaveSucceed()
        {
            //Arrange
            IBankTransferService transferService = new BankTransferService();

            ITypeAdapter adapter = PrepareTypeAdapter();

            SICustomerRepository customerRepository = new SICustomerRepository();
            customerRepository.GetGuid = (guid) =>
            {
                return new Customer()
                {
                    Id = guid,
                    FirstName = "Jhon",
                    LastName = "El rojo"
                };
            };

            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();
            bankAccountRepository.AddBankAccount = (ba) => { };
            bankAccountRepository.UnitOfWorkGet = () =>
            {
                var uow = new SIUnitOfWork();
                uow.Commit = () => { };

                return uow;
            };

            var dto = new BankAccountDTO()
            {
                CustomerId = Guid.NewGuid(),
                BankAccountNumber = "BA"
            };

            IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService, adapter);

            //Act
            var result = bankingService.AddBankAccount(dto);

            //Assert
            Assert.IsNotNull(result);
        }
        public void AddNewCustomerReturnAdaptedDTO()
        {
            //Arrange

            var countryRepository = new SICountryRepository();

            countryRepository.GetGuid = (guid) =>
            {
                var country = new Country("Spain", "es-ES");;
                country.ChangeCurrentIdentity(guid);

                return(country);
            };
            var customerRepository = new SICustomerRepository();

            customerRepository.AddCustomer   = (customer) => { };
            customerRepository.UnitOfWorkGet = () =>
            {
                var uow = new SIUnitOfWork();
                uow.Commit = () => { };

                return(uow);
            };

            var customerManagementService = new CustomerAppService(countryRepository, customerRepository);

            var customerDTO = new CustomerDTO()
            {
                CountryId = Guid.NewGuid(),
                FirstName = "Jhon",
                LastName  = "El rojo"
            };

            //act
            var result = customerManagementService.AddNewCustomer(customerDTO);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Id != Guid.Empty);
            Assert.AreEqual(result.FirstName, customerDTO.FirstName);
            Assert.AreEqual(result.LastName, customerDTO.LastName);
        }
        public void FindOrdersWithInvalidPageIndexThrowException()
        {
            //Arrange

            var customerRepository = new SICustomerRepository();
            var productRepository = new SIProductRepository();
            var orderRepository = new SIOrderRepository();
            orderRepository.GetPagedInt32Int32ExpressionOfFuncOfOrderKPropertyBoolean<DateTime>((index, count, order, ascending) =>
            {
                return new List<Order>();
            });


            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            //act
            var result = salesManagement.FindOrders(-1, 1);


        }
        public void AddBankAccountThrowInvalidOperationExceptionWhenCustomerNotExist()
        {
            //Arrange
            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();
            SICustomerRepository    customerRepository    = new SICustomerRepository();

            customerRepository.GetGuid = (guid) => { return(null); };

            IBankTransferService transferService = new BankTransferService();

            var dto = new BankAccountDTO()
            {
                CustomerId = Guid.NewGuid()
            };

            IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService);

            //Act
            bankingService.AddBankAccount(dto);
        }
Exemple #28
0
        public void AddNewOrderWithoutCustomerIdThrowArgumentException()
        {
            //Arrange

            var customerRepository = new SICustomerRepository();
            var productRepository  = new SIProductRepository();
            var orderRepository    = new SIOrderRepository();

            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            var order = new OrderDTO() // order is not valid when customer id is empty
            {
                CustomerId = Guid.Empty
            };

            //act
            var result = salesManagement.AddNewOrder(order);

            //assert
            Assert.IsNull(result);
        }
Exemple #29
0
        public void AddNewSoftwareThrowExceptionWhenDataIsInvalid()
        {
            //Arrange
            var customerRepository = new SICustomerRepository();
            var productRepository  = new SIProductRepository();
            var orderRepository    = new SIOrderRepository();

            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            var dto = new SoftwareDTO()
            {
                Title         = "The title",
                Description   = "the description",
                LicenseCode   = "license",
                AmountInStock = 10,
                UnitPrice     = -1//this is a not valid value
            };

            //Act
            var result = salesManagement.AddNewSoftware(dto);
        }
        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;
        }
        public void LockBankAccountReturnFalseIfIdentifierIsEmpty()
        {
            //Arrange
            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();
            bankAccountRepository.GetGuid = guid =>
            {
                if (guid == Guid.Empty)
                    return null;
                else
                    return new BankAccount { };
            };
            SICustomerRepository customerRepository = new SICustomerRepository();
            IBankTransferService transferService = new BankTransferService();

            IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService);

            //Act
            var result = bankingService.LockBankAccount(Guid.Empty);

            //Assert
            Assert.IsFalse(result);
        }
        public void FindBankAccountActivitiesReturnNullWhenBankAccountNotExists()
        {
            //Arrange

            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();

            bankAccountRepository.GetGuid = (guid) =>
            {
                return(null);
            };
            SICustomerRepository customerRepository = new SICustomerRepository();
            IBankTransferService transferService    = new BankTransferService();

            IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService);

            //Act
            var result = bankingService.FindBankAccountActivities(Guid.NewGuid());


            //Assert
            Assert.IsNull(result);
        }
Exemple #33
0
        public void FindProductsInPageReturnNullWhenNoData()
        {
            //Arrange

            var customerRepository = new SICustomerRepository();
            var orderRepository    = new SIOrderRepository();
            var productRepository  = new SIProductRepository();

            productRepository.GetPagedInt32Int32ExpressionOfFuncOfProductKPropertyBoolean <string>((index, count, order, ascending) =>
            {
                return(new List <Product>());
            });

            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            //act
            var result = salesManagement.FindProducts(0, 1);


            //Assert
            Assert.IsNull(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;
        }
Exemple #35
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);
        }
Exemple #36
0
        public void FindOrdersInDateRangeReturnNullWhenNoData()
        {
            //Arrange

            var customerRepository = new SICustomerRepository();
            var productRepository  = new SIProductRepository();
            var orderRepository    = new SIOrderRepository();

            orderRepository.AllMatchingISpecificationOfOrder = (spec) =>
            {
                return(new List <Order>());
            };

            var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository);

            //act
            var result = salesManagement.FindOrders(DateTime.Now.AddDays(-2), DateTime.Now.AddDays(+2));


            //Assert
            Assert.IsNull(result);
        }
        public void RemoveCustomerSetCustomerAsDisabled()
        {
            //Arrange
            var country = new Country("spain", "es-ES");

            country.GenerateNewIdentity();

            Guid customerId = Guid.NewGuid();

            var countryRepository  = new SICountryRepository();
            var customerRepository = new SICustomerRepository();

            customerRepository.UnitOfWorkGet = () =>
            {
                var uow = new SIUnitOfWork();
                uow.Commit = () => { };

                return(uow);
            };

            var customer = CustomerFactory.CreateCustomer("Jhon", "El rojo", "+3434", "company", country, new Address("city", "zipCode", "address line", "address line"));

            customer.ChangeCurrentIdentity(customerId);



            customerRepository.GetGuid = (guid) =>
            {
                return(customer);
            };

            //Act
            var customerManagementService = new CustomerAppService(countryRepository, customerRepository);

            customerManagementService.RemoveCustomer(customerId);

            //Assert
            Assert.IsFalse(customer.IsEnabled);
        }
        public void LockBankAccountReturnTrueIfBankAccountIsLocked()
        {
            //Arrange
            SICustomerRepository customerRepository = new SICustomerRepository();
            IBankTransferService transferService    = new BankTransferService();

            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();

            bankAccountRepository.UnitOfWorkGet = () =>
            {
                var uow = new SIUnitOfWork();
                uow.Commit = () => { };

                return(uow);
            };

            bankAccountRepository.GetGuid = (guid) =>
            {
                var customer = new Customer();
                customer.GenerateNewIdentity();

                var bankAccount = new BankAccount();
                bankAccount.GenerateNewIdentity();

                bankAccount.SetCustomerOwnerOfThisBankAccount(customer);

                return(bankAccount);
            };

            IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService);

            //Act
            var result = bankingService.LockBankAccount(Guid.NewGuid());

            //Assert
            Assert.IsTrue(result);
        }
        public void AddNewCustomerThrowApplicationErrorsWhenEntityIsNotValid()
        {
            //Arrange
            var countryId = Guid.NewGuid();

            var countryRepository = new SICountryRepository();

            countryRepository.GetGuid = (guid) =>
            {
                var country = new Country("spain", "es-ES");
                country.GenerateNewIdentity();

                return(country);
            };
            var customerRepository = new SICustomerRepository();

            customerRepository.AddCustomer   = (customer) => { };
            customerRepository.UnitOfWorkGet = () =>
            {
                var uow = new SIUnitOfWork();
                uow.Commit = () => { };

                return(uow);
            };

            var customerManagementService = new CustomerAppService(countryRepository, customerRepository);

            var customerDTO = new CustomerDTO() //missing lastname
            {
                CountryId = Guid.NewGuid(),
                FirstName = "Jhon"
            };

            //act
            var result = customerManagementService.AddNewCustomer(customerDTO);
        }
        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;
        }
        public void FindCustomerReturnNullIfCustomerIdIsEmpty()
        {
            //Arrange
            var countryRepository = new SICountryRepository();
            var customerRepository = new SICustomerRepository();
            customerRepository.GetGuid = (guid) =>
            {
                if (guid == Guid.Empty)
                    return null;
                else
                    return new Customer();
            };
            var customerManagementService = new CustomerAppService(countryRepository, customerRepository);

            //Act
            var result = customerManagementService.FindCustomer(Guid.Empty);

            //Assert
            Assert.IsNull(result);

        }
        public void FindCountriesInPageMaterializeResults()
        {
            //Arrange
            var customerRepository = new SICustomerRepository();
            var countryRepository = new SICountryRepository();
            countryRepository.GetPagedInt32Int32ExpressionOfFuncOfCountryKPropertyBoolean<string>((index, count, order, ascending) =>
            {
                var country = new Country("country name", "country iso");
                country.GenerateNewIdentity();

                return new List<Country>()
                {
                    country
                };
            });

            var customerManagementService = new CustomerAppService(countryRepository, customerRepository);

            //Act
            var result = customerManagementService.FindCountries(0, 1);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count == 1);
        }
        public void FindCountriesByFilterReturnNullIfNotData()
        {
            //Arrange
            var customerRepository = new SICustomerRepository();
            var countryRepository = new SICountryRepository();
            countryRepository.AllMatchingISpecificationOfCountry = (spec) =>
            {
                return new List<Country>();
            };

            var customerManagementService = new CustomerAppService(countryRepository, customerRepository);

            //Act
            var result = customerManagementService.FindCountries("filter");

            //Assert
            Assert.IsNull(result);
        }
        public void FindCountriesWithInvalidPageArgumentsReturnNull()
        {
            //Arrange
            var countryRepository = new SICountryRepository();
            var customerRepository = new SICustomerRepository();

            var customerManagementService = new CustomerAppService(countryRepository, customerRepository);

            //Act
            customerManagementService.FindCountries(-1, 0);
        }
        public void AddNewCustomerReturnAdaptedDTO()
        {
            //Arrange
             
            var countryRepository = new SICountryRepository();
            countryRepository.GetGuid = (guid) =>
            {
                var country = new Country("Spain", "es-ES"); ;
                country.ChangeCurrentIdentity(guid);

                return country;
            };
            var customerRepository = new SICustomerRepository();
            customerRepository.AddCustomer = (customer) => { };
            customerRepository.UnitOfWorkGet = () =>
            {
                var uow = new SIUnitOfWork();
                uow.Commit = () => { };

                return uow;
            };

            var customerManagementService = new CustomerAppService(countryRepository, customerRepository);

            var customerDTO = new CustomerDTO()
            {
                CountryId = Guid.NewGuid(),
                FirstName = "Jhon",
                LastName = "El rojo"
            };

            //act
            var result = customerManagementService.AddNewCustomer(customerDTO);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Id != Guid.Empty);
            Assert.AreEqual(result.FirstName, customerDTO.FirstName);
            Assert.AreEqual(result.LastName, customerDTO.LastName);
        }
        public void ConstructorThrowExceptionWhenCountryRepositoryDependencyIsNull()
        {
            //Arrange
            var customerRepository = new SICustomerRepository();
            SICountryRepository countryRepository = null;

            //act
            var customerManagementService = new CustomerAppService(countryRepository, customerRepository);

        }
        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 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 void FindCountriesByFilterMaterializeResults()
        {
            //Arrange
            var customerRepository = new SICustomerRepository();
            var countryRepository = new SICountryRepository();
            countryRepository.AllMatchingISpecificationOfCountry = (spec) =>
            {

                var country = new Country("country name", "country iso");
                country.GenerateNewIdentity();

                return new List<Country>()
                {
                   country
                };
            };

            var customerManagementService = new CustomerAppService(countryRepository, customerRepository);

            //Act
            var result = customerManagementService.FindCountries("filter");

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count == 1);
        }
        public void PerformBankTransfer()
        {
            //Arrange

            //--> source bank account data

            var sourceId = new Guid("3481009C-A037-49DB-AE05-44FF6DB67DEC");
            var bankAccountNumberSource = new BankAccountNumber("4444", "5555", "3333333333", "02");
            var sourceCustomer          = new Customer();

            sourceCustomer.GenerateNewIdentity();

            var source = BankAccountFactory.CreateBankAccount(sourceCustomer, bankAccountNumberSource);

            source.ChangeCurrentIdentity(sourceId);
            source.DepositMoney(1000, "initial");

            var sourceBankAccountDTO = new BankAccountDTO()
            {
                Id = sourceId,
                BankAccountNumber = source.Iban
            };

            //--> target bank account data
            var targetCustomer = new Customer();

            targetCustomer.GenerateNewIdentity();
            var targetId = new Guid("8A091975-F783-4730-9E03-831E9A9435C1");
            var bankAccountNumberTarget = new BankAccountNumber("1111", "2222", "3333333333", "01");
            var target = BankAccountFactory.CreateBankAccount(targetCustomer, bankAccountNumberTarget);

            target.ChangeCurrentIdentity(targetId);


            var targetBankAccountDTO = new BankAccountDTO()
            {
                Id = targetId,
                BankAccountNumber = target.Iban
            };

            var accounts = new List <BankAccount>()
            {
                source, target
            };


            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();

            bankAccountRepository.GetGuid = (guid) =>
            {
                return(accounts.Where(ba => ba.Id == guid).SingleOrDefault());
            };
            bankAccountRepository.UnitOfWorkGet = () =>
            {
                var unitOfWork = new SIUnitOfWork();
                unitOfWork.Commit = () => { };

                return(unitOfWork);
            };

            SICustomerRepository customerRepository = new SICustomerRepository();
            IBankTransferService transferService    = new BankTransferService();

            IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService);

            //Act
            bankingService.PerformBankTransfer(sourceBankAccountDTO, targetBankAccountDTO, 100M);


            //Assert
            Assert.AreEqual(source.Balance, 900);
            Assert.AreEqual(target.Balance, 100);
        }
        public void FindCustomerMaterializaResultIfExist()
        {
            //Arrange
            var countryRepository = new SICountryRepository();
            var customerRepository = new SICustomerRepository();
            var country = new Country("spain", "es-ES");
            country.GenerateNewIdentity();

            customerRepository.GetGuid = (guid) =>
            {
                return CustomerFactory.CreateCustomer("Jhon",
                                                      "El rojo",
                                                      "+3434344",
                                                      "company",
                                                      country,
                                                      new Address("city", "zipCode", "address line1", "address line2"));

            };

            var customerManagementService = new CustomerAppService(countryRepository, customerRepository);

            //Act
            var result = customerManagementService.FindCustomer(Guid.NewGuid());

            //Assert
            Assert.IsNotNull(result);
        }
        public void FindCustomersByFilterMaterializeResults()
        {
            //Arrange
            var countryRepository = new SICountryRepository();
            var customerRepository = new SICustomerRepository();
            var country = new Country("Spain", "es-ES");
            country.GenerateNewIdentity();

            customerRepository.AllMatchingISpecificationOfCustomer = (spec) =>
            {
                var customers = new List<Customer>();
                customers.Add(CustomerFactory.CreateCustomer("Jhon",
                                                            "El rojo",
                                                            "+34343",
                                                            "company",
                                                             country,
                                                             new Address("city", "zipCode", "address line", "address line2")));
                return customers;
            };


            var customerManagementService = new CustomerAppService(countryRepository, customerRepository);

            //Act
            var result = customerManagementService.FindCustomers("Jhon");

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count == 1);
        }
        public void FindCountriesInPageReturnNullIfNotData()
        {
            //Arrange
            var customerRepository = new SICustomerRepository();
            var countryRepository = new SICountryRepository();
            countryRepository.GetPagedInt32Int32ExpressionOfFuncOfCountryKPropertyBoolean<string>((index, count, order, ascending) =>
            {
                return new List<Country>();
            });

            var customerManagementService = new CustomerAppService(countryRepository, customerRepository);

            //Act
            var result = customerManagementService.FindCountries(0, 1);

            //Assert
            Assert.IsNull(result);
        }