public void PerformTransferCreateActivities() { //Arrange var customer = GetCustomer(); var source = BankAccountFactory.CreateBankAccount( customer, new BankAccountNumber("1111", "2222", "3333333333", "01")); source.DepositMoney(1000, "initial load"); var target = BankAccountFactory.CreateBankAccount( customer, new BankAccountNumber("1111", "2222", "12312321322", "01")); //Act var activities = source.BankAccountActivity.Count; var bankTransferService = new BankTransferService(); bankTransferService.PerformTransfer(50, source, target); //Assert Assert.IsNotNull(source.BankAccountActivity); Assert.AreEqual(++activities, source.BankAccountActivity.Count); }
public void LockBankAccountReturnFalseIfBankAccountNotExist() { //Arrange var customerRepository = new Mock <ICustomerRepository>(); IBankTransferService transferService = new BankTransferService(); Mock <MainBCUnitOfWork> _mockContext = new Mock <MainBCUnitOfWork>(); _mockContext.Setup(c => c.Commit()); var bankAccountRepository = new Mock <IBankAccountRepository>(); bankAccountRepository .Setup(x => x.UnitOfWork).Returns(_mockContext.Object); bankAccountRepository .Setup(x => x.Get(It.IsAny <Guid>())) .Returns((Guid guid) => null); Mock <ILogger <BankAppService> > _mockLogger = new Mock <ILogger <BankAppService> >(); IBankAppService bankingService = new BankAppService(bankAccountRepository.Object, customerRepository.Object, transferService, _mockLogger.Object); //Act var result = bankingService.LockBankAccount(Guid.NewGuid()); //Assert Assert.False(result); }
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 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 AddBankAccountThrowInvalidOperationExceptionWhenCustomerNotExist() { //Arrange var bankAccountRepository = new Mock <IBankAccountRepository>(); var customerRepository = new Mock <ICustomerRepository>(); customerRepository .Setup(x => x.Get(It.IsAny <Guid>())) .Returns((Guid guid) => null); IBankTransferService transferService = new BankTransferService(); var dto = new BankAccountDTO() { CustomerId = Guid.NewGuid() }; Mock <ILogger <BankAppService> > _mockLogger = new Mock <ILogger <BankAppService> >(); IBankAppService bankingService = new BankAppService(bankAccountRepository.Object, customerRepository.Object, transferService, _mockLogger.Object); Exception ex = Assert.Throws <InvalidOperationException>(() => { //Act bankingService.AddBankAccount(dto); } ); Assert.IsType(typeof(InvalidOperationException), ex); }
public void Transfer_NullFromAccount_Throws() { var toAccount = new Account(ToAccountNumber, 53.75); bool transferOk = false; Assert.Throws <BankTransferService.TransferException>(() => transferOk = BankTransferService.Transfer(null, toAccount, 24.13)); }
public void FindBankAccountActivitiesReturnNullWhenBankAccountIdIsEmpty() { //Arrange var bankAccountRepository = new Mock <IBankAccountRepository>(); bankAccountRepository .Setup(x => x.Get(It.IsAny <Guid>())) .Returns((Guid guid) => guid == Guid.Empty ? null : new BankAccount { }); var customerRepository = new Mock <ICustomerRepository>(); IBankTransferService transferService = new BankTransferService(); Mock <ILogger <BankAppService> > _mockLogger = new Mock <ILogger <BankAppService> >(); IBankAppService bankingService = new BankAppService(bankAccountRepository.Object, customerRepository.Object, transferService, _mockLogger.Object); //Act var result = bankingService.FindBankAccountActivities(Guid.Empty); //Assert Assert.Null(result); }
public void LockBankAccountReturnFalseIfIdentifierIsEmpty() { //Arrange var bankAccountRepository = new Mock <IBankAccountRepository>(); bankAccountRepository .Setup(x => x.Get(It.IsAny <Guid>())) .Returns((Guid guid) => guid == Guid.Empty ? null : new BankAccount { }); var customerRepository = new Mock <ICustomerRepository>(); IBankTransferService transferService = new BankTransferService(); Mock <ILogger <BankAppService> > _mockLogger = new Mock <ILogger <BankAppService> >(); IBankAppService bankingService = new BankAppService(bankAccountRepository.Object, customerRepository.Object, transferService, _mockLogger.Object); //Act var result = bankingService.LockBankAccount(Guid.Empty); //Assert Assert.False(result); }
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 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 Transfer_NegativeTransfer_NotAllowed() { var fromAccount = new Account(FromAccountNumber, 77.88); var toAccount = new Account(ToAccountNumber, 53.75); bool transferOk = false; transferOk = BankTransferService.Transfer(fromAccount, toAccount, -77.88); Assert.False(transferOk); }
public void ConstructorThrowExceptionIfBankAccountRepositoryDependencyIsNull() { //Arrange SICustomerRepository customerRepository = new SICustomerRepository(); SIBankAccountRepository bankAcccountRepository = null; IBankTransferService transferService = new BankTransferService(); //Act IBankAppService bankingService = new BankAppService(bankAcccountRepository, customerRepository, transferService); }
public void Transfer_OverdrawFromPositiveAccount_FromAccountChargedFeeRoundsUp() { var fromAccount = new Account(FromAccountNumber, 0.50); var toAccount = new Account(ToAccountNumber, 0.0); bool transferOk = false; transferOk = BankTransferService.Transfer(fromAccount, toAccount, 0.90); AssertEqual(-0.41, fromAccount.Balance); }
public void Transfer_ValidAccountsSufficientBalance_ToAccountIsIncreased() { var fromAccount = new Account(FromAccountNumber, 77.88); var toAccount = new Account(ToAccountNumber, 53.75); bool transferOk = false; transferOk = BankTransferService.Transfer(fromAccount, toAccount, 24.13); AssertEqual(77.88, toAccount.Balance); }
public void Transfer_ValidAccountsSufficientBalance_ReturnsTrue() { var fromAccount = new Account(FromAccountNumber, 77.88); var toAccount = new Account(ToAccountNumber, 53.75); bool transferOk = false; transferOk = BankTransferService.Transfer(fromAccount, toAccount, 24.13); Assert.True(transferOk); }
public void Transfer_OverdrawFromEmptyAccount_Allowed() { var fromAccount = new Account(FromAccountNumber, 0.0); var toAccount = new Account(ToAccountNumber, 53.75); bool transferOk = false; transferOk = BankTransferService.Transfer(fromAccount, toAccount, 77.89); Assert.True(transferOk); }
public void Transfer_OverdrawFromOverdrawnAccount_NotAllowedReturnsFalse() { var fromAccount = new Account(FromAccountNumber, -0.01); var toAccount = new Account(ToAccountNumber, 53.75); bool transferOk = false; transferOk = BankTransferService.Transfer(fromAccount, toAccount, 77.89); Assert.False(transferOk); }
public void Transfer_OverdrawFromPositiveAccount_ToAccountCredited() { var fromAccount = new Account(FromAccountNumber, 77.88); var toAccount = new Account(ToAccountNumber, 53.75); bool transferOk = false; transferOk = BankTransferService.Transfer(fromAccount, toAccount, 77.89); AssertEqual(131.64, toAccount.Balance); }
public void Transfer_OverdrawFromPositiveAccount_AllowedReturnsTrue() { var fromAccount = new Account(FromAccountNumber, 77.88); var toAccount = new Account(ToAccountNumber, 53.75); bool transferOk = false; transferOk = BankTransferService.Transfer(fromAccount, toAccount, 77.89); Assert.True(transferOk); }
public void Transfer_TransferEntireAccountBalance_Allowed() { var fromAccount = new Account(FromAccountNumber, 77.88); var toAccount = new Account(ToAccountNumber, 53.75); bool transferOk = false; transferOk = BankTransferService.Transfer(fromAccount, toAccount, 77.88); Assert.True(transferOk); AssertEqual(0.0, fromAccount.Balance); }
public void AddBankAccountReturnDTOWhenSaveSucceed() { //Arrange IBankTransferService transferService = new BankTransferService(); var customerRepository = new Mock <ICustomerRepository>(); customerRepository .Setup(x => x.Get(It.IsAny <Guid>())) .Returns((Guid guid) => { var customer = new Customer() { FirstName = "Jhon", LastName = "El rojo" }; customer.ChangeCurrentIdentity(guid); return(customer); } ); Mock <MainBCUnitOfWork> _mockContext = new Mock <MainBCUnitOfWork>(); _mockContext.Setup(c => c.Commit()); var bankAccountRepository = new Mock <IBankAccountRepository>(); bankAccountRepository.Setup(x => x.Add(It.IsAny <BankAccount>())); bankAccountRepository .Setup(x => x.UnitOfWork).Returns(_mockContext.Object); var dto = new BankAccountDTO() { CustomerId = Guid.NewGuid(), BankAccountNumber = "BA" }; Mock <ILogger <BankAppService> > _mockLogger = new Mock <ILogger <BankAppService> >(); IBankAppService bankingService = new BankAppService(bankAccountRepository.Object, customerRepository.Object, transferService, _mockLogger.Object); //Act var result = bankingService.AddBankAccount(dto); //Assert Assert.NotNull(result); }
public void ConstructorThrowExceptionIfBankAccountRepositoryDependencyIsNull() { //Arrange Mock <ICustomerRepository> customerRepository = new Mock <ICustomerRepository>(); IBankTransferService transferService = new BankTransferService(); Mock <ILogger <BankAppService> > _mockLogger = new Mock <ILogger <BankAppService> >(); Exception ex = Assert.Throws <ArgumentNullException>(() => { //Act IBankAppService bankingService = new BankAppService(null, customerRepository.Object, transferService, _mockLogger.Object); } ); Assert.IsType(typeof(ArgumentNullException), ex); }
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 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 PerformTransferThrowExceptionIfSourceCantWithdrawedWithExceedAmoung() { //Arrange var customer = GetCustomer(); var source = BankAccountFactory.CreateBankAccount(customer, new BankAccountNumber("1111", "2222", "3333333333", "01")); source.DepositMoney(1000, "initial load"); var target = BankAccountFactory.CreateBankAccount(customer, new BankAccountNumber("1111", "2222", "12312321322", "01")); //Act var bankTransferService = new BankTransferService(); bankTransferService.PerformTransfer(2000, source, target); }
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 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 PerformTransferThrowExceptionIfTargetBankAccountNumberIsEqualToSourceBankAccountNumber() { //Arrange var customer = GetCustomer(); var source = BankAccountFactory.CreateBankAccount(customer, new BankAccountNumber("1111", "2222", "3333333333", "01")); source.DepositMoney(1000, "initial load"); source.Lock(); var target = BankAccountFactory.CreateBankAccount(customer, new BankAccountNumber("1111", "2222", "3333333333", "01")); //Act var bankTransferService = new BankTransferService(); bankTransferService.PerformTransfer(10, source, target); }
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 FindBankAccountActivitiesReturnAllItems() { //Arrange var bankAccountRepository = new Mock <IBankAccountRepository>(); bankAccountRepository .Setup(x => x.Get(It.IsAny <Guid>())) .Returns((Guid 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 Mock <ICustomerRepository>(); IBankTransferService transferService = new BankTransferService(); Mock <ILogger <BankAppService> > _mockLogger = new Mock <ILogger <BankAppService> >(); IBankAppService bankingService = new BankAppService(bankAccountRepository.Object, customerRepository.Object, transferService, _mockLogger.Object); //Act var result = bankingService.FindBankAccountActivities(Guid.NewGuid()); //Assert Assert.NotNull(result); Assert.True(result.Count == 2); }
static void Main(string[] args) { bool useAutoGeneration = false; bool useTests = false; bool useInitializers = true; if(useAutoGeneration) { using (var unitOfWork = new UnitOfWork(new BankModuleFactory(useInitializers))) { var LoanApplicationService = new LoanApplicationService(unitOfWork); var LoanAgreementService = new LoanAgreementService(unitOfWork); Console.WriteLine("Автогенерация для заявок:"); foreach (var loanApplication in LoanApplicationService.Get()) { if (loanApplication.Goal == "Смена гардероба" || loanApplication.Goal == "Пластическая операция" || loanApplication.Additional == "Car loan test" || loanApplication.Additional == "Grad loan test 1" || loanApplication.Additional == "Grad loan test 2") { Console.WriteLine(string.Format("{0} {1} {2}", loanApplication.Client.FirstName, loanApplication.Goal, loanApplication.Term)); loanApplication.Status.Stage = ApplicationConsiderationStages.ApplicationConfirmationQueue; LoanApplicationService.ApproveApplication(loanApplication); loanApplication.Status.Stage = ApplicationConsiderationStages.Providing; LoanAgreementService.CompleteAgreement(loanApplication.LoanAgreements.First()); unitOfWork.Commit(); } } Console.WriteLine("\nРезультаты:\n"); foreach (var loanApplication in LoanApplicationService.Get()) { if (loanApplication.Goal == "Смена гардероба" || loanApplication.Goal == "Пластическая операция" || loanApplication.Additional == "Car loan test" || loanApplication.Additional == "Grad loan test 1" || loanApplication.Additional == "Grad loan test 2") { Console.WriteLine(string.Format("{0} {1} {2}", loanApplication.Client.FirstName, loanApplication.Goal, loanApplication.Term)); Console.WriteLine("Создан кредитный договор:"); var loanAgreement = loanApplication.LoanAgreements.First(); Console.WriteLine(string.Format("Номер:{0} Кредитный аккаунт:{1} Аккаунт для оплаты:{2}", loanAgreement.Id, loanAgreement.LoanAccount.IBAN, loanAgreement.RepaymentAccount.IBAN)); foreach(var bailAgreement in loanApplication.BailAgreements) { Console.WriteLine("Создан договор залога:"); Console.WriteLine(string.Format("Номер:{0} Объект:{1} Владелец:{2}", bailAgreement.Id, bailAgreement.BailObject, bailAgreement.BailObjectHolder)); } foreach (var suretyAgreement in loanApplication.SuretyAgreements) { Console.WriteLine("Создан договор поручительства:"); Console.WriteLine(string.Format("Номер:{0} Поручитель:{1} Должник:{2}", suretyAgreement.Id, suretyAgreement.Guarantor.FirstName + " " + suretyAgreement.Guarantor.LastName, suretyAgreement.Client.FirstName)); } Console.WriteLine(); } } } System.Console.ReadKey(true); return; } if(useTests) { Console.WriteLine(new LoanTest().RunTest()); Console.WriteLine(new UserTest().RunTest()); System.Console.ReadKey(true); return; } List<LoanApplication> archiveApplications; using (var unitOfWork = new UnitOfWork(new BankModuleFactory(useInitializers))) { var AccountService = new AccountService(unitOfWork); Console.WriteLine("Accounts:"); foreach(var account in AccountService.Get()) { System.Console.WriteLine(string.Format("{0} {1} {2} {3} Transfers From: {4} Transfers To:{5}", account.IBAN, account.AccountType, account.MoneyAmount, account.Currency, account.BankTransfersFrom.Count, account.BankTransfersTo.Count)); } var BankTransferService = new BankTransferService(unitOfWork); Console.WriteLine("Transfers:"); foreach (var transfer in BankTransferService.Get(includeProperties: "AccountFrom,AccountTo")) Console.WriteLine(string.Format("From: {0} To: {1} {2} {3} {4}", transfer.AccountFrom.IBAN, transfer.AccountTo.IBAN, transfer.Amount, transfer.Currency, transfer.TransferDate.ToShortDateString())); var LoanAgreementService = new LoanAgreementService(unitOfWork); Console.WriteLine("Loan Agreements:"); foreach (var loanAgreement in LoanAgreementService.Get(includeProperties: "PayoutStatus")) Console.WriteLine(string.Format("{0} {1} {2} {3} {4} {5} {6}", loanAgreement.Client.FirstName, loanAgreement.LoanType, loanAgreement.LoanProviding, loanAgreement.LoanRepayment, loanAgreement.Term, loanAgreement.Amount, loanAgreement.Currency)); var PayoutService = new PayoutService(unitOfWork); Console.WriteLine("Payouts:"); foreach (var payout in PayoutService.Get()) Console.WriteLine(string.Format("{0} {1} {2} {3} {4} {5}", payout.PayoutWay, payout.LoanAmount, payout.ProcessingFee, payout.InterestAmount, payout.TotalAmount, payout.Currency)); var FineService = new FineService(unitOfWork); Console.WriteLine("Fines:"); foreach (var fine in FineService.Get(includeProperties: "LoanAgreement")) Console.WriteLine(string.Format("{0} {1} {2} {3}", fine.LoanAgreement.Id, fine.DeadLineDate.ToShortDateString(), fine.FineRateOfInterest, fine.IsClosed)); var WithdrawalService = new WithdrawalService(unitOfWork); Console.WriteLine("Withdrawals:"); foreach (var withdrawal in WithdrawalService.Get(includeProperties: "ClientAccount,LoanAgreement")) Console.WriteLine(string.Format("{0} {1} {2} {3} {4}", withdrawal.ClientAccount.Id, withdrawal.MoneyAmount, withdrawal.Currency, withdrawal.WithdrawalWay, withdrawal.Date.ToShortDateString())); var PersonService = new PersonService(unitOfWork); Console.WriteLine("Persons:"); foreach (var person in PersonService.Get()) Console.WriteLine(string.Format("{0} {1} {2} Documents: {3} Records: {4}", person.FirstName, person.IdentificationNumber, person.MonthlyIncome, person.Documents.Count, person.CreditHistoryRecords.Count)); var HistoryService = new CreditHistoryRecordService(unitOfWork); Console.WriteLine("Records:"); foreach (var record in HistoryService.Get()) Console.WriteLine(string.Format("{0} {1} {2} {3} {4}", record.Person.FirstName, record.BankConstants.BIC, record.Amount, record.Currency, record.Interest)); var LoanService = new LoanService(unitOfWork); Console.WriteLine("Loan programs:"); foreach (var program in LoanService.Get()) Console.WriteLine(string.Format("{0} {1} {2} {3} {4} {5}", program.Name, program.LoanProviding, program.LoanGuarantee, program.LoanRepayment, program.LoanType, program.MaxAmount)); var LoanApplicationService = new LoanApplicationService(unitOfWork); Console.WriteLine("Loan applications:"); foreach (var loanApplication in LoanApplicationService.Get()) { Console.WriteLine(string.Format("{0} {1} {2} {3} Time: {4}", loanApplication.Client.FirstName, loanApplication.Loan.Name, loanApplication.Amount, loanApplication.Term, loanApplication.Status.ChangedDate.TimeOfDay.ToString())); } unitOfWork.Commit(); var SuretyAgreementService = new SuretyAgreementService(unitOfWork); Console.WriteLine("Surety agreements:"); foreach (var suretyAgreement in SuretyAgreementService.Get()) Console.WriteLine(string.Format("{0} {1} {2} {3} {4} {5}", suretyAgreement.Client.FirstName, suretyAgreement.Guarantor.FirstName, suretyAgreement.Amount, suretyAgreement.Currency, suretyAgreement.LoanTerm, suretyAgreement.SuretyTerm)); var BailAgreementService = new BailAgreementService(unitOfWork); Console.WriteLine("Bail agreements:"); foreach (var bailAgreement in BailAgreementService.Get()) Console.WriteLine(string.Format("{0} {1} {2} {3} {4} {5}", bailAgreement.Client.FirstName, bailAgreement.BailObject, bailAgreement.Amount, bailAgreement.Currency, bailAgreement.LoanTerm, bailAgreement.BailTerm)); var BailObjectService = new BailObjectsService(unitOfWork); Console.WriteLine("Bail objects:"); foreach (var bailObject in BailObjectService.Get()) Console.WriteLine(string.Format("{0} {1} {2} {3}", bailObject.Object, bailObject.ClientIdentificationNumber, bailObject.BailObjectEstimate, bailObject.Currency)); var SystemService = new SystemResolutionService(unitOfWork); Console.WriteLine("System resolutions:"); foreach (var resolution in SystemService.Get()) Console.WriteLine(string.Format("Application: {0} {1} {2}", resolution.LoanApplication.Id, resolution.MaxLoanAmount, resolution.ScoringPoint)); var SecurityService = new SecurityResolutionService(unitOfWork); Console.WriteLine("Security resolutions:"); foreach (var resolution in SecurityService.Get()) Console.WriteLine(string.Format("Application: {0} {1} {2}{3}", resolution.LoanApplication.Id, resolution.Income, Environment.NewLine, resolution.IncomeEstimate)); var ExpertService = new ExpertResolutionService(unitOfWork); Console.WriteLine("Expert resolutions:"); foreach (var resolution in ExpertService.Get()) Console.WriteLine(string.Format("Application: {0} {1} {2}", resolution.LoanApplication.Id, resolution.Social, resolution.SocialEstimate)); var CommitteeService = new CommitteeResolutionService(unitOfWork); Console.WriteLine("Committee resolutions:"); foreach (var resolution in CommitteeService.Get()) Console.WriteLine(string.Format("Link: {0} {1}", resolution.ProtocolDocument.Link, resolution.Resolution)); archiveApplications = LoanApplicationService.Get (app => app.Id < 5, app => app.OrderBy(p => p.Id), app => app.Client, app => app.LoanAgreements, app => app.LoanAgreements.Select(l => l.BankConstants), app => app.LoanAgreements.Select(l => l.Payouts), app => app.LoanAgreements.Select(l => l.ClientWithdrawals), app => app.BailAgreements.Select(b => b.AgreementDocument), app => app.BailAgreements.Select(b => b.EstimationDocument), app => app.BailAgreements.Select(b => b.InsuranceDocument), app => app.SuretyAgreements.Select(s => s.AgreementDocument), app => app.SuretyAgreements.Select(s => s.Client), app => app.SuretyAgreements.Select(s => s.Guarantor), app => app.SuretyAgreements.Select(s => s.BankConstants) ).ToList(); } using (var archiveUnit = new UnitOfWork(new ArchiveModuleFactory(useInitializers))) { var ApplicationService = new ArchiveLoanApplicationService(archiveUnit); foreach(var arch in archiveApplications) ApplicationService.ArchiveApplication(arch); archiveUnit.Commit(); } using (var archiveUnit = new UnitOfWork(new ArchiveModuleFactory(false))) { var ApplicationService = new ArchiveLoanApplicationService(archiveUnit); Console.WriteLine("\nArchived applications:"); foreach (var loanApplication in ApplicationService.Get()) Console.WriteLine(string.Format("{0} {1} {2} {3} Time: {4}", loanApplication.ClientIdentificationNumber, loanApplication.LoanAgreements.Count, loanApplication.Amount, loanApplication.Term, loanApplication.ArchivedDate.TimeOfDay.ToString())); } Console.WriteLine("\nAuthentification: "); using (var unitOfWork = new UnitOfWork(new AuthorizationModuleFactory(useInitializers))) { var userService = new UserService(unitOfWork); foreach (var user in userService.Get(includeProperties: "Roles")) { System.Console.WriteLine(string.Format("{0} {1} {2} {3}", user.FirstName, user.MiddleName, user.LastName, user.Roles.First().Name)); var newUser = userService.GetLoggedUser(user.Login, "ivan_peresvetov_pass"); if(newUser != null) Console.WriteLine("Found ivan!"); } } System.Console.ReadKey(true); }
static void Main(string[] args) { using (var studContext = new StudBankContext(true)) { var AccountService = new AccountService(studContext); Console.WriteLine("Accounts:"); foreach(var account in AccountService.Get()) { System.Console.WriteLine(string.Format("{0} {1} {2} {3} Transfers From: {4} Transfers To:{5}", account.IBAN, account.AccountType, account.MoneyAmount, account.Currency, account.BankTransfersFrom.Count, account.BankTransfersTo.Count)); } var BankTransferService = new BankTransferService(studContext); Console.WriteLine("Transfers:"); foreach (var transfer in BankTransferService.Get(includeProperties: "AccountFrom,AccountTo")) Console.WriteLine(string.Format("From: {0} To: {1} {2} {3} {4}", transfer.AccountFrom.IBAN, transfer.AccountTo.IBAN, transfer.Amount, transfer.Currency, transfer.TransferDate.ToShortDateString())); var LoanAgreementService = new LoanAgreementService(studContext); Console.WriteLine("Loan Agreements:"); foreach (var loanAgreement in LoanAgreementService.Get(includeProperties: "PayoutStatus")) Console.WriteLine(string.Format("{0} {1} {2} {3} {4} {5} {6}", loanAgreement.Client.FirstName, loanAgreement.LoanType, loanAgreement.LoanProviding, loanAgreement.LoanRepayment, loanAgreement.Term, loanAgreement.Amount, loanAgreement.Currency)); var PayoutService = new PayoutService(studContext); Console.WriteLine("Payouts:"); foreach (var payout in PayoutService.Get()) Console.WriteLine(string.Format("{0} {1} {2} {3} {4} {5}", payout.PayoutWay, payout.LoanAmount, payout.ProcessingFee, payout.InterestAmount, payout.TotalAmount, payout.Currency)); var FineService = new FineService(studContext); Console.WriteLine("Fines:"); foreach (var fine in FineService.Get(includeProperties: "LoanAgreement")) Console.WriteLine(string.Format("{0} {1} {2} {3}", fine.LoanAgreement.Id, fine.DeadLineDate.ToShortDateString(), fine.FineRateOfInterest, fine.IsClosed)); var WithdrawalService = new WithdrawalService(studContext); Console.WriteLine("Withdrawals:"); foreach (var withdrawal in WithdrawalService.Get(includeProperties: "ClientAccount,LoanAgreement")) Console.WriteLine(string.Format("{0} {1} {2} {3} {4}", withdrawal.ClientAccount.Id, withdrawal.MoneyAmount, withdrawal.Currency, withdrawal.WithdrawalWay, withdrawal.Date.ToShortDateString())); var PersonService = new PersonService(studContext); Console.WriteLine("Persons:"); foreach (var person in PersonService.Get()) Console.WriteLine(string.Format("{0} {1} {2} Documents: {3} Records: {4}", person.FirstName, person.IdentificationNumber, person.MonthlyIncome, person.Documents.Count, person.CreditHistoryRecords.Count)); var HistoryService = new CreditHistoryRecordService(studContext); Console.WriteLine("Records:"); foreach (var record in HistoryService.Get()) Console.WriteLine(string.Format("{0} {1} {2} {3} {4}", record.Person.FirstName, record.BankConstants.BIC, record.Amount, record.Currency, record.Interest)); var LoanService = new LoanService(studContext); Console.WriteLine("Loan programs:"); foreach (var program in LoanService.Get()) Console.WriteLine(string.Format("{0} {1} {2} {3} {4} {5}", program.Name, program.LoanProviding, program.LoanGuarantee, program.LoanRepayment, program.LoanType, program.MaxAmount)); var LoanApplicationService = new LoanApplicationService(studContext); Console.WriteLine("Loan applications:"); foreach (var loanApplication in LoanApplicationService.Get()) Console.WriteLine(string.Format("{0} {1} {2} {3} {4} First surety:{5}", loanApplication.Client.FirstName, loanApplication.Loan.Name, loanApplication.Amount, loanApplication.Currency, loanApplication.Term, loanApplication.Sureties.FirstOrDefault().FirstName)); var SuretyAgreementService = new SuretyAgreementService(studContext); Console.WriteLine("Surety agreements:"); foreach (var suretyAgreement in SuretyAgreementService.Get()) Console.WriteLine(string.Format("{0} {1} {2} {3} {4} {5}", suretyAgreement.Client.FirstName, suretyAgreement.Guarantor.FirstName, suretyAgreement.Amount, suretyAgreement.Currency, suretyAgreement.LoanTerm, suretyAgreement.SuretyTerm)); var BailAgreementService = new BailAgreementService(studContext); Console.WriteLine("Bail agreements:"); foreach (var bailAgreement in BailAgreementService.Get()) Console.WriteLine(string.Format("{0} {1} {2} {3} {4} {5}", bailAgreement.Client.FirstName, bailAgreement.BailObject, bailAgreement.Amount, bailAgreement.Currency, bailAgreement.LoanTerm, bailAgreement.BailTerm)); var SystemService = new SystemResolutionService(studContext); Console.WriteLine("System resolutions:"); foreach (var resolution in SystemService.Get()) Console.WriteLine(string.Format("Application: {0} {1} {2}", resolution.LoanApplication.Id, resolution.MaxLoanAmount, resolution.ScoringPoint)); var SecurityService = new SecurityResolutionService(studContext); Console.WriteLine("Security resolutions:"); foreach (var resolution in SecurityService.Get()) Console.WriteLine(string.Format("Application: {0} {1} {2}", resolution.LoanApplication.Id, resolution.Property, resolution.PropertyEstimate)); var ExpertService = new ExpertResolutionService(studContext); Console.WriteLine("Expert resolutions:"); foreach (var resolution in ExpertService.Get()) Console.WriteLine(string.Format("Application: {0} {1} {2}", resolution.LoanApplication.Id, resolution.Property, resolution.PropertyEstimate)); var CommitteeService = new CommitteeResolutionService(studContext); Console.WriteLine("Committee resolutions:"); foreach (var resolution in CommitteeService.Get()) Console.WriteLine(string.Format("Link: {0} {1}", resolution.ProtocolDocument.Link, resolution.Resolution)); } Console.WriteLine("\nAuthentification: "); using (var authContext = new StudAuthorizeContext(true)) { var userService = new EntityService<User>(authContext); var roleService = new EntityService<Role>(authContext); foreach (var user in userService.Get(includeProperties: "Roles")) { System.Console.WriteLine(string.Format("{0} {1} {2} {3}", user.FirstName, user.MiddleName, user.LastName, user.Roles.First().Name)); } System.Console.WriteLine(); userService.Get(user => user.FirstName == "Ivan").First().FirstName = "Vano"; authContext.SaveChanges(); foreach (var user in userService.Get(includeProperties: "Roles")) { System.Console.WriteLine(string.Format("{0} {1} {2} {3}", user.FirstName, user.MiddleName, user.LastName, user.Roles.First().Name)); } } System.Console.ReadKey(true); }