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 void AddListOfItemsFailsValidationTestAsync() { //Given var repository = new EfCoreAsyncAccountRepository(_databaseFactory); var listOfItems = AccountEntityHelper.CreateEfCoreTestAccounts(3); listOfItems[1].CompanyName = null; //When AsyncTestDelegate asyncTestDelegate = async() => await repository.AddRangeAsync(listOfItems).ConfigureAwait(true); //Then Assert.ThrowsAsync <DbUpdateException>( asyncTestDelegate); }
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 GetAsyncItemsViaStoredProcedureWithNoParameterNotParameterisedTestAsync() { //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 var items = await repository.ExecuteQueryAsync <Account>("exec GetAccounts").ConfigureAwait(true); //Then EqualityHelper.AssertListsAreEqual(items.OrderBy(x => x.CompanyName).ToList(), listOfItems.OrderBy(x => x.CompanyName).ToList(), new[] { "AccountID", "LastModified", "LastModifiedBy", "Contacts" }); } }
public async Task GetAsyncAutoCompleteItemsTestAsync() { //Given using (var efCoreAsyncUnitOfWork = new EfCoreAsyncUnitOfWork <SharedLibraryContext>(_databaseFactory)) { var repository = new EfCoreAsyncAccountRepository(_databaseFactory); var reference = "TestReference"; var listOfItems = GetAsyncItemsWithTwoItemsContainingTestReference(reference); await repository.AddRangeAsync(listOfItems).ConfigureAwait(true); await efCoreAsyncUnitOfWork.CommitAsync().ConfigureAwait(true); //When var item = await repository.GetAutoCompleteItemsAsync(x => x.CompanyName.Contains(reference), 1).ConfigureAwait(true); //Then EqualityHelper.PropertyValuesAreEqual(item.First(), listOfItems[0], new[] { "AccountID", "LastModified", "LastModifiedBy", "Contacts" }); } }
public async Task GetAsyncMAnyAsyncWithWhereClauseSuccessTestAsync() { //Given using (var efCoreAsyncUnitOfWork = new EfCoreAsyncUnitOfWork <SharedLibraryContext>(_databaseFactory)) { var repository = new EfCoreAsyncAccountRepository(_databaseFactory); var reference = "TestReference"; var listOfItems = GetAsyncItemsWithTwoItemsContainingTestReference(reference); await repository.AddRangeAsync(listOfItems).ConfigureAwait(true); await efCoreAsyncUnitOfWork.CommitAsync().ConfigureAwait(true); //When var items = await repository.GetManyAsync(x => x.CompanyName.Contains(reference)).ConfigureAwait(true); //Then EqualityHelper.AssertListsAreEqual(items.OrderBy(x => x.CompanyName).ToList(), listOfItems.OrderBy(x => x.CompanyName).Take(2).ToList(), new[] { "AccountID", "LastModified", "LastModifiedBy", "Contacts" }); } }
public async Task GetAsyncNoneAsyncButSomeExistTestAsync() { //Given using (var efCoreAsyncUnitOfWork = new EfCoreAsyncUnitOfWork <SharedLibraryContext>(_databaseFactory)) { var repository = new EfCoreAsyncAccountRepository(_databaseFactory); var listOfItems = AccountEntityHelper.CreateEfCoreTestAccounts(3); listOfItems[2].CompanyName = "TestReferenceOtherValue"; await repository.AddRangeAsync(listOfItems).ConfigureAwait(true); await efCoreAsyncUnitOfWork.CommitAsync().ConfigureAwait(true); //When var hasNoneAsync = await repository.NoneAsync(x => x.CompanyName.Contains("TestReference")).ConfigureAwait(true); //Then Assert.IsFalse(hasNoneAsync, "NoneAsync were found when there should have been some."); } }
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 GetAsyncWithWhereClauseSuccessTestAsync() { //Given using (var efCoreAsyncUnitOfWork = new EfCoreAsyncUnitOfWork <SharedLibraryContext>(_databaseFactory)) { var repository = new EfCoreAsyncAccountRepository(_databaseFactory); var listOfItems = AccountEntityHelper.CreateEfCoreTestAccounts(3); listOfItems[2].CompanyName = "TestReferenceOtherValue"; await repository.AddRangeAsync(listOfItems).ConfigureAwait(true); await efCoreAsyncUnitOfWork.CommitAsync().ConfigureAwait(true); //When var items = await repository.GetAsync(x => x.CompanyName.Contains("TestReference")).ConfigureAwait(true); //Then EqualityHelper.PropertyValuesAreEqual(items, listOfItems[2], new[] { "AccountID", "LastModified", "LastModifiedBy", "Contacts" }); } }
public async Task GetAsyncItemsViaStoredProcedureWithParameterNotParameterisedTestAsync() { //Given using (var efCoreAsyncUnitOfWork = new EfCoreAsyncUnitOfWork <SharedLibraryContext>(_databaseFactory)) { var repository = new EfCoreAsyncAccountRepository(_databaseFactory); var reference = "TestReference"; var listOfItems = GetAsyncItemsWithTwoItemsContainingTestReference(reference); await repository.AddRangeAsync(listOfItems).ConfigureAwait(true); await efCoreAsyncUnitOfWork.CommitAsync().ConfigureAwait(true); //When var filter = new SqlParameter("@CompanyName", SqlDbType.VarChar) { Value = $"%{reference}%" }; var items = await repository.ExecuteQueryAsync <Account>("exec GetAccounts @CompanyName", filter).ConfigureAwait(true); //Then EqualityHelper.AssertListsAreEqual(items.OrderBy(x => x.CompanyName).ToList(), listOfItems.OrderBy(x => x.CompanyName).Take(2).ToList(), new[] { "AccountID", "LastModified", "LastModifiedBy", "Contacts" }); } }
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" }); } }