public async void Add_AddMultipleEntries() { // Arrange var unitOfWork = new UnitOfWork(dbFactory); var repository = new RecurringPaymentRepository(dbFactory); // Act repository.Add(new RecurringPaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" } }); repository.Add(new RecurringPaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" } }); repository.Add(new RecurringPaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" } }); await unitOfWork.Commit(); // Assert Assert.Equal(3, repository.GetAll().Count()); }
public async void Delete_EntryMatchedFilterDeleted() { // Arrange var unitOfWork = new UnitOfWork(dbFactory); var filterText = "Text"; var repository = new RecurringPaymentRepository(dbFactory); var testEntry1 = new RecurringPaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" }, Note = filterText }; var testEntry2 = new RecurringPaymentEntity { 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 async void Get_MatchedDataReturned() { // Arrange var unitOfWork = new UnitOfWork(dbFactory); var repository = new RecurringPaymentRepository(dbFactory); var filterText = "Text"; var testEntry = new RecurringPaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" }, Note = filterText }; repository.Add(testEntry); repository.Add(new RecurringPaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" } }); repository.Add(new RecurringPaymentEntity { 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 Add_AddNewEntryOnEveryCall() { // Arrange var unitOfWork = new UnitOfWork(dbFactory); var repository = new RecurringPaymentRepository(dbFactory); var testEntry = new RecurringPaymentEntity { 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 GetMany_MatchedDataReturned() { // Arrange var factory = new DbFactory(); var unitOfWork = new UnitOfWork(factory); var repository = new RecurringPaymentRepository(factory); var filterText = "Text"; repository.Add(new RecurringPaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" }, Note = filterText }); repository.Add(new RecurringPaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" } }); repository.Add(new RecurringPaymentEntity { 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 GetMany_NothingMatched() { // Arrange var factory = new DbFactory(); var unitOfWork = new UnitOfWork(factory); var repository = new RecurringPaymentRepository(factory); repository.Add(new RecurringPaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" } }); repository.Add(new RecurringPaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" } }); repository.Add(new RecurringPaymentEntity { 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 Get_NothingMatched() { // Arrange var unitOfWork = new UnitOfWork(dbFactory); var repository = new RecurringPaymentRepository(dbFactory); repository.Add(new RecurringPaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" } }); repository.Add(new RecurringPaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" } }); repository.Add(new RecurringPaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" } }); await unitOfWork.Commit(); // Act var result = await repository.Get(x => x.Note == "text"); // Assert Assert.Null(result); }
public async void GetAll_AllDataReturned() { // Arrange var unitOfWork = new UnitOfWork(dbFactory); var repository = new RecurringPaymentRepository(dbFactory); repository.Add(new RecurringPaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" } }); repository.Add(new RecurringPaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" } }); repository.Add(new RecurringPaymentEntity { 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_MatchedDataReturned() { // 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 filterText = "Text"; using (var dbContextScope = dbContextScopeFactory.Create()) { recurringPaymentRepository.Add(new RecurringPaymentEntity { ChargedAccount = testAccount, Note = filterText }); await dbContextScope.SaveChangesAsync(); } List <RecurringPaymentEntity> resultList; // Act using (var dbContextScope = dbContextScopeFactory.Create()) { recurringPaymentRepository.Add(new RecurringPaymentEntity { ChargedAccount = testAccount }); recurringPaymentRepository.Add(new RecurringPaymentEntity { ChargedAccount = testAccount }); await dbContextScope.SaveChangesAsync(); resultList = recurringPaymentRepository.GetMany(x => x.Note == filterText).ToList(); } // Assert Assert.NotNull(resultList); Assert.Equal(1, resultList.Count); }
public async void Add_AddedAndRead() { // Arrange var factory = new DbFactory(); var unitOfWork = new UnitOfWork(factory); var repository = new RecurringPaymentRepository(factory); var testEntry = new RecurringPaymentEntity { 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); }
public async void Update_IdUnchanged() { // Arrange var unitOfWork = new UnitOfWork(dbFactory); var repository = new RecurringPaymentRepository(dbFactory); var testEntry = new RecurringPaymentEntity { 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 unitOfWork = new UnitOfWork(dbFactory); var repository = new RecurringPaymentRepository(dbFactory); var newValue = "newText"; var testEntry = new RecurringPaymentEntity { 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_IdSet() { // 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 Assert.NotNull(testEntry.Id); Assert.NotEqual(0, testEntry.Id); }
public async void Update_NoNewEntryAdded() { // Arrange var unitOfWork = new UnitOfWork(dbFactory); var repository = new RecurringPaymentRepository(dbFactory); var testEntry = new RecurringPaymentEntity { 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 Delete_EntryMatchedFilterDeleted() { // Arrange var filterText = "Text"; 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 testEntry1 = new RecurringPaymentEntity { ChargedAccount = testAccount, Note = filterText }; using (var dbContextScope = dbContextScopeFactory.Create()) { var testEntry2 = new RecurringPaymentEntity { ChargedAccount = testAccount }; recurringPaymentRepository.Add(testEntry1); recurringPaymentRepository.Add(testEntry2); await dbContextScope.SaveChangesAsync(); } // Act using (var dbContextScope = dbContextScopeFactory.Create()) { recurringPaymentRepository.Delete(x => x.Note == filterText); await dbContextScope.SaveChangesAsync(); } // Assert using (dbContextScopeFactory.CreateReadOnly()) { Assert.Equal(1, recurringPaymentRepository.GetAll().Count()); } }
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 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()); }
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 async void Add_WithoutAccount() { // Arrange var factory = new DbFactory(); var unitOfWork = new UnitOfWork(factory); var repository = new RecurringPaymentRepository(factory); var testEntry = new RecurringPaymentEntity() { Note = "Testtext" }; // Act / Assert repository.Add(testEntry); await Assert.ThrowsAsync <DbUpdateException>(async() => await unitOfWork.Commit()); }
public async void Update_EntryUpdated() { // 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 newValue = "newText"; 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.Note = newValue; recurringPaymentRepository.Update(testEntry); await dbContextScope.SaveChangesAsync(); } // Assert using (dbContextScopeFactory.CreateReadOnly()) { var loadedEntry = await recurringPaymentRepository.GetById(testEntry.Id); Assert.Equal(newValue, loadedEntry.Note); } }
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 async void Delete_EntryDeleted() { // Arrange var unitOfWork = new UnitOfWork(dbFactory); var repository = new RecurringPaymentRepository(dbFactory); var testEntry = new RecurringPaymentEntity { ChargedAccount = 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 Add_IdSet() { // Arrange var unitOfWork = new UnitOfWork(dbFactory); var repository = new RecurringPaymentRepository(dbFactory); var testEntry = new RecurringPaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" }, Note = "Testtext" }; // Act repository.Add(testEntry); await unitOfWork.Commit(); // Assert Assert.NotNull(testEntry.Id); Assert.NotEqual(0, testEntry.Id); }