public async Task DeleteAsyncWithWhereClauseSuccessTestAsync() { //Given using (var efCoreAsyncUnitOfWork = new EfCoreAsyncUnitOfWork <SharedLibraryContext>(_databaseFactory)) { var repository = new EfCoreAsyncAccountRepository(_databaseFactory); var listOfItems = AccountEntityHelper.CreateEfCoreTestAccounts(3); var originalItems = await repository.GetAllAsync().ConfigureAwait(true); await repository.AddRangeAsync(listOfItems).ConfigureAwait(true); var allNewItems = await repository.GetAllAsync().ConfigureAwait(true); var newItems = allNewItems as IList <Account> ?? allNewItems.ToList(); var itemsAdded = newItems.Except(originalItems).ToList(); //When var idsToDeleteAsync = itemsAdded.Select(x => x.AccountId); await repository.DeleteAsync(x => idsToDeleteAsync.Contains(x.AccountId)).ConfigureAwait(true); await efCoreAsyncUnitOfWork.CommitAsync().ConfigureAwait(true); var allItems = await repository.GetAllAsync().ConfigureAwait(true); //Then Assert.AreEqual(0, allItems.Except(newItems).Count(), "The items have not been DeleteAsyncd."); } }
public async Task UpdateFailItemTestAsync() { //Given Account testAccount; var repository = new EfCoreAsyncAccountRepository(_databaseFactory); using (var efCoreAsyncUnitOfWork = new EfCoreAsyncUnitOfWork <SharedLibraryContext>(_databaseFactory)) { testAccount = await repository.SaveAsync(AccountEntityHelper.CreateEfTestAccount()).ConfigureAwait(true); await efCoreAsyncUnitOfWork.CommitAsync().ConfigureAwait(false); } using (var efCoreAsyncUnitOfWork = new EfCoreAsyncUnitOfWork <SharedLibraryContext>(_databaseFactory)) { //When testAccount.CompanyName = null; await repository.SaveAsync(testAccount).ConfigureAwait(true); // ReSharper disable once AccessToDisposedClosure AsyncTestDelegate testDelegate = async() => await efCoreAsyncUnitOfWork.CommitAsync().ConfigureAwait(true); Assert.ThrowsAsync <DbUpdateException>(testDelegate); } //Then //GetAsync fresh database factory var finalDatabaseFactory = new EfCoreDatabaseFactoryBase <SharedLibraryContext>("SharedLibraryContext"); var finalRepo = new EfCoreAsyncAccountRepository(finalDatabaseFactory); var itemToCheck = await finalRepo.GetAllAsync().ConfigureAwait(true); Assert.AreEqual(testAccount.CompanyName, itemToCheck.FirstOrDefault()?.CompanyName, "The compAnyAsync name was updated when it should not have been"); }
public async Task AddListOfItemsTestAsync() { //Given var repository = new EfCoreAsyncAccountRepository(_databaseFactory); var listOfItems = AccountEntityHelper.CreateEfCoreTestAccounts(3); var originalItems = await repository.GetAllAsync().ConfigureAwait(true); //When await repository.AddRangeAsync(listOfItems).ConfigureAwait(true); //Then var allNewItems = await repository.GetAllAsync().ConfigureAwait(true); var itemsAdded = allNewItems.Except(originalItems).ToList(); EqualityHelper.AssertListsAreEqual(itemsAdded, listOfItems, new[] { "AccountID", "LastModified", "Contacts" }); }
public async Task GetAllAsyncButNoneAsyncExistTestAsync() { //Given var repository = new EfCoreAsyncAccountRepository(_databaseFactory); //When var allItems = await repository.GetAllAsync().ConfigureAwait(true); //Then Assert.AreEqual(0, allItems.Count(), "Some items were returned where NoneAsync should have been"); }
public async Task ExecuteStoredProcedureAsActionTestAsync() { //Given using (var efCoreAsyncUnitOfWork = new EfCoreAsyncUnitOfWork <SharedLibraryContext>(_databaseFactory)) { var repository = new EfCoreAsyncAccountRepository(_databaseFactory); var listOfItems = AccountEntityHelper.CreateEfCoreTestAccounts(3); await repository.AddRangeAsync(listOfItems).ConfigureAwait(true); await efCoreAsyncUnitOfWork.CommitAsync().ConfigureAwait(true); //When await repository.ExecuteQueryAsActionAsync("exec DeleteAllAccounts").ConfigureAwait(true); //Then var allItems = await repository.GetAllAsync().ConfigureAwait(true); Assert.AreEqual(0, allItems.ToList().Count(), "There are still items in the database."); } }
public async Task GetAllAsyncSuccessTestAsync() { //Given using (var efCoreAsyncUnitOfWork = new EfCoreAsyncUnitOfWork <SharedLibraryContext>(_databaseFactory)) { var repository = new EfCoreAsyncAccountRepository(_databaseFactory); var listOfItems = AccountEntityHelper.CreateEfCoreTestAccounts(3); listOfItems[0].CompanyName = "1"; listOfItems[1].CompanyName = "2"; listOfItems[2].CompanyName = "3"; await repository.AddRangeAsync(listOfItems).ConfigureAwait(true); await efCoreAsyncUnitOfWork.CommitAsync().ConfigureAwait(true); //When var allItems = await repository.GetAllAsync().ConfigureAwait(true); //Then EqualityHelper.AssertListsAreEqual(allItems.OrderBy(x => x.CompanyName).ToList(), listOfItems.OrderBy(x => x.CompanyName).ToList(), new[] { "AccountID", "LastModified", "LastModifiedBy", "Contacts" }); } }