public IActionResult Post([FromBody] Account account) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } account = accountRepository.Add(account); return(CreatedAtRoute("Get", new { id = account.AccountId }, account)); //return Ok(account); } catch (Exception ex) { return(HandleException(ex)); } }
private void Button_Click(object sender, RoutedEventArgs e) { var item = this.DataContext as Account; using (var repo = new AccountRepository()) { if (item.Id > 0) { repo.Update(item); } else { repo.Add(new Account(item.Client.Id, item.Amount)); } } Window.GetWindow(this).Close(); }
public void DeleteAccount() { RestoreDate(); var accountRepository = new AccountRepository(mockContext.Object); Teacher account = new Teacher { FirstName = "Account1", SecondName = "Account1" }; accountRepository.Add(account); accountRepository.Remove(account); Assert.IsNull(_accounts.Where(s => account.Id == s.Id).FirstOrDefault()); }
public async void DeleteAccount_RelatedChargedPaymentsRemoved() { // Arrange var accountRepository = new AccountRepository(ambientDbContextLocator); var paymentRepository = new PaymentRepository(ambientDbContextLocator); var account = new AccountEntity { Name = "Testtext" }; using (var dbContextScope = dbContextScopeFactory.Create()) { accountRepository.Add(account); await dbContextScope.SaveChangesAsync(); } var payment = new PaymentEntity { Note = "Foo", ChargedAccount = account }; // Act using (var dbContextScope = dbContextScopeFactory.Create()) { paymentRepository.Add(payment); await dbContextScope.SaveChangesAsync(); Assert.Equal(1, await accountRepository.GetAll().CountAsync()); Assert.Equal(1, await paymentRepository.GetAll().CountAsync()); } using (var dbContextScope = dbContextScopeFactory.Create()) { accountRepository.Delete(account); await dbContextScope.SaveChangesAsync(); } // Assert using (var dbContextScope = dbContextScopeFactory.Create()) { Assert.False(await accountRepository.GetAll().AnyAsync()); Assert.False(await paymentRepository.GetAll().AnyAsync()); } }
public async void Save_WithRecurringPayment_GetRecurringPaymentFromHelper() { // Arrange var unitOfWork = new UnitOfWork(dbFactory); var repository = new PaymentRepository(dbFactory); var accountRepository = new AccountRepository(dbFactory); var testAccount = new AccountEntity { Name = "testAccount" }; accountRepository.Add(testAccount); await unitOfWork.Commit(); var testEntry = new PaymentViewModel(new Payment { Data = { ChargedAccount = testAccount, Date = DateTime.Now, IsRecurring = true, Note = "Testtext" } }); testEntry.RecurringPayment = new RecurringPaymentViewModel( RecurringPaymentHelper.GetRecurringFromPayment(testEntry.Payment, true, PaymentRecurrence.Bimonthly, DateTime.Now)); var paymentService = new PaymentService(repository, unitOfWork); // Act await paymentService.SavePayment(testEntry.Payment); await unitOfWork.Commit(); var payment = await paymentService.GetById(testEntry.Payment.Data.Id); // Assert Assert.NotNull(payment); }
public async void Get_MatchedDataReturned() { // Arrange var repository = new RecurringPaymentRepository(ambientDbContextLocator); var accountRepository = new AccountRepository(ambientDbContextLocator); AccountEntity testAccount; using (var dbContextScope = dbContextScopeFactory.Create()) { testAccount = new AccountEntity { Name = "testAccount" }; accountRepository.Add(testAccount); await dbContextScope.SaveChangesAsync(); } var filterText = "Text"; var testEntry = new RecurringPaymentEntity { ChargedAccount = testAccount, Note = filterText }; RecurringPaymentEntity result; // Act using (var dbContextScope = dbContextScopeFactory.Create()) { repository.Add(testEntry); repository.Add(new RecurringPaymentEntity { ChargedAccount = testAccount }); repository.Add(new RecurringPaymentEntity { ChargedAccount = testAccount }); await dbContextScope.SaveChangesAsync(); result = await repository.Get(x => x.Note == filterText); } // Assert Assert.NotNull(result); Assert.Equal(testEntry.Id, result.Id); }
public void AddAccount_SavesAccountToDb() { //var account = new Account(myUser.Id, "Checking", "Chase Sucks", 0m); var account = new Account { Id = myUser.Id, AccountType = "Checking", Name = "Chase Sucks", StartingBalance = 0m }; var repo = new AccountRepository(); repo.Add(account); var accountFromDb = repo.Get(account.Id); Assert.AreEqual(account.Name, accountFromDb.Name); }
public User GetUser(int id) { User NewUser = new User(); NewUser.UserID = id; NewUser.FirstName = "C"; NewUser.LastName = "D"; IAccountRepository accountRepo = new AccountRepository(); Account acc = new Account(); acc.Balance = 1000; acc.AccountID = 120; accountRepo.Add(acc); accountRepo.GetAll(); return(NewUser); }
public void ReturnsAccountBalance() { //Arrange string id = "10"; decimal value = 60; var repo = new AccountRepository(); var service = new AccountService(repo); var account = new Account.Domain.Models.Account(id); repo.Add(account); account.Deposit(value); //Act var result = service.GetBalance(id); //Assert Assert.IsTrue(result.IsOK); Assert.AreEqual(value, result.Data); }
public void Usuario_Deve_Ter_Acesso_a_Permissao() { var acc = ObjectBuilder.CreateAccount(); acc.Groups = acc.Groups.Where(g => !g.IsAdmin).ToList(); if (acc.Groups.Any()) { var group = ObjectBuilder.CreateGroup(); group.IsAdmin = false; acc.Groups.Add(group); } var permission = ObjectBuilder.CreatePermission(); acc.Groups.Last().Claims.Last().Permissions.Add(permission); AccountRepository.Add(acc); Uow.Commit(); Assert.IsTrue(AuthorizationService.IsAuthorized(acc.Username, permission.PermissionId)); }
public async void Add_AddNewEntryOnEveryCall() { // Arrange var recurringPaymentRepository = new RecurringPaymentRepository(ambientDbContextLocator); var accountRepository = new AccountRepository(ambientDbContextLocator); AccountEntity testAccount; using (var dbContextScope = dbContextScopeFactory.Create()) { testAccount = new AccountEntity { Name = "testAccount" }; accountRepository.Add(testAccount); await dbContextScope.SaveChangesAsync(); } var testEntry = new RecurringPaymentEntity { ChargedAccount = testAccount, Note = "Testtext" }; using (var dbContextScope = dbContextScopeFactory.Create()) { recurringPaymentRepository.Add(testEntry); await dbContextScope.SaveChangesAsync(); } // Act using (var dbContextScope = dbContextScopeFactory.Create()) { testEntry.Id = 0; recurringPaymentRepository.Add(testEntry); await dbContextScope.SaveChangesAsync(); } // Assert using (dbContextScopeFactory.CreateReadOnly()) { Assert.Equal(2, recurringPaymentRepository.GetAll().Count()); } }
public async void Update_IdUnchanged() { // Arrange var recurringPaymentRepository = new RecurringPaymentRepository(ambientDbContextLocator); var accountRepository = new AccountRepository(ambientDbContextLocator); AccountEntity testAccount; using (var dbContextScope = dbContextScopeFactory.Create()) { testAccount = new AccountEntity { Name = "testAccount" }; accountRepository.Add(testAccount); await dbContextScope.SaveChangesAsync(); } var testEntry = new RecurringPaymentEntity { ChargedAccount = testAccount, Note = "Testtext" }; int idBeforeUpdate; using (var dbContextScope = dbContextScopeFactory.Create()) { recurringPaymentRepository.Add(testEntry); await dbContextScope.SaveChangesAsync(); } // Act using (var dbContextScope = dbContextScopeFactory.Create()) { idBeforeUpdate = testEntry.Id; recurringPaymentRepository.Update(testEntry); await dbContextScope.SaveChangesAsync(); } // Assert Assert.Equal(idBeforeUpdate, testEntry.Id); }
public void AccountRepository_Delegates_Changes_To_The_Unit_Of_Work_Instance() { Account accountToBeAmended = new Account(); Account accountToBeRemoved = new Account(); Account accountToBeAdded = new Account(); var unitOfWorkMockery = new Mock <IUnitOfWork>(); AccountRepository accountRepository = new AccountRepository(unitOfWorkMockery.Object); unitOfWorkMockery.Setup(uow => uow.RegisterAmended(accountToBeAmended, accountRepository)); unitOfWorkMockery.Setup(uow => uow.RegisterNew(accountToBeAdded, accountRepository)); unitOfWorkMockery.Setup(uow => uow.RegisterRemoved(accountToBeRemoved, accountRepository)); accountRepository.Add(accountToBeAdded); accountRepository.Save(accountToBeAmended); accountRepository.Remove(accountToBeRemoved); unitOfWorkMockery.VerifyAll(); }
public async void Add_IdSet() { // Arrange var unitOfWork = new UnitOfWork(dbFactory); var repository = new AccountRepository(dbFactory); var testEntry = new AccountEntity { Name = "Testtext" }; // Act repository.Add(testEntry); await unitOfWork.Commit(); // Assert Assert.NotNull(testEntry.Id); Assert.NotEqual(0, testEntry.Id); }
public async void Delete_EntryDeleted() { // Arrange var unitOfWork = new UnitOfWork(dbFactory); var repository = new AccountRepository(dbFactory); var testEntry = new AccountEntity { Name = "testAccount" }; repository.Add(testEntry); await unitOfWork.Commit(); // Act repository.Delete(testEntry); await unitOfWork.Commit(); // Assert Assert.Equal(0, repository.GetAll().Count()); }
public async void GetAll_AllDataReturned() { // Arrange var recurringPaymentRepository = new RecurringPaymentRepository(ambientDbContextLocator); var accountRepository = new AccountRepository(ambientDbContextLocator); AccountEntity testAccount; using (var dbContextScope = dbContextScopeFactory.Create()) { testAccount = new AccountEntity { Name = "testAccount" }; accountRepository.Add(testAccount); await dbContextScope.SaveChangesAsync(); } List <RecurringPaymentEntity> resultList; // Act using (var dbContextScope = dbContextScopeFactory.Create()) { recurringPaymentRepository.Add(new RecurringPaymentEntity { ChargedAccount = testAccount }); recurringPaymentRepository.Add(new RecurringPaymentEntity { ChargedAccount = testAccount }); recurringPaymentRepository.Add(new RecurringPaymentEntity { ChargedAccount = testAccount }); await dbContextScope.SaveChangesAsync(); resultList = recurringPaymentRepository.GetAll().ToList(); } // Assert Assert.NotNull(resultList); Assert.Equal(3, resultList.Count); }
public ActionResult Create([Bind(Include = "AccountId,Email,Password,Name,AccountTypeId")] Account account) { ViewBag.AccountTypeId = new SelectList(repository.GetAccountTypes(), "AccountTypeId", "Name", account.AccountTypeId); if (ModelState.IsValid) { List <Account> accounts = repository.GetByEmail(account.Email); if (accounts.Count == 0) { account.Password = Utils.Instance.Encript(account.Password); repository.Add(account); repository.SaveChanges(); return(RedirectToAction("Index")); } else { ViewBag.Error = "This e-mail is already taken."; } } return(View(account)); }
public async void Add_IdSet() { // Arrange var repository = new AccountRepository(ambientDbContextLocator); var testEntry = new AccountEntity { Name = "Testtext" }; // Act using (var dbContextScope = dbContextScopeFactory.Create()) { repository.Add(testEntry); await dbContextScope.SaveChangesAsync(); } // Assert Assert.NotNull(testEntry.Id); Assert.NotEqual(0, testEntry.Id); }
public void Add_ShouldThrowArgumentExceptionWhenTheAccountAlreadyExists() { //Arrange Account existingAccount; using (var context = CreateDbContext()) { var existingCustomer = CreateExistingCustomer(context); existingAccount = new AccountBuilder().WithCustomerId(existingCustomer.Id).Build(); context.Set <Account>().Add(existingAccount); context.SaveChanges(); } using (var context = CreateDbContext()) { var repo = new AccountRepository(context); //Act + Assert Assert.That(() => repo.Add(existingAccount), Throws.ArgumentException); } }
public async void Add_AddedAndRead() { // Arrange var unitOfWork = new UnitOfWork(dbFactory); var repository = new AccountRepository(dbFactory); var testEntry = new AccountEntity { Name = "Testtext" }; // Act repository.Add(testEntry); await unitOfWork.Commit(); // Assert var loadedEntry = await repository.GetById(testEntry.Id); Assert.Equal(testEntry.Name, loadedEntry.Name); }
public async void Update_NoNewEntryAdded() { // Arrange var paymentRepository = new PaymentRepository(ambientDbContextLocator); var accountRepository = new AccountRepository(ambientDbContextLocator); var testAccount = new AccountEntity { Name = "testAccount" }; using (var dbContextScope = dbContextScopeFactory.Create()) { accountRepository.Add(testAccount); await dbContextScope.SaveChangesAsync(); } var testEntry = new PaymentEntity { ChargedAccount = testAccount, Note = "Testtext" }; // Act using (var dbContextScope = dbContextScopeFactory.Create()) { paymentRepository.Add(testEntry); await dbContextScope.SaveChangesAsync(); } using (var dbContextScope = dbContextScopeFactory.Create()) { paymentRepository.Update(testEntry); await dbContextScope.SaveChangesAsync(); } // Assert using (dbContextScopeFactory.CreateReadOnly()) { Assert.Equal(1, paymentRepository.GetAll().Count()); } }
public async void GetMany_NothingMatched() { // Arrange var recurringPaymentRepository = new RecurringPaymentRepository(ambientDbContextLocator); var accountRepository = new AccountRepository(ambientDbContextLocator); AccountEntity testAccount; using (var dbContextScope = dbContextScopeFactory.Create()) { testAccount = new AccountEntity { Name = "testAccount" }; accountRepository.Add(testAccount); await dbContextScope.SaveChangesAsync(); } List <RecurringPaymentEntity> resultList; // Act using (var dbContextScope = dbContextScopeFactory.Create()) { recurringPaymentRepository.Add(new RecurringPaymentEntity { ChargedAccount = testAccount }); recurringPaymentRepository.Add(new RecurringPaymentEntity { ChargedAccount = testAccount }); recurringPaymentRepository.Add(new RecurringPaymentEntity { ChargedAccount = testAccount }); await dbContextScope.SaveChangesAsync(); resultList = recurringPaymentRepository.GetMany(x => x.Note == "text").ToList(); } // Assert Assert.NotNull(resultList); Assert.False(resultList.Any()); }
private bool RegisterUser(string email, string password, Role role) { if (role == Role.Admin) { return(false); } if (repository.Contains(email)) { return(false); } var account = new Account() { Email = email, Password = password, Role = role }; repository.Add(account); return(true); }
public void Add_GetWithRelation_Activity_With_Account_From_Repository() { using (var context = new AcManContext(OptionsRandom)) { string randomAccountName = "Account " + Guid.NewGuid(); var account = new Account { Name = randomAccountName }; var accountRepository = new AccountRepository(context); var accountId = accountRepository.Add(account); var activity = new Activity { Caption = "Test activity", AccountId = accountId }; var activityRepository = new ActivityRepository(context); var activityId = activityRepository.Add(activity); var resultActivity = activityRepository.GetWithRelation(activityId); Assert.IsTrue(resultActivity.AccountId == accountId); Assert.IsTrue(resultActivity.Account.Id == accountId); } }
public async void Add_AddedAndRead() { // Arrange var repository = new AccountRepository(ambientDbContextLocator); var testEntry = new AccountEntity { Name = "Testtext" }; // Act using (var dbContextScope = dbContextScopeFactory.Create()) { repository.Add(testEntry); await dbContextScope.SaveChangesAsync(); // Assert var loadedEntry = await repository.GetById(testEntry.Id); Assert.Equal(testEntry.Name, loadedEntry.Name); } }
public async void Update_NoNewEntryAdded() { // Arrange var unitOfWork = new UnitOfWork(dbFactory); var repository = new AccountRepository(dbFactory); var testEntry = new AccountEntity { Name = "Testtext" }; // Act repository.Add(testEntry); await unitOfWork.Commit(); repository.Update(testEntry); await unitOfWork.Commit(); // Assert Assert.Equal(1, repository.GetAll().Count()); }
public async void GetName_NameReturned() { // Arrange var unitOfWork = new UnitOfWork(dbFactory); var repository = new AccountRepository(dbFactory); const string accountName = "TestAccount"; var testEntry = new AccountEntity { Name = accountName }; repository.Add(testEntry); await unitOfWork.Commit(); // Act var result = await repository.GetName(testEntry.Id); // Assert Assert.NotNull(result); Assert.Equal(accountName, result); }
public static void ImportFromExcelFile(string filename) { IDictionary<string, AccountType> accountTypes = new Dictionary<string, AccountType>(); IDictionary<string, AccountCategory> accountCategories = new Dictionary<string, AccountCategory>(); IDictionary<string, Account> accounts = new Dictionary<string, Account>(); Iesi.Collections.Generic.ISet<Item> items = new HashedSet<Item>(); IDictionary<int, Transaction> transactions = new Dictionary<int, Transaction>(); OleDbConnection excelConnection; excelConnection = new OleDbConnection( "Provider=Microsoft.ACE.OLEDB.12.0; " + "Data Source=" + filename + "; " + "Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1\""); excelConnection.Open(); RecreateDatabase(); ImportAccountTypes(excelConnection, accountTypes); ImportAccountCategories(excelConnection, accountCategories); ImportAccounts(excelConnection, accounts, accountTypes, accountCategories); ImportTransactions(excelConnection, transactions); ImportItems(excelConnection, items, accounts, transactions); AccountTypeRepository atr = new AccountTypeRepository(); AccountCategoryRepository acr = new AccountCategoryRepository(); AccountRepository ar = new AccountRepository(); TransactionRepository tr = new TransactionRepository(); ItemRepository ir = new ItemRepository(); foreach (AccountType at in accountTypes.Values) atr.Add(at); foreach (AccountCategory ac in accountCategories.Values) acr.Add(ac); foreach (Account a in accounts.Values) ar.Add(a); foreach (Transaction t in transactions.Values) tr.Add(t); foreach (Item i in items) ir.Add(i); excelConnection.Close(); }
public async void Add_AddedAndRead() { // Arrange var recurringPaymentRepository = new RecurringPaymentRepository(ambientDbContextLocator); var accountRepository = new AccountRepository(ambientDbContextLocator); AccountEntity testAccount; using (var dbContextScope = dbContextScopeFactory.Create()) { testAccount = new AccountEntity { Name = "testAccount" }; accountRepository.Add(testAccount); await dbContextScope.SaveChangesAsync(); } var testEntry = new RecurringPaymentEntity { ChargedAccount = testAccount, Note = "Testtext" }; // Act using (var dbContextScope = dbContextScopeFactory.Create()) { recurringPaymentRepository.Add(testEntry); await dbContextScope.SaveChangesAsync(); } // Assert using (dbContextScopeFactory.CreateReadOnly()) { var loadedEntry = await recurringPaymentRepository.GetById(testEntry.Id); Assert.Equal(testEntry.Note, loadedEntry.Note); } }
public async void Get_NothingMatched() { // Arrange var paymentRepository = new PaymentRepository(ambientDbContextLocator); var accountRepository = new AccountRepository(ambientDbContextLocator); var testAccount = new AccountEntity { Name = "testAccount" }; using (var dbContextScope = dbContextScopeFactory.Create()) { accountRepository.Add(testAccount); await dbContextScope.SaveChangesAsync(); } PaymentEntity result; // Act using (var dbContextScope = dbContextScopeFactory.Create()) { paymentRepository.Add(new PaymentEntity { ChargedAccount = testAccount }); paymentRepository.Add(new PaymentEntity { ChargedAccount = testAccount }); paymentRepository.Add(new PaymentEntity { ChargedAccount = testAccount }); await dbContextScope.SaveChangesAsync(); result = await paymentRepository.Get(x => x.Note == "text"); } // Assert Assert.Null(result); }
public async void Add_AddMultipleEntries() { // Arrange var recurringPaymentRepository = new RecurringPaymentRepository(ambientDbContextLocator); var accountRepository = new AccountRepository(ambientDbContextLocator); AccountEntity account; using (var dbContextScope = dbContextScopeFactory.Create()) { account = new AccountEntity { Name = "testAccount" }; accountRepository.Add(account); await dbContextScope.SaveChangesAsync(); } // Act using (var dbContextScope = dbContextScopeFactory.Create()) { recurringPaymentRepository.Add(new RecurringPaymentEntity { ChargedAccount = account }); recurringPaymentRepository.Add(new RecurringPaymentEntity { ChargedAccount = account }); recurringPaymentRepository.Add(new RecurringPaymentEntity { ChargedAccount = account }); await dbContextScope.SaveChangesAsync(); } // Assert using (dbContextScopeFactory.CreateReadOnly()) { Assert.Equal(3, recurringPaymentRepository.GetAll().Count()); } }
public void Account_Create_New() { using (var context = new DataModelContainer()) { var rep = new AccountRepository(context); var account = rep.Create(); account.FirstName = "FirstName"; account.LastName = "LastName"; account.Email = "Email"; account.EmailVerified = false; account.Username = "******"; account.Password = "******"; account.BirthDate = SqlDateTime.MaxValue.Value; account.CreateDate = SqlDateTime.MaxValue.Value; account.LastUpdateDate = SqlDateTime.MaxValue.Value; rep.Add(account); rep.SaveChanges(); } }
public void Can_add_new_account() { var account = new Account { Name = "Credit Card", IsValid = true }; account.setType(_accountType1); account.setCategory(_accountCategory); IAccountRepository Arepository = new AccountRepository(); Arepository.Add(account); using (ISession session = SessionFactory.OpenSession()) { var fromDb = session.Get<Account>(account.Id); Assert.IsNotNull(fromDb); Assert.AreNotSame(account, fromDb); Assert.AreEqual(account.Name, fromDb.Name); Assert.AreEqual(account.IsValid, fromDb.IsValid); Assert.AreEqual(account.Type.Name, fromDb.Type.Name); Assert.AreEqual(account.Category.Name, fromDb.Category.Name); Assert.IsTrue(IsInCollection(account, account.Category.Accounts)); Assert.IsTrue(IsInCollection(account, account.Type.Accounts)); } }
public string AddAccount(AccountDto accountDto) { try { AccountRepository repository = new AccountRepository(); IndexAccount indexAccount = repository.ActiveContext.IndexAccounts.Include("BankAccounts") .FirstOrDefault(ia => ia.Id == accountDto.IndexAccountId); if (!indexAccount.ContainAccount(accountDto.Code)) { Account account = new Account(); accountDto.Id = Guid.NewGuid(); account.InjectFrom<UnflatLoopValueInjection>(accountDto); account.IndexAccount = indexAccount; repository.Add(account); return "account is created"; } return "account with this code is recreated !?"; } catch (Exception exception) { return exception.Message; } }
public void Register(Account account) { if (account == null) throw new ArgumentNullException("account"); using (AccountRepository accountRepository = new AccountRepository()) { if (accountRepository.CheckAccountExistByName(account.AccountName)) { // throw account name exists exception throw new AccountIsExistException(string.Format(Resource.ResourceMessage.ex_AccountExist, account.AccountName)); } var accounts = accountRepository.GetFiltered(a => a.Email == account.Email); if (accounts.Count<Account>() > 0) { // throw email exists exception throw new AccountEmailExistException(string.Format(Resource.ResourceMessage.ex_EmailExist, account.Email)); } accounts = accountRepository.GetFiltered(a => a.IdentityCardNumber == account.IdentityCardNumber); if (accounts.Count<Account>() > 0) { // throw IdentityCardNumber exists exception throw new AccountIdCardExistException(string.Format(Resource.ResourceMessage.ex_IdentityCardNumberExist, account.IdentityCardNumber)); } accountService.Register(account); accountRepository.Add(account); accountRepository.Commit(); // send a email to tell use his activation code so that he can activate the account SendMail(account, HostSendMail.EmailCategory.ActivationCode); } }
public void Change_account_category() { var account = new Account { Name = "Credit Card", IsValid = true }; account.setType(_accountType1); account.setCategory(_accountCategory); account.setCategory(_accountCategory2); IAccountRepository Arepository = new AccountRepository(); Arepository.Add(account); using (ISession session = SessionFactory.OpenSession()) { var fromDb = session.Get<Account>(account.Id); Assert.IsTrue(IsInCollection(account, account.Category.Accounts)); Assert.IsFalse(IsInCollection(account, _accountCategory.Accounts)); } }
public static void FillDb() { using (var context = new BankDbContext()) { Console.WriteLine("ConnectionString\n" + context.Database.Connection.ConnectionString); Console.WriteLine("DataSource\n" + context.Database.Connection.DataSource); Console.WriteLine("ConnectionString\n" + context.Database.Connection.Database); // CLEARS ALL DATA !!! Console.WriteLine("ALL DATA WILL BE DELETED FROM DB NOW!!! ([ENTER] TO PROCEED)"); Console.ReadLine(); //if (!context.Database.Exists()) //{ context.Database.Delete(); context.Database.Create(); //} context.Database.Initialize(true);// Console.WriteLine("Db initialized"); Console.ReadLine(); context.Accounts.RemoveRange(context.Accounts); ///Console.WriteLine("I've successfully completed first db action!"); ///Console.ReadLine(); context.Clients.RemoveRange(context.Clients); context.Credits.RemoveRange(context.Credits); context.CreditTypes.RemoveRange(context.CreditTypes); context.Payments.RemoveRange(context.Payments); context.Requests.RemoveRange(context.Requests); //context.RequestStatuses.RemoveRange(context.RequestStatuses); context.Users.RemoveRange(context.Users); context.SaveChanges(); // CLEARS ALL DATA !!! //var statusRepo = new RequestStatusRepository(context); //var statusCreated = new RequestStatus { Status = "Created" }; //var statusConfirmedByOperator = new RequestStatus { Status = "statusConfirmedByOperator" }; //var statusConfirmedBySse = new RequestStatus { Status = "statusConfirmedBySecurityServiceEmployee" }; ////var statusConfirmed = new RequestStatus { Status = "ConfirmedBy" }; //var statusCreditProvided = new RequestStatus { Status = "statusCreditProvided" }; //var statusDenied = new RequestStatus { Status = "Denied" }; //statusRepo.Add(statusCreated, statusConfirmedByOperator, statusConfirmedByOperator, statusCreditProvided,statusDenied); // context.SaveChanges(); // var confirmedByOperatorStatusId = statusCreditProvided.RequestStatusId; // var createdStatusId = statusCreated.RequestStatusId; // var deinedStatusId = statusDenied.RequestStatusId; var creditShort = new CreditType { Name = "Easy Money", //Type = "" WTF IS TYPE????? TimeMonths = 12, PercentPerYear = 20.0m, Currency = "USD", FinePercent = 40.0m, MinAmount = 200, MaxAmount = 2000, IsAvailable = true }; var creditMedium = new CreditType { Name = "Not So Easy Money", //Type = "" WTF IS TYPE????? TimeMonths = 12 * 2, PercentPerYear = 25.0m, Currency = "USD", FinePercent = 50.0m, MinAmount = 200, MaxAmount = 5000, IsAvailable = true }; var creditLong = new CreditType { Name = "Still Money", //Type = "" WTF IS TYPE????? TimeMonths = 12 * 4, PercentPerYear = 30.0m, Currency = "USD", FinePercent = 60.0m, MinAmount = 200, MaxAmount = 5000, IsAvailable = true }; var creditTypeRepo = new CreditTypeRepository(context); creditTypeRepo.Add(creditShort, creditLong, creditMedium); context.SaveChanges(); var creditEasyId = creditShort.CreditTypeId; var creditMediumId = creditMedium.CreditTypeId; var creditLongId = creditLong.CreditTypeId; var admin = new User { Login = "******", Password = "******", Role = UserRole.Admin, IsActive = true }; var ss = new User // security service employee { Login = "******", Password = "******", Role = UserRole.SecurityServiceEmployee, IsActive = true }; var operator1 = new User // { Login = "******", Password = "******", Role = UserRole.Operator, IsActive = true }; var operator2 = new User // { Login = "******", Password = "******", Role = UserRole.Operator, IsActive = true }; var client1 = new User { Login = "******", Password = "******", Role = UserRole.Client }; var client2 = new User { Login = "******", Password = "******", Role = UserRole.Client }; var client3 = new User { Login = "******", Password = "******", Role = UserRole.Client }; var userRepo = new UserRepository(context); userRepo.Add(admin, ss, operator1, operator2, client1, client2, client3); context.SaveChanges(); var client1Id = client1.UserId; var client2Id = client2.UserId; var client3Id = client3.UserId; var client1Info = new Client { UserId = client1.UserId, Name = "Clientone", LastName = "Clientov", Patronymic = "Clientovich", Birthday = new DateTime(1990, 1, 1), Mobile = "+375441234567", Email = "*****@*****.**", PassportNo = "AB1234567", PassportIdentificationNo = "4123456B124PB7", PassportAuthority = "Ministry of internal affairs", PassportExpirationDate = DateTime.Now.AddYears(6), PlaceOfResidence = "Pushkina st.1 app.18", RegistrationAddress = "Pushkina st.1 app.18" }; var client2Info = new Client { UserId = client2.UserId, Name = "Clienttwo", LastName = "Clientov", Patronymic = "Clientovich", Birthday = new DateTime(1982, 2, 2), Mobile = "+375251234567", Email = "*****@*****.**", PassportNo = "AB1234123", PassportIdentificationNo = "4125552B124PB7", PassportAuthority = "Ministry of internal affairs", PassportExpirationDate = DateTime.Now.AddYears(1), PlaceOfResidence = "Pushkina st.2 app.7", RegistrationAddress = "Pushkina st.2 app.7" }; var client3Info = new Client { UserId = client3.UserId, Name = "Clientthree", LastName = "Clientov", Patronymic = "Clientovich", Birthday = new DateTime(1973, 3, 3), Mobile = "+375291234567", Email = "*****@*****.**", PassportNo = "AB1223331", PassportIdentificationNo = "4129332B124PB3", PassportAuthority = "Ministry of internal affairs", PassportExpirationDate = DateTime.Now.AddYears(6), PlaceOfResidence = "Pushkina st.3 app.24", RegistrationAddress = "Pushkina st.3 app.24" }; var clientRepo = new ClientRepository(context); clientRepo.Add(client1Info, client2Info, client3Info); context.SaveChanges(); var request1client1 = new Request { ClientId = client1Info.ClientId, //RequestStatusId = createdStatusId, Status = RequestStatus.Created, CreditTypeId = creditEasyId, AmountOfCredit = 1000, Salary = 500 }; var request2client1 = new Request { ClientId = client1Info.ClientId, //RequestStatusId = createdStatusId, Status = RequestStatus.Created, OperatorId = operator1.UserId, CreditTypeId = creditMediumId, AmountOfCredit = 1200, Salary = 500 }; var request3client1 = new Request { ClientId = client1Info.ClientId, //RequestStatusId = confirmedByOperatorStatusId, Status = RequestStatus.ConfirmedByOperator, OperatorId = operator1.UserId, CreditTypeId = creditLongId, AmountOfCredit = 1000, Salary = 500 }; var request4client1 = new Request { ClientId = client1Info.ClientId, Status = RequestStatus.ConfirmedByOperator, // createdStatusId, OperatorId = operator1.UserId, CreditTypeId = creditMediumId, AmountOfCredit = 1100, Salary = 500 }; var request5client1 = new Request { ClientId = client1Info.ClientId, //RequestStatusId = createdStatusId, Status = RequestStatus.CreditProvided, OperatorId = operator1.UserId, CreditTypeId = creditLongId, AmountOfCredit = 1300, Salary = 500 }; var request6client1 = new Request { ClientId = client1Info.ClientId, //RequestStatusId = confirmedByOperatorStatusId, Status = RequestStatus.CreditProvided, OperatorId = operator1.UserId, CreditTypeId = creditLongId, AmountOfCredit = 900, Salary = 500 }; var request7client1 = new Request { ClientId = client1Info.ClientId, Status = RequestStatus.ConfirmedBySecurityOfficer, // createdStatusId, OperatorId = operator1.UserId, CreditTypeId = creditLongId, AmountOfCredit = 800, Salary = 500 }; var request8client1 = new Request { ClientId = client1Info.ClientId, //RequestStatusId = confirmedByOperatorStatusId, Status = RequestStatus.CreditProvided, OperatorId = operator1.UserId, CreditTypeId = creditMediumId, AmountOfCredit = 900, Salary = 500 }; var requestRepo = new RequestRepository(context); requestRepo.Add( request1client1, request2client1, request3client1, request4client1, request5client1, request6client1, request7client1, request8client1); context.SaveChanges(); //var acc1 = new Account //Bank Account //{ // ClientId = null, // Balance = 40*1000*1000 //}; var bankAccount = new BankAccount //Bank Account { Balance = 40 * 1000 * 1000, Currency = "USD" }; context.BankAccount = bankAccount; context.SaveChanges(); var acc2 = new Account { ClientId = client1Info.ClientId, Balance = request2client1.AmountOfCredit }; var accountRepo = new AccountRepository(context); accountRepo.Add( /*acc1,*/ acc2); context.SaveChanges(); DateTime dt1 = DateTime.Now.AddDays(-(30 * 4 + 5)); var credit1Client1 = new Credit { AccountId = acc2.AccountId, CreditTypeId = creditLong.CreditTypeId, //ContractNo = 123123, //random RequestId = request5client1.RequestId, //AllreadyPaid = 0, AmountOfPaymentPerMonth = (request5client1.AmountOfCredit / creditLong.TimeMonths) * (1 + creditLong.PercentPerYear / 100 * creditLong.TimeMonths / 12), StartDate = dt1, IsRepaid = false, HasDelays = false, CountFineFromThisDate = dt1.AddDays(30),//DateTime.UtcNow.AddDays(30), //!!! hard-coded!!! AmountToCountFineFromForFirstDelayedMonth = (request5client1.AmountOfCredit / creditLong.TimeMonths) * (1 + creditLong.PercentPerYear / 100 * creditLong.TimeMonths / 12), PaidForFine = 0 }; DateTime dt2 = DateTime.UtcNow.AddDays(-(30 * 50 + 7)); var credit2Client1 = new Credit { AccountId = acc2.AccountId, CreditTypeId = creditLong.CreditTypeId, //ContractNo = 123123, //random RequestId = request6client1.RequestId, //AllreadyPaid = 0, AmountOfPaymentPerMonth = (request6client1.AmountOfCredit / creditLong.TimeMonths) * (1 + creditLong.PercentPerYear / 100 * creditLong.TimeMonths/12), StartDate = dt2, IsRepaid = true, HasDelays = true, CountFineFromThisDate = dt2.AddDays(30), //!!! hard-coded!!! AmountToCountFineFromForFirstDelayedMonth = (request6client1.AmountOfCredit / creditLong.TimeMonths) * (1 + creditLong.PercentPerYear / 100 * creditLong.TimeMonths / 12), PaidForFine = 0 }; var credit3Client1 = new Credit { AccountId = acc2.AccountId, CreditTypeId = creditMedium.CreditTypeId, //ContractNo = 123123, //random RequestId = request8client1.RequestId, //AllreadyPaid = 0, AmountOfPaymentPerMonth = (request8client1.AmountOfCredit / creditMedium.TimeMonths) * (1 + creditMedium.PercentPerYear / 100 * creditMedium.TimeMonths / 12), StartDate = DateTime.Now, IsRepaid = false, HasDelays = true, CountFineFromThisDate = DateTime.Now.AddDays(30), //!!! hard-coded!!! AmountToCountFineFromForFirstDelayedMonth = (request8client1.AmountOfCredit / creditMedium.TimeMonths) * (1 + creditMedium.PercentPerYear / 100 * creditMedium.TimeMonths / 12), PaidForFine = 0 }; request5client1.Credit = credit1Client1; // IMPORTANT do this for 1-1 relationship (exception otherwise) request6client1.Credit = credit2Client1; // IMPORTANT do this for 1-1 relationship (exception otherwise) request8client1.Credit = credit3Client1; // IMPORTANT do this for 1-1 relationship (exception otherwise) var creditRepo = new CreditRepository(context); creditRepo.Add(credit1Client1, credit2Client1, credit3Client1); context.SaveChanges(); /* var payment = new Payment { OperatorId = operator1.UserId, CreditId = credit1Client1.CreditId, //ContractNo = credit1Client1.ContractNo, Amount = 75, Date = credit1Client1.StartDate.AddDays(15) }; //var credit var payRepo = new PaymentRepository(context); payRepo.Add(payment); */ var test = context.BankAccount; //context.RequestStatuses.Where(x => x.Status.Contains("Created")).FirstOrDefault(); //context.RequestStatuses.Add(new RequestStatus { Status = "Created" }); context.SaveChanges(); } }
public void Can_not_insert_same_account_twice() { IAccountRepository repository = new AccountRepository(); repository.Add(_account1); }
public void UnitOfWorkTest() { var customer = new Client {Name = "CustomerA1", Family = "CustomerA1"}; var ClientRepository = new ClientRepository(_unitOfWork); ClientRepository.Add(customer); var account1 = new Account {Client = customer, Balance = 0, OpendedDate = DateTime.Now}; var account2 = new Account {Client = customer, Balance = 100, OpendedDate = DateTime.Now}; var accountRepository = new AccountRepository(_unitOfWork); accountRepository.Add(account1); accountRepository.Add(account2); _unitOfWork.Commit(); var accountList = accountRepository.GetCustomerAccounts(customer.ClientID); Assert.AreEqual(2, accountList.Count); }