public async void Get_MatchedDataReturned() { // Arrange var unitOfWork = new UnitOfWork(dbFactory); var repository = new PaymentRepository(dbFactory); var filterText = "Text"; var testEntry = new PaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" }, Note = filterText }; repository.Add(testEntry); repository.Add(new PaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" } }); repository.Add(new PaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" } }); await unitOfWork.Commit(); // Act var result = await repository.Get(x => x.Note == filterText); // Assert Assert.NotNull(result); Assert.Equal(testEntry.Id, result.Id); }
public async void GetMany_MatchedDataReturned() { // Arrange var factory = new DbFactory(); var unitOfWork = new UnitOfWork(factory); var repository = new PaymentRepository(factory); var filterText = "Text"; repository.Add(new PaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" }, Note = filterText }); repository.Add(new PaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" } }); repository.Add(new PaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" } }); await unitOfWork.Commit(); // Act var resultList = repository.GetMany(x => x.Note == filterText).ToList(); // Assert Assert.NotNull(resultList); Assert.Equal(1, resultList.Count); }
public async void Delete_EntryMatchedFilterDeleted() { // Arrange var factory = new DbFactory(); var unitOfWork = new UnitOfWork(factory); var filterText = "Text"; var repository = new PaymentRepository(factory); var testEntry1 = new PaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" }, Note = filterText }; var testEntry2 = new PaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" } }; repository.Add(testEntry1); repository.Add(testEntry2); await unitOfWork.Commit(); // Act repository.Delete(x => x.Note == filterText); await unitOfWork.Commit(); // Assert Assert.Equal(1, repository.GetAll().Count()); }
public void Test_PaymentRepository_Find() { using (IPaymentRepository repo = new PaymentRepository()) { //Arrange var payment1 = new Payment { PaymentID = 1, Amount = 3.50m, Type = PaymentType.Cash }; repo.Add(payment1); var payment2 = new Payment { PaymentID = 1, Amount = 1.50m, Type = PaymentType.CreditCard }; repo.Add(payment2); //Act var criteria = new PaymentFindCriteria(); criteria.Type = PaymentType.CreditCard; var result = repo.FindByCriteria(criteria).FirstOrDefault(); //Assert Assert.AreEqual(payment2, result); } }
public async void Get_NothingMatched() { // Arrange var factory = new DbFactory(); var unitOfWork = new UnitOfWork(factory); var repository = new PaymentRepository(factory); repository.Add(new PaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" } }); repository.Add(new PaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" } }); repository.Add(new PaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" } }); await unitOfWork.Commit(); // Act var result = await repository.Get(x => x.Note == "text"); // Assert Assert.Null(result); }
public void Test_DrinkCanRepository_Reset() { using (IPaymentRepository repo = new PaymentRepository()) { //Arrange var payment1 = new Payment { PaymentID = 1, Amount = 3.50m, Type = PaymentType.Cash }; repo.Add(payment1); var payment2 = new Payment { PaymentID = 1, Amount = 1.50m, Type = PaymentType.CreditCard }; repo.Add(payment2); //Act repo.Reset(); var criteria = new PaymentFindCriteria(); var result = repo.FindByCriteria(criteria).FirstOrDefault(); repo.Delete(result); var updatedList = repo.FindByCriteria(criteria); //Assert Assert.AreEqual(0, updatedList.Count()); } }
public async void Add_AddMultipleEntries() { // Arrange var factory = new DbFactory(); var unitOfWork = new UnitOfWork(factory); var repository = new PaymentRepository(factory); // Act repository.Add(new PaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" } }); repository.Add(new PaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" } }); repository.Add(new PaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" } }); await unitOfWork.Commit(); // Assert Assert.Equal(3, repository.GetAll().Count()); }
public async void Add_AddNewEntryOnEveryCall() { // Arrange var factory = new DbFactory(); var unitOfWork = new UnitOfWork(factory); var repository = new PaymentRepository(factory); var testEntry = new PaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" }, Note = "Testtext" }; // Act repository.Add(testEntry); await unitOfWork.Commit(); testEntry.Id = 0; repository.Add(testEntry); await unitOfWork.Commit(); // Assert Assert.Equal(2, repository.GetAll().Count()); }
public async void GetAll_AllDataReturned() { // Arrange var factory = new DbFactory(); var unitOfWork = new UnitOfWork(factory); var repository = new PaymentRepository(factory); repository.Add(new PaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" } }); repository.Add(new PaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" } }); repository.Add(new PaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" } }); await unitOfWork.Commit(); // Act var resultList = repository.GetAll().ToList(); // Assert Assert.NotNull(resultList); Assert.Equal(3, resultList.Count); }
public async void GetMany_NothingMatched() { // Arrange var unitOfWork = new UnitOfWork(dbFactory); var repository = new PaymentRepository(dbFactory); repository.Add(new PaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" } }); repository.Add(new PaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" } }); repository.Add(new PaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" } }); await unitOfWork.Commit(); // Act var resultList = repository.GetMany(x => x.Note == "text").ToList(); // Assert Assert.NotNull(resultList); Assert.False(resultList.Any()); }
public async void Update_NoNewEntryAdded() { // Arrange var factory = new DbFactory(); var unitOfWork = new UnitOfWork(factory); var repository = new PaymentRepository(factory); var testEntry = new PaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" }, Note = "Testtext" }; // Act repository.Add(testEntry); await unitOfWork.Commit(); repository.Update(testEntry); await unitOfWork.Commit(); // Assert Assert.Equal(1, repository.GetAll().Count()); }
public async void Update_IdUnchanged() { // Arrange var factory = new DbFactory(); var unitOfWork = new UnitOfWork(factory); var repository = new PaymentRepository(factory); var testEntry = new PaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" }, Note = "Testtext" }; // Act repository.Add(testEntry); await unitOfWork.Commit(); var idBeforeUpdate = testEntry.Id; repository.Update(testEntry); await unitOfWork.Commit(); // Assert Assert.Equal(idBeforeUpdate, testEntry.Id); }
public async void Update_EntryUpdated() { // Arrange var factory = new DbFactory(); var unitOfWork = new UnitOfWork(factory); var repository = new PaymentRepository(factory); var newValue = "newText"; var testEntry = new PaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" }, Note = "Testtext" }; // Act repository.Add(testEntry); await unitOfWork.Commit(); testEntry.Note = newValue; repository.Update(testEntry); await unitOfWork.Commit(); // Assert var loadedEntry = await repository.GetById(testEntry.Id); Assert.Equal(newValue, loadedEntry.Note); }
public async void Add_WithRecurringPayment() { // Arrange var factory = new DbFactory(); var unitOfWork = new UnitOfWork(factory); var repository = new PaymentRepository(factory); var testAccount = new AccountEntity { Name = "testAccount" }; var testEntry = new PaymentEntity { ChargedAccount = testAccount, RecurringPayment = new RecurringPaymentEntity { ChargedAccount = testAccount, Recurrence = PaymentRecurrence.Bimonthly, IsEndless = true }, IsRecurring = true, Note = "Testtext" }; // Act repository.Add(testEntry); await unitOfWork.Commit(); // Assert Assert.NotNull(testEntry.Id); Assert.NotEqual(0, testEntry.Id); Assert.NotEqual(0, testEntry.RecurringPayment.Id); Assert.NotEqual(0, testEntry.RecurringPaymentId); }
public async void Delete_RelatedPaymentSetNull() { // Arrange var unitOfWork = new UnitOfWork(dbFactory); var recurringPaymentRepository = new RecurringPaymentRepository(dbFactory); var paymentRepository = new PaymentRepository(dbFactory); var recurringPaymentEntity = new RecurringPaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" } }; var payment = new PaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" }, RecurringPayment = recurringPaymentEntity }; paymentRepository.Add(payment); await unitOfWork.Commit(); // Act recurringPaymentRepository.Delete(recurringPaymentEntity); await unitOfWork.Commit(); // Assert Assert.Null(payment.RecurringPayment); Assert.Null(paymentRepository.GetById(payment.Id).Result.RecurringPayment); }
public void Import(IEnumerable <P.Payment> payments) { foreach (var payment in payments) { PaymentRepository.Add(payment); } }
public async void DeleteAccount_RelatedChargedPaymentsRemoved() { // Arrange var unitOfWork = new UnitOfWork(dbFactory); var accountRepository = new AccountRepository(dbFactory); var paymentRepository = new PaymentRepository(dbFactory); var account = new AccountEntity { Name = "Testtext" }; var payment = new PaymentEntity { Note = "Foo", ChargedAccount = account }; accountRepository.Add(account); paymentRepository.Add(payment); await unitOfWork.Commit(); Assert.Equal(1, await accountRepository.GetAll().CountAsync()); Assert.Equal(1, await paymentRepository.GetAll().CountAsync()); // Act accountRepository.Delete(account); await unitOfWork.Commit(); // Assert Assert.False(await accountRepository.GetAll().AnyAsync()); Assert.False(await paymentRepository.GetAll().AnyAsync()); }
public async void Add_AddedAndRead() { // Arrange var factory = new DbFactory(); var unitOfWork = new UnitOfWork(factory); var repository = new PaymentRepository(factory); var testEntry = new PaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" }, Note = "Testtext" }; // Act repository.Add(testEntry); await unitOfWork.Commit(); // Assert var loadedEntry = await repository.GetById(testEntry.Id); Assert.Equal(testEntry.Note, loadedEntry.Note); }
/// <inheritdoc /> public async Task <BalanceDto> AddPayment(PaymentAddDto request, PaymentType type = PaymentType.User) { var payment = new Payment { ClientId = request.ClientId, Amount = request.Amount, Comment = request.Comment, DateTime = DateTime.Now, Type = type }; await _repository.Add(payment); var payments = await _repository.GetByClientId(request.ClientId); var balance = 0.0; foreach (var pay in payments) { balance += pay.Amount; } return(new BalanceDto { ClientId = request.ClientId, Balance = await _clientService.UpdateBalance(balance, request.ClientId) }); }
public async void Delete_AssignedPaymentsSetNull() { // Arrange var factory = new DbFactory(); var unitOfWork = new UnitOfWork(factory); var categoryRepository = new CategoryRepository(factory); var paymentRepository = new PaymentRepository(factory); var category = new CategoryEntity { Name = "TestCategory" }; var payment = new PaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" }, Category = category }; categoryRepository.Add(category); paymentRepository.Add(payment); await unitOfWork.Commit(); // Act categoryRepository.Delete(category); await unitOfWork.Commit(); // Assert Assert.Null(payment.Category); Assert.Null(paymentRepository.GetById(payment.Id).Result.Category); }
public async void Add_IdSet() { // Arrange var paymentRepository = new PaymentRepository(ambientDbContextLocator); var accountRepository = new AccountRepository(ambientDbContextLocator); var account = new AccountEntity { Name = "testAccount" }; using (var dbContextScope = dbContextScopeFactory.Create()) { accountRepository.Add(account); await dbContextScope.SaveChangesAsync(); } var testEntry = new PaymentEntity { ChargedAccount = account, Note = "Testtext" }; // Act using (var dbContextScope = dbContextScopeFactory.Create()) { paymentRepository.Add(testEntry); await dbContextScope.SaveChangesAsync(); } // Assert Assert.NotNull(testEntry.Id); Assert.NotEqual(0, testEntry.Id); }
public async void GetMany_MatchedDataReturned() { // 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 filterText = "Text"; using (var dbContextScope = dbContextScopeFactory.Create()) { paymentRepository.Add(new PaymentEntity { ChargedAccount = testAccount, Note = filterText }); await dbContextScope.SaveChangesAsync(); } List <PaymentEntity> resultList; // Act using (var dbContextScope = dbContextScopeFactory.Create()) { paymentRepository.Add(new PaymentEntity { ChargedAccount = testAccount }); paymentRepository.Add(new PaymentEntity { ChargedAccount = testAccount }); await dbContextScope.SaveChangesAsync(); resultList = paymentRepository.GetMany(x => x.Note == filterText).ToList(); } // Assert Assert.NotNull(resultList); Assert.Equal(1, resultList.Count); }
public void AddPayment() { using (CapriconContext context = new CapriconContext()) { var messageRepository = new MessageRepository(context); var existingMessage = messageRepository.GetAll().LastOrDefault(); Assert.IsNotNull(existingMessage); var newPayment = new Payment() { PaymentDate = DateTime.Now, Amount = 750, Message = existingMessage }; var paymentRep = new PaymentRepository(context); paymentRep.Add(newPayment); try { context.SaveChanges(); } catch (DbEntityValidationException ex) { //Retrieve validation errors ex.EntityValidationErrors.ToList().ForEach ( v => { v.ValidationErrors.ToList().ForEach ( e => { System.Diagnostics.Debug.WriteLine(e.ErrorMessage); } ); } ); Assert.Fail("Test failed"); } //retrieve saved object var context1 = new CapriconContext(); var repository = new PaymentRepository(context1); var savedPayments = repository.GetAll().ToList(); Assert.AreEqual(savedPayments.Count(), 3, "returns 20 records"); var savedPaymentsList = savedPayments; savedPaymentsList.ForEach ( p => { Debug.WriteLine(p.PaymentId + " - " + p.Amount + " " + p.Message.MessageId); } ); }; }
public async void Delete_EntryMatchedFilterDeleted() { // Arrange var filterText = "Text"; 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 testEntry1 = new PaymentEntity { ChargedAccount = testAccount, Note = filterText }; var testEntry2 = new PaymentEntity { ChargedAccount = testAccount }; // Act using (var dbContextScope = dbContextScopeFactory.Create()) { paymentRepository.Add(testEntry1); paymentRepository.Add(testEntry2); await dbContextScope.SaveChangesAsync(); } using (var dbContextScope = dbContextScopeFactory.Create()) { paymentRepository.Delete(x => x.Note == filterText); await dbContextScope.SaveChangesAsync(); } // Assert using (dbContextScopeFactory.CreateReadOnly()) { Assert.Equal(1, paymentRepository.GetAll().Count()); } }
public async void Delete_AssignedRelatedPaymentsSetNull() { // Arrange var categoryRepository = new CategoryRepository(ambientDbContextLocator); var accountRepository = new AccountRepository(ambientDbContextLocator); var paymentRepository = new PaymentRepository(ambientDbContextLocator); var category = new CategoryEntity { Name = "TestCategory" }; var account = new AccountEntity { Name = "testAccount" }; var recurringPayment = new RecurringPaymentEntity { ChargedAccount = account, Category = category }; using (var dbContextScope = dbContextScopeFactory.Create()) { categoryRepository.Add(category); accountRepository.Add(account); await dbContextScope.SaveChangesAsync(); } var payment = new PaymentEntity { ChargedAccount = account, Category = category, RecurringPayment = recurringPayment }; using (var dbContextScope = dbContextScopeFactory.Create()) { categoryRepository.Add(category); paymentRepository.Add(payment); await dbContextScope.SaveChangesAsync(); } // Act using (var dbContextScope = dbContextScopeFactory.Create()) { categoryRepository.Delete(category); await dbContextScope.SaveChangesAsync(); } // Assert using (dbContextScopeFactory.CreateReadOnly()) { Assert.Null(recurringPayment.Category); Assert.Null(paymentRepository.GetById(payment.Id).Result.RecurringPayment.Category); } }
public async void Add_AddNewEntryOnEveryCall() { // Arrange var paymentRepository = new PaymentRepository(ambientDbContextLocator); var accountRepository = new AccountRepository(ambientDbContextLocator); var account = new AccountEntity { Name = "testAccount" }; using (var dbContextScope = dbContextScopeFactory.Create()) { accountRepository.Add(account); await dbContextScope.SaveChangesAsync(); } var testEntry = new PaymentEntity { ChargedAccount = account, Note = "Testtext" }; // Act using (var dbContextScope = dbContextScopeFactory.Create()) { paymentRepository.Add(testEntry); await dbContextScope.SaveChangesAsync(); } using (var dbContextScope = dbContextScopeFactory.Create()) { testEntry.Id = 0; paymentRepository.Add(testEntry); await dbContextScope.SaveChangesAsync(); } // Assert using (dbContextScopeFactory.CreateReadOnly()) { Assert.Equal(2, paymentRepository.GetAll().Count()); } }
public async void Add_AddMultipleEntries() { // Arrange var paymentRepository = new PaymentRepository(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()) { paymentRepository.Add(new PaymentEntity { ChargedAccount = account }); paymentRepository.Add(new PaymentEntity { ChargedAccount = account }); paymentRepository.Add(new PaymentEntity { ChargedAccount = account }); await dbContextScope.SaveChangesAsync(); } // Assert using (dbContextScopeFactory.CreateReadOnly()) { Assert.Equal(3, paymentRepository.GetAll().Count()); } }
public async void GetMany_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(); } List <PaymentEntity> resultList; // 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(); resultList = paymentRepository.GetMany(x => x.Note == "text").ToList(); } // Assert Assert.NotNull(resultList); Assert.False(resultList.Any()); }
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 Task AddTest() { var options = new DbContextOptionsBuilder <JanusContext>() .UseInMemoryDatabase(databaseName: "save-a-transaction") .Options; using (var context = new JanusContext(options)) { var paymentRepo = new PaymentRepository(context); await paymentRepo.Add(new Transaction { Id = 1, Amount = 11.45, ExternalId = "externalId", Status = true }); await paymentRepo.Add(new Transaction { Id = 2, Amount = 11.45, ExternalId = "externalId2", Status = true }); await paymentRepo.Add(new Transaction { Id = 3, Amount = 11.45, ExternalId = "externalId3", Status = true }); } using (var newContext = new JanusContext(options)) { var transactions = await newContext.Transactions.ToListAsync(); Assert.AreEqual(3, transactions.Count); } }