public async Task UpdateSuccessItemTestAsync()
        {
            //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(true);

                //When
                testAccount.CompanyName = "Updated account";
                await repository.SaveAsync(testAccount).ConfigureAwait(true);

                await efCoreAsyncUnitOfWork.CommitAsync().ConfigureAwait(true);
            }

            //Then
            var finalRepo   = new EfCoreAsyncAccountRepository(_databaseFactory);
            var itemToCheck = await finalRepo.GetByIdAsync(testAccount.AccountId).ConfigureAwait(true);

            EqualityHelper.PropertyValuesAreEqual(itemToCheck, testAccount, new[] { "LastModified", "Contact" });
        }
        public void UpdateSuccessItemTest()
        {
            //Given
            var     databseFactory = new EfCoreDatabaseFactoryBase <SharedLibraryContext>("SharedLibraryContext");
            Account testAccount;
            var     repository = new EfCoreAccountRepository(databseFactory);

            using (var efCoreUnitOfWork = new EfCoreUnitOfWork <SharedLibraryContext>(databseFactory))
            {
                testAccount = repository.Save(AccountEntityHelper.CreateEfTestAccount());
                efCoreUnitOfWork.Commit();

                //When
                testAccount.CompanyName = "Updated account";
                repository.Save(testAccount);
                efCoreUnitOfWork.Commit();
            }

            //Then
            var finalDatabaseFactory = new EfCoreDatabaseFactoryBase <SharedLibraryContext>("SharedLibraryContext");
            var finalRepo            = new EfCoreAccountRepository(finalDatabaseFactory);
            var itemToCheck          = finalRepo.GetById(testAccount.AccountId);

            EqualityHelper.PropertyValuesAreEqual(itemToCheck, testAccount, new[] { "LastModified", "Contact" });
        }
        public void GetAccountByIdTest()
        {
            //Given
            var compositeKeyTest = CreateAndRetrieveTestItem();

            //When
            var response = GetController().Get().First(keyTest => keyTest.FirstKey == compositeKeyTest.FirstKey && keyTest.SecondKey == compositeKeyTest.SecondKey);

            //Then
            EqualityHelper.PropertyValuesAreEqual(response, compositeKeyTest, new[] { "LastModified", "LastModifiedBy" });
        }
        public void DeleteAccountTest()
        {
            //Given
            var testItem = CreateAndRetrieveTestItem();

            //When
            var response = GetController().Get(testItem.AccountID);

            //Then
            EqualityHelper.PropertyValuesAreEqual(response.Queryable.First(), testItem, new [] { "LastModified", "LastModifiedBy", "Contacts" });
        }
        public void GetAccountByIdTest()
        {
            //Given
            var testItem = CreateAndRetrieveTestItem();

            //When
            var response = GetController().Get().First(account => account.AccountID == testItem.AccountID);

            //Then
            EqualityHelper.PropertyValuesAreEqual(response, testItem, new[] { "LastModified", "LastModifiedBy", "Contacts" });
        }
        public void UpdateAccountTest()
        {
            //Given
            var testItem = CreateAndRetrieveTestItem();

            testItem.Value = $"{DateTime.Now.ToFileTime()}updatedTest";

            //When
            var response = GetController().Post(testItem);

            //Then
            var updatedItem = ApiControllerTestHelper.GetContentAsync <CompositeKeyTest>(response);

            EqualityHelper.PropertyValuesAreEqual(updatedItem, testItem);
        }
        public void CreateCompositeSuccessfullyTest()
        {
            //Given
            var controller = GetController();
            var request    = GetTestObject();

            //When
            var response = controller.Post(request);

            //Then
            var content = response as System.Web.OData.Results.CreatedODataResult <CompositeKeyTest>;

            Assert.IsInstanceOf(typeof(System.Web.OData.Results.CreatedODataResult <CompositeKeyTest>), response);
            Assert.IsNotNull(content, "Item not returned");
            EqualityHelper.PropertyValuesAreEqual(content.Entity, request, new[] { "LastModified", "ModifiedBy" });
        }
        public async Task AddItemTestAsync()
        {
            //Given
            var repository = new EfCoreAsyncAccountRepository(_databaseFactory);

            using (var efCoreAsyncUnitOfWork = new EfCoreAsyncUnitOfWork <SharedLibraryContext>(_databaseFactory))
            {
                //When
                var testAccount  = AccountEntityHelper.CreateEfTestAccount();
                var addedAccount = await repository.SaveAsync(testAccount).ConfigureAwait(true);

                await efCoreAsyncUnitOfWork.CommitAsync().ConfigureAwait(true);

                //Then
                Assert.AreNotEqual(addedAccount.AccountId, 0, "The account ID was not updated.");
                EqualityHelper.PropertyValuesAreEqual(addedAccount, testAccount, new[] { "AccountID" });
            }
        }
        public async Task RetrieveItemByIdTestAsync()
        {
            //Given
            var repository = new EfCoreAsyncAccountRepository(_databaseFactory);

            using (var efCoreAsyncUnitOfWork = new EfCoreAsyncUnitOfWork <SharedLibraryContext>(_databaseFactory))
            {
                var addedAccount = await repository.SaveAsync(AccountEntityHelper.CreateEfTestAccount()).ConfigureAwait(true);

                await efCoreAsyncUnitOfWork.CommitAsync().ConfigureAwait(true);

                //When
                var retrievedItem = await repository.GetByIdAsync(addedAccount.AccountId).ConfigureAwait(true);

                //Then
                EqualityHelper.PropertyValuesAreEqual(retrievedItem, addedAccount);
            }
        }
示例#10
0
        private static void TestGetItemByID <TEntity, TKey>(
            Func <IQueryable <TEntity> > datafFunc,
            Func <IQueryable <TEntity>, ODataReadOnlyControllerBase <TEntity, TKey, FakeDbContext> > controllerFunc,
            Func <IQueryable <TEntity>, TEntity> getFirstItemFunc,
            Func <TEntity, TKey> getPrimaryKeyFunc) where TEntity : class
        {
            //Given:
            var data       = datafFunc();
            var controller = controllerFunc(data);
            var itemToFind = getFirstItemFunc(data);
            var primaryKey = getPrimaryKeyFunc(itemToFind);

            //When:
            var result = controller.Get(primaryKey).Queryable.First();

            //Then:
            EqualityHelper.PropertyValuesAreEqual(result, itemToFind);
        }
        public void RetrieveItemByIdTest()
        {
            //Given
            var databseFactory =
                new EfCoreDatabaseFactoryBase <SharedLibraryContext>("SharedLibraryContext");
            var repository = new EfCoreAccountRepository(databseFactory);

            using (var efCoreUnitOfWork = new EfCoreUnitOfWork <SharedLibraryContext>(databseFactory))
            {
                var addedAccount = repository.Save(AccountEntityHelper.CreateEfTestAccount());
                efCoreUnitOfWork.Commit();

                //When
                var retrievedItem = repository.GetById(addedAccount.AccountId);

                //Then
                EqualityHelper.PropertyValuesAreEqual(retrievedItem, addedAccount);
            }
        }
        public void AddItemTest()
        {
            //Given
            var databseFactory =
                new EfCoreDatabaseFactoryBase <SharedLibraryContext>("SharedLibraryContext");
            var repository = new EfCoreAccountRepository(databseFactory);

            using (var efCoreUnitOfWork = new EfCoreUnitOfWork <SharedLibraryContext>(databseFactory))
            {
                //When
                var testAccount  = AccountEntityHelper.CreateEfTestAccount();
                var addedAccount = repository.Save(testAccount);
                efCoreUnitOfWork.Commit();

                //Then
                Assert.AreNotEqual(addedAccount.AccountId, 0, "The account ID was not updated.");
                EqualityHelper.PropertyValuesAreEqual(addedAccount, testAccount, new[] { "AccountID" });
            }
        }
        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 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 void GetAutoCompleteItemsTest()
        {
            //Given
            var databseFactory =
                new EfCoreDatabaseFactoryBase <SharedLibraryContext>("SharedLibraryContext");

            using (var efCoreUnitOfWork = new EfCoreUnitOfWork <SharedLibraryContext>(databseFactory))
            {
                var repository  = new EfCoreAccountRepository(databseFactory);
                var reference   = "TestReference";
                var listOfItems = GetItemsWithTwoItemsContainingTestReference(reference);
                repository.AddRange(listOfItems);
                efCoreUnitOfWork.Commit();

                //When
                var item = repository.GetAutoCompleteItems(x => x.CompanyName.Contains(reference), 1);

                //Then
                EqualityHelper.PropertyValuesAreEqual(item.First(), listOfItems[0], new[] { "AccountID", "LastModified", "LastModifiedBy", "Contacts" });
            }
        }
        public void GetWithWhereClauseSuccessTest()
        {
            //Given
            var databseFactory =
                new EfCoreDatabaseFactoryBase <SharedLibraryContext>("SharedLibraryContext");

            using (var efCoreUnitOfWork = new EfCoreUnitOfWork <SharedLibraryContext>(databseFactory))
            {
                var repository  = new EfCoreAccountRepository(databseFactory);
                var listOfItems = AccountEntityHelper.CreateEfCoreTestAccounts(3);
                listOfItems[2].CompanyName = "TestReferenceOtherValue";
                repository.AddRange(listOfItems);
                efCoreUnitOfWork.Commit();

                //When
                var items = repository.Get(x => x.CompanyName.Contains("TestReference"));

                //Then
                EqualityHelper.PropertyValuesAreEqual(items, listOfItems[2],
                                                      new[] { "AccountID", "LastModified", "LastModifiedBy", "Contacts" });
            }
        }