public void AddNewValidOrderReturnAddedOrder() { //Arrange var productRepository = new SIProductRepository(); var orderRepository = new SIOrderRepository(); var customerRepository = new SICustomerRepository(); 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 SIUnitOfWork(); 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 = 20 } } }; //act var result = salesManagement.AddNewOrder(dto); //assert Assert.IsNotNull(result); Assert.IsTrue(result.Id != Guid.Empty); Assert.AreEqual(result.ShippingAddress, dto.ShippingAddress); Assert.AreEqual(result.ShippingCity, dto.ShippingCity); Assert.AreEqual(result.ShippingName, dto.ShippingName); Assert.AreEqual(result.ShippingZipCode, dto.ShippingZipCode); Assert.IsTrue(result.OrderLines.Count == 1); Assert.IsTrue(result.OrderLines.All(ol => ol.Id != Guid.Empty)); }
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 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 UpdateCustomerMergePersistentAndCurrent() { //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); }; 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 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 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); }
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); }
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 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 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 UpdateCustomerMergePersistentAndCurrent() { //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; }; 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 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 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 void AddNewSoftwareReturnAddedSoftware() { //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 SoftwareDTO() { Title = "The title", Description = "description", LicenseCode = "license code", AmountInStock = 10, UnitPrice = 10 }; //Act var result = salesManagement.AddNewSoftware(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.LicenseCode, dto.LicenseCode); Assert.AreEqual(result.AmountInStock, dto.AmountInStock); Assert.AreEqual(result.UnitPrice, dto.UnitPrice); }
public void AddNewOrderWithTotalGreaterCustomerCreditReturnNull() { //Arrange var productRepository = new SIProductRepository(); var orderRepository = new SIOrderRepository(); var customerRepository = new SICustomerRepository(); 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 SIUnitOfWork(); 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 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 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 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 RemoveCustomerSetCustomerAsDisabled() { //Arrange Guid countryGuid = Guid.NewGuid(); Guid customerId = Guid.NewGuid(); var adapter = PrepareTypeAdapter(); 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",countryGuid,new Address("city", "zipCode", "address line", "address line")); customer.Id = customerId; customerRepository.GetGuid = (guid) => { return customer; }; //Act var customerManagementService = new CustomerAppService(adapter, countryRepository, customerRepository); customerManagementService.RemoveCustomer(customerId); //Assert Assert.IsFalse(customer.IsEnabled); }
public void LockBankAccountReturnTrueIfBankAccountIsLocked() { //Arrange SICustomerRepository customerRepository = new SICustomerRepository(); IBankTransferService transferService = new BankTransferService(); ITypeAdapter adapter = PrepareTypeAdapter(); SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository(); bankAccountRepository.UnitOfWorkGet = () => { var uow = new SIUnitOfWork(); uow.Commit = () => { }; return uow; }; bankAccountRepository.GetGuid = (guid) => { return new BankAccount() { Id = Guid.NewGuid(), CustomerId = Guid.NewGuid() }; }; IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService, adapter); //Act var result = bankingService.LockBankAccount(Guid.NewGuid()); //Assert Assert.IsTrue(result); }
public void PerformBankTransfer() { //Arrange var sourceId = new Guid("3481009C-A037-49DB-AE05-44FF6DB67DEC"); var bankAccountNumberSource = new BankAccountNumber("4444", "5555", "3333333333", "02"); var source = BankAccountFactory.CreateBankAccount(Guid.NewGuid(), bankAccountNumberSource); source.Id = sourceId; source.DepositMoney(1000,"initial"); var sourceBankAccountDTO = new BankAccountDTO() { Id = sourceId, BankAccountNumber = source.Iban }; var targetId = new Guid("8A091975-F783-4730-9E03-831E9A9435C1"); var bankAccountNumberTarget = new BankAccountNumber("1111", "2222", "3333333333", "01"); var target = BankAccountFactory.CreateBankAccount(Guid.NewGuid(), bankAccountNumberTarget); target.Id = targetId; var targetBankAccountDTO = new BankAccountDTO() { Id = targetId, BankAccountNumber = target.Iban }; var accounts = new List<BankAccount>() { source, target }; var accountsDTO = new List<BankAccountDTO>() { sourceBankAccountDTO, targetBankAccountDTO }; SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository(); bankAccountRepository.GetGuid = (guid) => { return accounts.Where(a => a.Id == guid).SingleOrDefault(); }; bankAccountRepository.UnitOfWorkGet = () => { var unitOfWork = new SIUnitOfWork(); unitOfWork.Commit = () => { }; return unitOfWork; }; SICustomerRepository customerRepository = new SICustomerRepository(); IBankTransferService transferService = new BankTransferService(); ITypeAdapter adapter = PrepareTypeAdapter(); IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService, adapter); //Act bankingService.PerformBankTransfer(sourceBankAccountDTO, targetBankAccountDTO, 100M); }
public void AddNewCustomerThrowApplicationErrorsWhenEntityIsNotValid() { //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() //missing lastname { CountryId = Guid.NewGuid(), FirstName = "Jhon" }; //act var result = customerManagementService.AddNewCustomer(customerDTO); }
public void AddNewValidOrderReturnAddedOrder() { //Arrange var adapter = PrepareTypeAdapter(); var productRepository = new SIProductRepository(); var orderRepository = new SIOrderRepository(); var customerRepository = new SICustomerRepository(); customerRepository.GetGuid = (guid) => { //default credit limit is 1000 var customer = CustomerFactory.CreateCustomer("Jhon", "El rojo", Guid.NewGuid(), new Address("city", "zipCode", "addressline1", "addressline2")); customer.Id = IdentityGenerator.NewSequentialGuid(); return customer; }; orderRepository.UnitOfWorkGet = () => { var uow = new SIUnitOfWork(); uow.Commit = () => { }; return uow; }; orderRepository.AddOrder = (order) => { }; var salesManagement = new SalesAppService(adapter, 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 = 20} } }; //act var result = salesManagement.AddNewOrder(dto); //assert Assert.IsNotNull(result); Assert.IsTrue(result.Id != Guid.Empty); Assert.AreEqual(result.ShippingAddress, dto.ShippingAddress); Assert.AreEqual(result.ShippingCity, dto.ShippingCity); Assert.AreEqual(result.ShippingName, dto.ShippingName); Assert.AreEqual(result.ShippingZipCode, dto.ShippingZipCode); Assert.IsTrue(result.OrderLines.Count == 1); Assert.IsTrue(result.OrderLines.All(ol=>ol.Id != Guid.Empty)); }