public void LockBankAccountReturnFalseIfIdentifierIsEmpty() { //Arrange var bankAccountRepository = new StubIBankAccountRepository(); bankAccountRepository.GetGuid = guid => { if (guid == Guid.Empty) { return(null); } else { return(new BankAccount { }); } }; var customerRepository = new StubICustomerRepository(); IBankTransferService transferService = new BankTransferService(); IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService); //Act var result = bankingService.LockBankAccount(Guid.Empty); //Assert Assert.IsFalse(result); }
public void TestAnotherInterface() { //var stub = new StubICustomerRepository //{ // GetAll = () => new[] // { // new Customer {Id = 1, Name = "John", Email = "*****@*****.**"}, // new Customer {Id = 2, Name = "Peter", Email = "*****@*****.**"} // } //}; // Arrange var savedCustomer = default(Customer); // null var repository = new StubICustomerRepository { SaveOrUpdateCustomer = customer => savedCustomer = customer }; var actualCustomer = new Customer { Id = 1, Name = "Sample Customer" }; var viewModel = new CustomerViewModel(actualCustomer, repository); // Act viewModel.Save(); // Assert Assert.IsNotNull(savedCustomer); Assert.IsTrue(savedCustomer.Id == 1); Assert.IsTrue(savedCustomer.Name == "Sample Customer"); }
public void FindCustomerReturnNullIfCustomerIdIsEmpty() { //Arrange var countryRepository = new StubICountryRepository(); var customerRepository = new StubICustomerRepository(); 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 FindCustomersByFilterMaterializeResults() { //Arrange var countryRepository = new StubICountryRepository(); var customerRepository = new StubICustomerRepository(); 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 LockBankAccountReturnFalseIfIdentifierIsEmpty() { //Arrange var bankAccountRepository = new StubIBankAccountRepository(); bankAccountRepository.GetGuid = guid => { if (guid == Guid.Empty) { return null; } else { return new BankAccount { }; } }; var customerRepository = new StubICustomerRepository(); IBankTransferService transferService = new BankTransferService(); IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService); //Act var result = bankingService.LockBankAccount(Guid.Empty); //Assert Assert.IsFalse(result); }
public void FindCustomersInPageMaterializeResults() { //Arrange var countryRepository = new StubICountryRepository(); var customerRepository = new StubICustomerRepository(); var country = new Country("spain", "es-ES"); country.GenerateNewIdentity(); customerRepository.GetEnabledInt32Int32 = (index, count) => { var customers = new List <Customer>(); customers.Add( CustomerFactory.CreateCustomer( "Jhon", "El rojo", "+343", "company", country, new Address("city", "zipCode", "address line", "address line2"))); return(customers); }; var customerManagementService = new CustomerAppService(countryRepository, customerRepository); //Act var result = customerManagementService.FindCustomers(0, 1); //Assert Assert.IsNotNull(result); Assert.IsTrue(result.Count == 1); }
public void FindCustomerMaterializaResultIfExist() { //Arrange var countryRepository = new StubICountryRepository(); var customerRepository = new StubICustomerRepository(); 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 FindCountriesByFilterMaterializeResults() { //Arrange var customerRepository = new StubICustomerRepository(); var countryRepository = new StubICountryRepository(); 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 FindBankAccountsReturnAllItems() { var bankAccountRepository = new StubIBankAccountRepository(); bankAccountRepository.GetAll = () => { var customer = new Customer(); customer.GenerateNewIdentity(); var bankAccount = new BankAccount() { BankAccountNumber = new BankAccountNumber("4444", "5555", "3333333333", "02"), }; bankAccount.SetCustomerOwnerOfThisBankAccount(customer); bankAccount.GenerateNewIdentity(); var accounts = new List <BankAccount>() { bankAccount }; return(accounts); }; var customerRepository = new StubICustomerRepository(); IBankTransferService transferService = new BankTransferService(); IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService); //Act var result = bankingService.FindBankAccounts(); Assert.IsNotNull(result); Assert.IsTrue(result.Count == 1); }
public void FindProductsInPageReturnNullWhenNoData() { //Arrange var customerRepository = new StubICustomerRepository(); var orderRepository = new StubIOrderRepository(); var productRepository = new StubIProductRepository(); //productRepository.GetPagedInt32Int32ExpressionOfFuncOfProductKPropertyBoolean<string>( // (index, count, order, ascending) => { return new List<Product>(); }); productRepository.GetPagedOf1Int32Int32ExpressionOfFuncOfProductM0Boolean <string>( (index, count, order, @ascending) => new List <Product>()); //productRepository.GetPagedOf1Int32Int32ExpressionOfFuncOfProductM0Boolean<string>( // delegate(int index, int count, Expression<Func<Product, string>> order, bool ascending) // { // return new List<Product>(); // }); var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository); //act var result = salesManagement.FindProducts(0, 1); //Assert Assert.IsNull(result); }
public void FindOrdersInDateRangeMaterializeResults() { //Arrange var customerRepository = new StubICustomerRepository(); var productRepository = new StubIProductRepository(); var orderRepository = new StubIOrderRepository(); orderRepository.AllMatchingISpecificationOfOrder = (spec) => { var order = new Order(); order.GenerateNewIdentity(); order.SetTheCustomerReferenceForThisOrder(Guid.NewGuid()); return(new List <Order>() { order }); }; var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository); //act var result = salesManagement.FindOrders(DateTime.Now.AddDays(-2), DateTime.Now.AddDays(-1)); //Assert Assert.IsNotNull(result); Assert.IsTrue(result.Any()); }
public void AddNewOrderWithTotalGreaterCustomerCreditReturnNull() { //Arrange var productRepository = new StubIProductRepository(); var orderRepository = new StubIOrderRepository(); var customerRepository = new StubICustomerRepository(); var country = new Country("spain", "es-ES"); country.GenerateNewIdentity(); customerRepository.GetGuid = (guid) => { //default credit limit is 1000 var customer = CustomerFactory.CreateCustomer( "Jhon", "El rojo", "+34343", "company", country, new Address("city", "zipCode", "addressline1", "addressline2")); return(customer); }; orderRepository.UnitOfWorkGet = () => { var uow = new StubIUnitOfWork(); uow.Commit = () => { }; return(uow); }; orderRepository.AddOrder = (order) => { }; var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository); var dto = new OrderDto() { CustomerId = Guid.NewGuid(), ShippingAddress = "Address", ShippingCity = "city", ShippingName = "name", ShippingZipCode = "zipcode", OrderLines = new List <OrderLineDto>() { new OrderLineDto() { ProductId = Guid.NewGuid(), Amount = 1, Discount = 0, UnitPrice = 2000 } } }; //act var result = salesManagement.AddNewOrder(dto); //assert Assert.IsNull(result); }
public void FindOrdersMaterializeResultsIfCustomerExist() { //Arrange var customerRepository = new StubICustomerRepository(); var productRepository = new StubIProductRepository(); var orderRepository = new StubIOrderRepository(); orderRepository.GetFilteredExpressionOfFuncOfOrderBoolean = (filter) => { var orders = new List <Order>(); var customer = new Customer(); customer.ChangeCurrentIdentity(Guid.NewGuid()); orders.Add(OrderFactory.CreateOrder(customer, "name", "city", "address", "zipcode")); return(orders); }; var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository); //act var result = salesManagement.FindOrders(Guid.NewGuid()); //Assert Assert.IsNotNull(result); Assert.IsTrue(result.Count == 1); }
public void FindOrdersInPageMaterializeResults() { //Arrange var customerRepository = new StubICustomerRepository(); var productRepository = new StubIProductRepository(); var orderRepository = new StubIOrderRepository(); //orderRepository.GetPagedInt32Int32ExpressionOfFuncOfOrderKPropertyBoolean<DateTime>( // (index, count, order, ascending) => // { // var item = new Order(); // item.GenerateNewIdentity(); // item.SetTheCustomerReferenceForThisOrder(Guid.NewGuid()); // return new List<Order>() // { // item // }; // }); orderRepository.GetPagedOf1Int32Int32ExpressionOfFuncOfOrderM0Boolean <DateTime>( FindOrdersInPageMaterializeResults); var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository); //act var result = salesManagement.FindOrders(0, 1); //Assert Assert.IsNotNull(result); Assert.IsTrue(result.Any()); }
public void FindBankAccountActivitiesReturnNullWhenBankAccountIdIsEmpty() { //Arrange var bankAccountRepository = new StubIBankAccountRepository(); bankAccountRepository.GetGuid = guid => { if (guid == Guid.Empty) { return(null); } else { return(new BankAccount { }); } }; var customerRepository = new StubICustomerRepository(); IBankTransferService transferService = new BankTransferService(); IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService); //Act var result = bankingService.FindBankAccountActivities(Guid.Empty); //Assert Assert.IsNull(result); }
public void FindProductsByFilterMaterializeResults() { //Arrange var customerRepository = new StubICustomerRepository(); var productRepository = new StubIProductRepository(); var orderRepository = new StubIOrderRepository(); productRepository.AllMatchingISpecificationOfProduct = (spec) => { var book = new Book("title", "description", "publisher", "isbn"); book.ChangeUnitPrice(10); book.GenerateNewIdentity(); var software = new Software("title", "description", "license code"); software.ChangeUnitPrice(10); software.GenerateNewIdentity(); return(new List <Product>() { book, software }); }; var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository); //act var result = salesManagement.FindProducts("filter text"); //Assert Assert.IsNotNull(result); Assert.IsTrue(result.Count == 2); }
public void ConstructorThrowExceptionWhenCountryRepositoryDependencyIsNull() { //Arrange var customerRepository = new StubICustomerRepository(); StubICountryRepository countryRepository = null; //act var customerManagementService = new CustomerAppService(countryRepository, customerRepository); }
public void ConstructorThrowExceptionIfCustomerRepositoryDependencyIsNull() { //Arrange StubICustomerRepository customerRepository = null; var orderRepository = new StubIOrderRepository(); var productRepository = new StubIProductRepository(); //Act var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository); }
public void UpdateCustomerMergePersistentAndCurrent() { //Arrange var country = new Country("spain", "es-ES"); country.GenerateNewIdentity(); var customerId = Guid.NewGuid(); var countryRepository = new StubICountryRepository(); var customerRepository = new StubICustomerRepository(); customerRepository.UnitOfWorkGet = () => { var uow = new StubIUnitOfWork(); uow.Commit = () => { }; return(uow); }; customerRepository.GetGuid = (guid) => { var customer = CustomerFactory.CreateCustomer( "Jhon", "El rojo", "+3434", "company", country, new Address("city", "zipCode", "address line", "address line")); customer.ChangeCurrentIdentity(customerId); return(customer); }; customerRepository.MergeCustomerCustomer = (persistent, current) => { Assert.AreEqual(persistent, current); Assert.IsTrue(persistent != null); Assert.IsTrue(current != null); }; var customerManagementService = new CustomerAppService(countryRepository, customerRepository); var customerDto = new CustomerDto() //missing lastname { Id = customerId, CountryId = country.Id, FirstName = "Jhon", LastName = "El rojo", }; //act customerManagementService.UpdateCustomer(customerDto); }
public void FindCountriesWithInvalidPageArgumentsReturnNull() { //Arrange var countryRepository = new StubICountryRepository(); var customerRepository = new StubICustomerRepository(); var customerManagementService = new CustomerAppService(countryRepository, customerRepository); //Act customerManagementService.FindCountries(-1, 0); }
public void FindCustomersWithInvalidPageArgumentsThrowArgumentException() { //Arrange var countryRepository = new StubICountryRepository(); var customerRepository = new StubICustomerRepository(); var customerManagementService = new CustomerAppService(countryRepository, customerRepository); //Act customerManagementService.FindCustomers(-1, 0); }
public void FindProductsInPageMaterializeResults() { //Arrange var customerRepository = new StubICustomerRepository(); var productRepository = new StubIProductRepository(); var orderRepository = new StubIOrderRepository(); //productRepository.GetPagedInt32Int32ExpressionOfFuncOfProductKPropertyBoolean<string>( // (index, count, order, ascending) => // { // var book = new Book("title", "description", "publisher", "isbn"); // book.ChangeUnitPrice(10M); // book.GenerateNewIdentity(); // var software = new Software("title", "description", "license code"); // software.ChangeUnitPrice(10); // software.GenerateNewIdentity(); // return new List<Product>() // { // book, // software // }; // }); productRepository.GetPagedOf1Int32Int32ExpressionOfFuncOfProductM0Boolean <string>( (index, count, order, ascending) => { var book = new Book("title", "description", "publisher", "isbn"); book.ChangeUnitPrice(10M); book.GenerateNewIdentity(); var software = new Software("title", "description", "license code"); software.ChangeUnitPrice(10); software.GenerateNewIdentity(); return(new List <Product> { book, software }); }); var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository); //act var result = salesManagement.FindProducts(0, 2); //Assert Assert.IsNotNull(result); Assert.IsTrue(result.Count == 2); }
public void AddNewSoftwareWithNullDataThrowArgumentException() { //Arrange var customerRepository = new StubICustomerRepository(); var productRepository = new StubIProductRepository(); var orderRepository = new StubIOrderRepository(); var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository); //Act var result = salesManagement.AddNewSoftware(null); }
public void FindProductsInPageThrowExceptionWhenPageIsInvalid() { //Arrange var customerRepository = new StubICustomerRepository(); var productRepository = new StubIProductRepository(); var orderRepository = new StubIOrderRepository(); var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository); //act var resultInvalidPageIndex = salesManagement.FindProducts(-1, 1); }
public void ConstructorThrowExceptionIfBankAccountRepositoryDependencyIsNull() { //Arrange StubICustomerRepository customerRepository = new StubICustomerRepository(); StubIBankAccountRepository bankAcccountRepository = null; IBankTransferService transferService = new BankTransferService(); //Act IBankAppService bankingService = new BankAppService( bankAcccountRepository, customerRepository, transferService); }
public void AddNewCustomerThrowExceptionIfCustomerDtoIsNull() { //Arrange var countryRepository = new StubICountryRepository(); var customerRepository = new StubICustomerRepository(); var customerManagementService = new CustomerAppService(countryRepository, customerRepository); //act var result = customerManagementService.AddNewCustomer(null); //Assert Assert.IsNull(result); }
public void FindCustomersInPageReturnNullIfNotData() { //Arrange var countryRepository = new StubICountryRepository(); var customerRepository = new StubICustomerRepository(); 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 AddNewCustomerThrowArgumentExceptionIfCustomerCountryInformationIsEmpty() { //Arrange var countryRepository = new StubICountryRepository(); var customerRepository = new StubICustomerRepository(); var customerManagementService = new CustomerAppService(countryRepository, customerRepository); var customerDto = new CustomerDto() { CountryId = Guid.Empty }; //act var result = customerManagementService.AddNewCustomer(customerDto); }
public void FindCountriesByFilterReturnNullIfNotData() { //Arrange var customerRepository = new StubICustomerRepository(); var countryRepository = new StubICountryRepository(); 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 FindOrdersInPageThrowArgumentExceptionWhenPageDataIsInvalid() { //Arrange var customerRepository = new StubICustomerRepository(); var productRepository = new StubIProductRepository(); var orderRepository = new StubIOrderRepository(); var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository); //act var resultInvalidPageIndex = salesManagement.FindOrders(-1, 1); //Assert Assert.IsNull(resultInvalidPageIndex); }
public void AddBankAccountThrowArgumentNullExceptionWhenBankAccountDtoIsNull() { //Arrange var bankAccountRepository = new StubIBankAccountRepository(); var customerRepository = new StubICustomerRepository(); IBankTransferService transferService = new BankTransferService(); IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService); //Act var result = bankingService.AddBankAccount(null); //Assert Assert.IsNull(result); }
public void FindOrdersWithInvalidPageIndexThrowException() { //Arrange var customerRepository = new StubICustomerRepository(); var productRepository = new StubIProductRepository(); var orderRepository = new StubIOrderRepository(); //orderRepository.GetPagedInt32Int32ExpressionOfFuncOfOrderKPropertyBoolean<DateTime>( // (index, count, order, ascending) => { return new List<Order>(); }); orderRepository.GetPagedOf1Int32Int32ExpressionOfFuncOfOrderM0Boolean<DateTime>( FindOrdersWithInvalidPageIndexThrowException); var salesManagement = new SalesAppService(productRepository, orderRepository, customerRepository); //act var result = salesManagement.FindOrders(-1, 1); }
public void AddNewCustomerReturnAdaptedDto() { //Arrange var countryRepository = new StubICountryRepository(); countryRepository.GetGuid = (guid) => { var country = new Country("Spain", "es-ES"); ; country.ChangeCurrentIdentity(guid); return country; }; var customerRepository = new StubICustomerRepository(); customerRepository.AddCustomer = (customer) => { }; customerRepository.UnitOfWorkGet = () => { var uow = new StubIUnitOfWork(); 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 LockBankAccountReturnFalseIfBankAccountNotExist() { //Arrange var customerRepository = new StubICustomerRepository(); IBankTransferService transferService = new BankTransferService(); var bankAccountRepository = new StubIBankAccountRepository(); bankAccountRepository.UnitOfWorkGet = () => { var uow = new StubIUnitOfWork(); 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 AddBankAccountThrowInvalidOperationExceptionWhenCustomerNotExist() { //Arrange var bankAccountRepository = new StubIBankAccountRepository(); var customerRepository = new StubICustomerRepository(); 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); }
public void AddBankAccountReturnNullWhenCustomerIdIsEmpty() { //Arrange var bankAccountRepository = new StubIBankAccountRepository(); var customerRepository = new StubICustomerRepository(); IBankTransferService transferService = new BankTransferService(); var dto = new BankAccountDto() { CustomerId = Guid.Empty }; IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService); //Act var result = bankingService.AddBankAccount(dto); }
public void FindCustomersInPageMaterializeResults() { //Arrange var countryRepository = new StubICountryRepository(); var customerRepository = new StubICustomerRepository(); var country = new Country("spain", "es-ES"); country.GenerateNewIdentity(); customerRepository.GetEnabledInt32Int32 = (index, count) => { var customers = new List<Customer>(); customers.Add( CustomerFactory.CreateCustomer( "Jhon", "El rojo", "+343", "company", country, new Address("city", "zipCode", "address line", "address line2"))); return customers; }; var customerManagementService = new CustomerAppService(countryRepository, customerRepository); //Act var result = customerManagementService.FindCustomers(0, 1); //Assert Assert.IsNotNull(result); Assert.IsTrue(result.Count == 1); }
public void FindBankAccountActivitiesReturnNullWhenBankAccountIdIsEmpty() { //Arrange var bankAccountRepository = new StubIBankAccountRepository(); bankAccountRepository.GetGuid = guid => { if (guid == Guid.Empty) { return null; } else { return new BankAccount { }; } }; var customerRepository = new StubICustomerRepository(); IBankTransferService transferService = new BankTransferService(); IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService); //Act var result = bankingService.FindBankAccountActivities(Guid.Empty); //Assert Assert.IsNull(result); }
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 }; var bankAccountRepository = new StubIBankAccountRepository(); bankAccountRepository.GetGuid = (guid) => { return accounts.Where(ba => ba.Id == guid).SingleOrDefault(); }; bankAccountRepository.UnitOfWorkGet = () => { var unitOfWork = new StubIUnitOfWork(); unitOfWork.Commit = () => { }; return unitOfWork; }; var customerRepository = new StubICustomerRepository(); 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 StubICountryRepository(); var customerRepository = new StubICustomerRepository(); 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 FindCustomerReturnNullIfCustomerIdIsEmpty() { //Arrange var countryRepository = new StubICountryRepository(); var customerRepository = new StubICustomerRepository(); 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 AddBankAccountReturnDtoWhenSaveSucceed() { //Arrange IBankTransferService transferService = new BankTransferService(); var customerRepository = new StubICustomerRepository(); customerRepository.GetGuid = (guid) => { var customer = new Customer() { FirstName = "Jhon", LastName = "El rojo" }; customer.ChangeCurrentIdentity(guid); return customer; }; var bankAccountRepository = new StubIBankAccountRepository(); bankAccountRepository.AddBankAccount = (ba) => { }; bankAccountRepository.UnitOfWorkGet = () => { var uow = new StubIUnitOfWork(); 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 FindBankAccountActivitiesReturnAllItems() { //Arrange var bankAccountRepository = new StubIBankAccountRepository(); 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; }; var customerRepository = new StubICustomerRepository(); 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 FindBankAccountsReturnAllItems() { var bankAccountRepository = new StubIBankAccountRepository(); bankAccountRepository.GetAll = () => { var customer = new Customer(); customer.GenerateNewIdentity(); var bankAccount = new BankAccount() { BankAccountNumber = new BankAccountNumber("4444", "5555", "3333333333", "02"), }; bankAccount.SetCustomerOwnerOfThisBankAccount(customer); bankAccount.GenerateNewIdentity(); var accounts = new List<BankAccount>() { bankAccount }; return accounts; }; var customerRepository = new StubICustomerRepository(); IBankTransferService transferService = new BankTransferService(); IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService); //Act var result = bankingService.FindBankAccounts(); Assert.IsNotNull(result); Assert.IsTrue(result.Count == 1); }
public void FindCustomersByFilterMaterializeResults() { //Arrange var countryRepository = new StubICountryRepository(); var customerRepository = new StubICustomerRepository(); 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 FindBankAccountActivitiesReturnNullWhenBankAccountNotExists() { //Arrange var bankAccountRepository = new StubIBankAccountRepository(); bankAccountRepository.GetGuid = (guid) => { return null; }; var customerRepository = new StubICustomerRepository(); IBankTransferService transferService = new BankTransferService(); IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService); //Act var result = bankingService.FindBankAccountActivities(Guid.NewGuid()); //Assert Assert.IsNull(result); }
public void FindCountriesByFilterReturnNullIfNotData() { //Arrange var customerRepository = new StubICustomerRepository(); var countryRepository = new StubICountryRepository(); 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 FindCountriesInPageReturnNullIfNotData() { //Arrange var customerRepository = new StubICustomerRepository(); var countryRepository = new StubICountryRepository(); //countryRepository.GetPagedInt32Int32ExpressionOfFuncOfCountryKPropertyBoolean<string>( // (index, count, order, ascending) => { return new List<Country>(); }); countryRepository.GetPagedOf1Int32Int32ExpressionOfFuncOfCountryM0Boolean<string>( (index, count, order, ascending) => 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 StubICountryRepository(); var customerRepository = new StubICustomerRepository(); 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 FindCountriesInPageMaterializeResults() { //Arrange var customerRepository = new StubICustomerRepository(); var countryRepository = new StubICountryRepository(); /* countryRepository.GetPagedInt32Int32ExpressionOfFuncOfCountryKPropertyBoolean<string>( (index, count, order, ascending) => { var country = new Country("country name", "country iso"); country.GenerateNewIdentity(); return new List<Country>() { country }; });*/ countryRepository.GetPagedOf1Int32Int32ExpressionOfFuncOfCountryM0Boolean<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 LockBankAccountReturnTrueIfBankAccountIsLocked() { //Arrange var customerRepository = new StubICustomerRepository(); IBankTransferService transferService = new BankTransferService(); var bankAccountRepository = new StubIBankAccountRepository(); bankAccountRepository.UnitOfWorkGet = () => { var uow = new StubIUnitOfWork(); 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 FindCountriesByFilterMaterializeResults() { //Arrange var customerRepository = new StubICustomerRepository(); var countryRepository = new StubICountryRepository(); 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); }