Esempio n. 1
0
		public void Constructor_IsPassedUnsortedResultSet_GetResultSetReturnsSorted()
		{
			ResultSetCache<TestItem> resultSetCacheUnderTest = new ResultSetCache<TestItem>(_repository, _sortDefinitions, _results, _queryToCache);
			Assert.AreEqual(3, resultSetCacheUnderTest.GetResultSet().Count);
			Assert.AreEqual("Item 0", resultSetCacheUnderTest.GetResultSet()[0]["StoredString"]);
			Assert.AreEqual("Item 2", resultSetCacheUnderTest.GetResultSet()[1]["StoredString"]);
			Assert.AreEqual("Item 3", resultSetCacheUnderTest.GetResultSet()[2]["StoredString"]);
		}
Esempio n. 2
0
        public void Constructor_IsPassedUnsortedResultSet_GetResultSetReturnsSorted()
        {
            ResultSetCache <PalasoTestItem> resultSetCacheUnderTest = new ResultSetCache <PalasoTestItem>(_dataMapper, _sortDefinitions, _results, _queryToCache);

            Assert.AreEqual(3, resultSetCacheUnderTest.GetResultSet().Count);
            Assert.AreEqual("Item 0", resultSetCacheUnderTest.GetResultSet()[0]["StoredString"]);
            Assert.AreEqual("Item 2", resultSetCacheUnderTest.GetResultSet()[1]["StoredString"]);
            Assert.AreEqual("Item 3", resultSetCacheUnderTest.GetResultSet()[2]["StoredString"]);
        }
Esempio n. 3
0
        public void UpdateItemInCache_ItemHasNotChanged_ResultSetIsNotChanged()
        {
            PalasoTestItem unmodifiedItem = dataMapper.CreateItem();

            unmodifiedItem.StoredString = "Item 6";
            dataMapper.SaveItem(unmodifiedItem);

            //_results = dataMapper.GetItemsMatching(_queryToCache);
            ResultSetCache <PalasoTestItem> resultSetCacheUnderTest = new ResultSetCache <PalasoTestItem>(dataMapper, _sortDefinitions, _results, _queryToCache);

            QueryAdapter <PalasoTestItem> secondQueryToCache = new QueryAdapter <PalasoTestItem>();

            secondQueryToCache.In("Child").Show("StoredString");
            ResultSet <PalasoTestItem> results = dataMapper.GetItemsMatching(secondQueryToCache);

            resultSetCacheUnderTest.Add(results, secondQueryToCache);

            resultSetCacheUnderTest.UpdateItemInCache(unmodifiedItem);

            //Would be a better test but ResultSets don't support equality checks
            //Assert.AreEqual(resultsBeforeUpdate, resultsAfterUpdate);

            Assert.AreEqual(8, resultSetCacheUnderTest.GetResultSet().Count);
            Assert.AreEqual(null, resultSetCacheUnderTest.GetResultSet()[0]["StoredString"]);
            Assert.AreEqual("Item 0", resultSetCacheUnderTest.GetResultSet()[1]["StoredString"]);
            Assert.AreEqual("Item 1", resultSetCacheUnderTest.GetResultSet()[2]["StoredString"]);
            Assert.AreEqual("Item 2", resultSetCacheUnderTest.GetResultSet()[3]["StoredString"]);
            Assert.AreEqual("Item 3", resultSetCacheUnderTest.GetResultSet()[4]["StoredString"]);
            Assert.AreEqual("Item 4", resultSetCacheUnderTest.GetResultSet()[5]["StoredString"]);
            Assert.AreEqual("Item 5", resultSetCacheUnderTest.GetResultSet()[6]["StoredString"]);
            Assert.AreEqual("Item 6", resultSetCacheUnderTest.GetResultSet()[7]["StoredString"]);
        }
Esempio n. 4
0
        public void UpdateItemInCache_ItemExists_ResultSetIsUpdatedAndSorted()
        {
            PalasoTestItem itemToModify = dataMapper.CreateItem();

            itemToModify.StoredString = "Item 6";
            dataMapper.SaveItem(itemToModify);

            ResultSetCache <PalasoTestItem> resultSetCacheUnderTest = new ResultSetCache <PalasoTestItem>(dataMapper, _sortDefinitions, _results, _queryToCache);

            QueryAdapter <PalasoTestItem> secondQueryToCache = new QueryAdapter <PalasoTestItem>();

            secondQueryToCache.In("Child").Show("StoredString");
            ResultSet <PalasoTestItem> results = dataMapper.GetItemsMatching(secondQueryToCache);

            resultSetCacheUnderTest.Add(results, secondQueryToCache);

            itemToModify.StoredString = "Item 7";
            dataMapper.SaveItem(itemToModify);
            resultSetCacheUnderTest.UpdateItemInCache(itemToModify);

            Assert.AreEqual(8, resultSetCacheUnderTest.GetResultSet().Count);
            Assert.AreEqual(null, resultSetCacheUnderTest.GetResultSet()[0]["StoredString"]);
            Assert.AreEqual("Item 0", resultSetCacheUnderTest.GetResultSet()[1]["StoredString"]);
            Assert.AreEqual("Item 1", resultSetCacheUnderTest.GetResultSet()[2]["StoredString"]);
            Assert.AreEqual("Item 2", resultSetCacheUnderTest.GetResultSet()[3]["StoredString"]);
            Assert.AreEqual("Item 3", resultSetCacheUnderTest.GetResultSet()[4]["StoredString"]);
            Assert.AreEqual("Item 4", resultSetCacheUnderTest.GetResultSet()[5]["StoredString"]);
            Assert.AreEqual("Item 5", resultSetCacheUnderTest.GetResultSet()[6]["StoredString"]);
            Assert.AreEqual("Item 7", resultSetCacheUnderTest.GetResultSet()[7]["StoredString"]);
        }
Esempio n. 5
0
        public void UpdateItemInCache_ItemDoesNotExistInCacheButDoesInRepository_ItemIsAddedToResultSetAndSortedCorrectly()
        {
            ResultSetCache <PalasoTestItem> resultSetCacheUnderTest = new ResultSetCache <PalasoTestItem>(dataMapper, _sortDefinitions, _results, _queryToCache);

            QueryAdapter <PalasoTestItem> secondQueryToCache = new QueryAdapter <PalasoTestItem>();

            secondQueryToCache.In("Child").Show("StoredString");
            ResultSet <PalasoTestItem> results = dataMapper.GetItemsMatching(secondQueryToCache);

            resultSetCacheUnderTest.Add(results, secondQueryToCache);

            PalasoTestItem itemCreatedAfterCache = dataMapper.CreateItem();

            itemCreatedAfterCache.StoredString = "Item 6";
            dataMapper.SaveItem(itemCreatedAfterCache);
            resultSetCacheUnderTest.UpdateItemInCache(itemCreatedAfterCache);

            Assert.AreEqual(8, resultSetCacheUnderTest.GetResultSet().Count);
            Assert.AreEqual(null, resultSetCacheUnderTest.GetResultSet()[0]["StoredString"]);
            Assert.AreEqual("Item 0", resultSetCacheUnderTest.GetResultSet()[1]["StoredString"]);
            Assert.AreEqual("Item 1", resultSetCacheUnderTest.GetResultSet()[2]["StoredString"]);
            Assert.AreEqual("Item 2", resultSetCacheUnderTest.GetResultSet()[3]["StoredString"]);
            Assert.AreEqual("Item 3", resultSetCacheUnderTest.GetResultSet()[4]["StoredString"]);
            Assert.AreEqual("Item 4", resultSetCacheUnderTest.GetResultSet()[5]["StoredString"]);
            Assert.AreEqual("Item 5", resultSetCacheUnderTest.GetResultSet()[6]["StoredString"]);
            Assert.AreEqual("Item 6", resultSetCacheUnderTest.GetResultSet()[7]["StoredString"]);
        }
Esempio n. 6
0
        public void MultipleQueries_QueriedFieldsAreIdentical_ReturnsOnlyOneRecordToken()
        {
            ResultSetCache <PalasoTestItem> resultSetCacheUnderTest = new ResultSetCache <PalasoTestItem>(dataMapper, _sortDefinitions, _results, _queryToCache);

            QueryAdapter <PalasoTestItem> secondQueryToCache = new QueryAdapter <PalasoTestItem>();

            secondQueryToCache.In("Child").Show("StoredString");
            ResultSet <PalasoTestItem> results = dataMapper.GetItemsMatching(secondQueryToCache);

            resultSetCacheUnderTest.Add(results, secondQueryToCache);

            PalasoTestItem itemCreatedAfterCache = dataMapper.CreateItem();

            itemCreatedAfterCache.StoredString       = "Item 6";
            itemCreatedAfterCache.Child.StoredString = "Item 6";
            dataMapper.SaveItem(itemCreatedAfterCache);
            resultSetCacheUnderTest.UpdateItemInCache(itemCreatedAfterCache);

            Assert.AreEqual(7, resultSetCacheUnderTest.GetResultSet().Count);
            Assert.AreEqual("Item 0", resultSetCacheUnderTest.GetResultSet()[0]["StoredString"]);
            Assert.AreEqual("Item 1", resultSetCacheUnderTest.GetResultSet()[1]["StoredString"]);
            Assert.AreEqual("Item 2", resultSetCacheUnderTest.GetResultSet()[2]["StoredString"]);
            Assert.AreEqual("Item 3", resultSetCacheUnderTest.GetResultSet()[3]["StoredString"]);
            Assert.AreEqual("Item 4", resultSetCacheUnderTest.GetResultSet()[4]["StoredString"]);
            Assert.AreEqual("Item 5", resultSetCacheUnderTest.GetResultSet()[5]["StoredString"]);
            Assert.AreEqual("Item 6", resultSetCacheUnderTest.GetResultSet()[6]["StoredString"]);
        }
Esempio n. 7
0
        public void DeleteAllItemsFromCache_AllItemsAreDeleted()
        {
            ResultSetCache <PalasoTestItem> resultSetCacheUnderTest = new ResultSetCache <PalasoTestItem>(dataMapper, _sortDefinitions, _results, _queryToCache);

            resultSetCacheUnderTest.DeleteAllItemsFromCache();
            Assert.AreEqual(0, resultSetCacheUnderTest.GetResultSet().Count);
        }
Esempio n. 8
0
        public void UpdateItemInCache_ItemDoesNotExistInCacheButDoesInRepository_ItemIsAddedToResultSetAndSortedCorrectly()
        {
            ResultSetCache <PalasoTestItem> resultSetCacheUnderTest = new ResultSetCache <PalasoTestItem>(_dataMapper, _sortDefinitions, _results, _queryToCache);

            PalasoTestItem itemCreatedAfterCache = _dataMapper.CreateItem();

            itemCreatedAfterCache.StoredString = "Item 1";
            _dataMapper.SaveItem(itemCreatedAfterCache);
            resultSetCacheUnderTest.UpdateItemInCache(itemCreatedAfterCache);

            Assert.AreEqual(4, resultSetCacheUnderTest.GetResultSet().Count);
            Assert.AreEqual("Item 0", resultSetCacheUnderTest.GetResultSet()[0]["StoredString"]);
            Assert.AreEqual("Item 1", resultSetCacheUnderTest.GetResultSet()[1]["StoredString"]);
            Assert.AreEqual("Item 2", resultSetCacheUnderTest.GetResultSet()[2]["StoredString"]);
            Assert.AreEqual("Item 3", resultSetCacheUnderTest.GetResultSet()[3]["StoredString"]);
        }
Esempio n. 9
0
        public void DeleteItemFromCacheById_Id_ItemIsNoLongerInResultSet()
        {
            PalasoTestItem itemToDelete = dataMapper.CreateItem();

            itemToDelete.StoredString = "Item 6";
            dataMapper.SaveItem(itemToDelete);

            //_results = dataMapper.GetItemsMatching(_queryToCache);
            ResultSetCache <PalasoTestItem> resultSetCacheUnderTest = new ResultSetCache <PalasoTestItem>(dataMapper, _sortDefinitions, _results, _queryToCache);

            QueryAdapter <PalasoTestItem> secondQueryToCache = new QueryAdapter <PalasoTestItem>();

            secondQueryToCache.In("Child").Show("StoredString");
            ResultSet <PalasoTestItem> results = dataMapper.GetItemsMatching(secondQueryToCache);

            resultSetCacheUnderTest.Add(results, secondQueryToCache);

            resultSetCacheUnderTest.DeleteItemFromCache(itemToDelete);

            //Would be a better test but ResultSets don't support equality checks
            //Assert.AreEqual(resultsBeforeUpdate, resultsAfterUpdate);

            Assert.AreEqual(6, resultSetCacheUnderTest.GetResultSet().Count);
            Assert.AreEqual("Item 0", resultSetCacheUnderTest.GetResultSet()[0]["StoredString"]);
            Assert.AreEqual("Item 1", resultSetCacheUnderTest.GetResultSet()[1]["StoredString"]);
            Assert.AreEqual("Item 2", resultSetCacheUnderTest.GetResultSet()[2]["StoredString"]);
            Assert.AreEqual("Item 3", resultSetCacheUnderTest.GetResultSet()[3]["StoredString"]);
            Assert.AreEqual("Item 4", resultSetCacheUnderTest.GetResultSet()[4]["StoredString"]);
            Assert.AreEqual("Item 5", resultSetCacheUnderTest.GetResultSet()[5]["StoredString"]);
        }
Esempio n. 10
0
		public void Constructor_SortDefinitionNull_SortedByRepositoryId()
		{
			ResultSetCache<TestItem> resultSetCacheUnderTest = new ResultSetCache<TestItem>(_repository, null, _results, _queryToCache);
			ResultSet<TestItem> resultSet = resultSetCacheUnderTest.GetResultSet();
			Assert.AreEqual(3, resultSet.Count);
			for (int recordTokenNum = 0; recordTokenNum < (resultSet.Count - 1); recordTokenNum++)
			{
				Assert.IsTrue(resultSet[recordTokenNum].Id.CompareTo(resultSet[recordTokenNum + 1].Id) < 0);
			}
		}
Esempio n. 11
0
        public void Constructor_SortDefinitionNull_SortedByRepositoryId()
        {
            ResultSetCache <PalasoTestItem> resultSetCacheUnderTest = new ResultSetCache <PalasoTestItem>(_dataMapper, null, _results, _queryToCache);
            ResultSet <PalasoTestItem>      resultSet = resultSetCacheUnderTest.GetResultSet();

            Assert.AreEqual(3, resultSet.Count);
            for (int recordTokenNum = 0; recordTokenNum < (resultSet.Count - 1); recordTokenNum++)
            {
                Assert.IsTrue(resultSet[recordTokenNum].Id.CompareTo(resultSet[recordTokenNum + 1].Id) < 0);
            }
        }
Esempio n. 12
0
        public void DeleteItemFromCacheById_Id_ItemIsNoLongerInResultSet()
        {
            PalasoTestItem itemToDelete = _dataMapper.CreateItem();

            itemToDelete.StoredString = "Item 1";
            _dataMapper.SaveItem(itemToDelete);

            _results = _dataMapper.GetItemsMatching(_queryToCache);
            ResultSetCache <PalasoTestItem> resultSetCacheUnderTest = new ResultSetCache <PalasoTestItem>(_dataMapper, _sortDefinitions, _results, _queryToCache);

            resultSetCacheUnderTest.DeleteItemFromCache(itemToDelete);

            //Would be a better test but ResultSets don't support equality checks
            //Assert.AreEqual(resultsBeforeUpdate, resultsAfterUpdate);

            Assert.AreEqual(3, resultSetCacheUnderTest.GetResultSet().Count);
            Assert.AreEqual("Item 0", resultSetCacheUnderTest.GetResultSet()[0]["StoredString"]);
            Assert.AreEqual("Item 2", resultSetCacheUnderTest.GetResultSet()[1]["StoredString"]);
            Assert.AreEqual("Item 3", resultSetCacheUnderTest.GetResultSet()[2]["StoredString"]);
        }
Esempio n. 13
0
        public void UpdateItemInCache_ItemExists_ResultSetIsUpdatedAndSorted()
        {
            PalasoTestItem itemToModify = _dataMapper.CreateItem();

            itemToModify.StoredString = "Item 5";
            _dataMapper.SaveItem(itemToModify);

            _results = _dataMapper.GetItemsMatching(_queryToCache);
            ResultSetCache <PalasoTestItem> resultSetCacheUnderTest = new ResultSetCache <PalasoTestItem>(_dataMapper, _sortDefinitions, _results, _queryToCache);

            itemToModify.StoredString = "Item 1";
            _dataMapper.SaveItem(itemToModify);
            resultSetCacheUnderTest.UpdateItemInCache(itemToModify);

            Assert.AreEqual(4, resultSetCacheUnderTest.GetResultSet().Count);
            Assert.AreEqual("Item 0", resultSetCacheUnderTest.GetResultSet()[0]["StoredString"]);
            Assert.AreEqual("Item 1", resultSetCacheUnderTest.GetResultSet()[1]["StoredString"]);
            Assert.AreEqual("Item 2", resultSetCacheUnderTest.GetResultSet()[2]["StoredString"]);
            Assert.AreEqual("Item 3", resultSetCacheUnderTest.GetResultSet()[3]["StoredString"]);
        }
Esempio n. 14
0
        public void UpdateItemInCache_ItemHasNotChanged_ResultSetIsNotChanged()
        {
            PalasoTestItem unmodifiedItem = _dataMapper.CreateItem();

            unmodifiedItem.StoredString = "Item 1";
            _dataMapper.SaveItem(unmodifiedItem);

            _results = _dataMapper.GetItemsMatching(_queryToCache);
            ResultSetCache <PalasoTestItem> resultSetCacheUnderTest = new ResultSetCache <PalasoTestItem>(_dataMapper, _sortDefinitions, _results, _queryToCache);

            resultSetCacheUnderTest.UpdateItemInCache(unmodifiedItem);

            //Would be a better test but ResultSets don't support equality checks
            //Assert.AreEqual(resultsBeforeUpdate, resultsAfterUpdate);

            Assert.AreEqual(4, resultSetCacheUnderTest.GetResultSet().Count);
            Assert.AreEqual("Item 0", resultSetCacheUnderTest.GetResultSet()[0]["StoredString"]);
            Assert.AreEqual("Item 1", resultSetCacheUnderTest.GetResultSet()[1]["StoredString"]);
            Assert.AreEqual("Item 2", resultSetCacheUnderTest.GetResultSet()[2]["StoredString"]);
            Assert.AreEqual("Item 3", resultSetCacheUnderTest.GetResultSet()[3]["StoredString"]);
        }
Esempio n. 15
0
        public void DeleteAllItemsFromCache_AllItemsAreDeleted()
        {
            ResultSetCache <PalasoTestItem> resultSetCacheUnderTest = new ResultSetCache <PalasoTestItem>(dataMapper, _sortDefinitions, _results, _queryToCache);

            QueryAdapter <PalasoTestItem> secondQueryToCache = new QueryAdapter <PalasoTestItem>();

            secondQueryToCache.In("Child").Show("StoredString");
            ResultSet <PalasoTestItem> results = dataMapper.GetItemsMatching(secondQueryToCache);

            resultSetCacheUnderTest.Add(results, secondQueryToCache);

            resultSetCacheUnderTest.DeleteAllItemsFromCache();
            Assert.AreEqual(0, resultSetCacheUnderTest.GetResultSet().Count);
        }
Esempio n. 16
0
        public void UpdateItemInCache_ItemExists_ResultSetIsUpdatedAndSorted()
        {
            PalasoTestItem itemToModify = dataMapper.CreateItem();

            itemToModify.StoredList = PopulateListWith("Change Me!", "Me 2!");
            dataMapper.SaveItem(itemToModify);

            _results = dataMapper.GetItemsMatching(_queryToCache);
            ResultSetCache <PalasoTestItem> resultSetCacheUnderTest = new ResultSetCache <PalasoTestItem>(dataMapper, _sortDefinitions, _results, _queryToCache);

            itemToModify.StoredList = PopulateListWith("Item 5", "Item 4");
            dataMapper.SaveItem(itemToModify);
            resultSetCacheUnderTest.UpdateItemInCache(itemToModify);

            Assert.AreEqual(6, resultSetCacheUnderTest.GetResultSet().Count);
            Assert.AreEqual("Item 0", resultSetCacheUnderTest.GetResultSet()[0]["StoredList"]);
            Assert.AreEqual("Item 1", resultSetCacheUnderTest.GetResultSet()[1]["StoredList"]);
            Assert.AreEqual("Item 2", resultSetCacheUnderTest.GetResultSet()[2]["StoredList"]);
            Assert.AreEqual("Item 3", resultSetCacheUnderTest.GetResultSet()[3]["StoredList"]);
            Assert.AreEqual("Item 4", resultSetCacheUnderTest.GetResultSet()[4]["StoredList"]);
            Assert.AreEqual("Item 5", resultSetCacheUnderTest.GetResultSet()[5]["StoredList"]);
        }
Esempio n. 17
0
		public void DeleteItemFromCacheById_Id_ItemIsNoLongerInResultSet()
		{
			TestItem itemToDelete = _repository.CreateItem();
			itemToDelete.StoredString = "Item 6";
			_repository.SaveItem(itemToDelete);

			//_results = _repository.GetItemsMatching(_queryToCache);
			ResultSetCache<TestItem> resultSetCacheUnderTest = new ResultSetCache<TestItem>(_repository, _sortDefinitions, _results, _queryToCache);

			QueryAdapter<TestItem> secondQueryToCache = new QueryAdapter<TestItem>();

			secondQueryToCache.In("Child").Show("StoredString");
			ResultSet<TestItem> results = _repository.GetItemsMatching(secondQueryToCache);

			resultSetCacheUnderTest.Add(results, secondQueryToCache);

			resultSetCacheUnderTest.DeleteItemFromCache(itemToDelete);

			//Would be a better test but ResultSets don't support equality checks
			//Assert.AreEqual(resultsBeforeUpdate, resultsAfterUpdate);

			Assert.AreEqual(6, resultSetCacheUnderTest.GetResultSet().Count);
			Assert.AreEqual("Item 0", resultSetCacheUnderTest.GetResultSet()[0]["StoredString"]);
			Assert.AreEqual("Item 1", resultSetCacheUnderTest.GetResultSet()[1]["StoredString"]);
			Assert.AreEqual("Item 2", resultSetCacheUnderTest.GetResultSet()[2]["StoredString"]);
			Assert.AreEqual("Item 3", resultSetCacheUnderTest.GetResultSet()[3]["StoredString"]);
			Assert.AreEqual("Item 4", resultSetCacheUnderTest.GetResultSet()[4]["StoredString"]);
			Assert.AreEqual("Item 5", resultSetCacheUnderTest.GetResultSet()[5]["StoredString"]);
		}
Esempio n. 18
0
		public void UpdateItemInCache_ItemExists_ResultSetIsUpdatedAndSorted()
		{
			TestItem itemToModify = _repository.CreateItem();
			itemToModify.StoredString = "Item 6";
			_repository.SaveItem(itemToModify);

			ResultSetCache<TestItem> resultSetCacheUnderTest = new ResultSetCache<TestItem>(_repository, _sortDefinitions, _results, _queryToCache);

			QueryAdapter<TestItem> secondQueryToCache = new QueryAdapter<TestItem>();

			secondQueryToCache.In("Child").Show("StoredString");
			ResultSet<TestItem> results = _repository.GetItemsMatching(secondQueryToCache);

			resultSetCacheUnderTest.Add(results, secondQueryToCache);

			itemToModify.StoredString = "Item 7";
			_repository.SaveItem(itemToModify);
			resultSetCacheUnderTest.UpdateItemInCache(itemToModify);

			Assert.AreEqual(8, resultSetCacheUnderTest.GetResultSet().Count);
			Assert.AreEqual(null, resultSetCacheUnderTest.GetResultSet()[0]["StoredString"]);
			Assert.AreEqual("Item 0", resultSetCacheUnderTest.GetResultSet()[1]["StoredString"]);
			Assert.AreEqual("Item 1", resultSetCacheUnderTest.GetResultSet()[2]["StoredString"]);
			Assert.AreEqual("Item 2", resultSetCacheUnderTest.GetResultSet()[3]["StoredString"]);
			Assert.AreEqual("Item 3", resultSetCacheUnderTest.GetResultSet()[4]["StoredString"]);
			Assert.AreEqual("Item 4", resultSetCacheUnderTest.GetResultSet()[5]["StoredString"]);
			Assert.AreEqual("Item 5", resultSetCacheUnderTest.GetResultSet()[6]["StoredString"]);
			Assert.AreEqual("Item 7", resultSetCacheUnderTest.GetResultSet()[7]["StoredString"]);
		}
Esempio n. 19
0
		public void UpdateItemInCache_ItemHasNotChanged_ResultSetIsNotChanged()
		{
			TestItem unmodifiedItem = _repository.CreateItem();
			unmodifiedItem.StoredString = "Item 6";
			_repository.SaveItem(unmodifiedItem);

			//_results = _repository.GetItemsMatching(_queryToCache);
			ResultSetCache<TestItem> resultSetCacheUnderTest = new ResultSetCache<TestItem>(_repository, _sortDefinitions, _results, _queryToCache);

			QueryAdapter<TestItem> secondQueryToCache = new QueryAdapter<TestItem>();

			secondQueryToCache.In("Child").Show("StoredString");
			ResultSet<TestItem> results = _repository.GetItemsMatching(secondQueryToCache);

			resultSetCacheUnderTest.Add(results, secondQueryToCache);

			resultSetCacheUnderTest.UpdateItemInCache(unmodifiedItem);

			//Would be a better test but ResultSets don't support equality checks
			//Assert.AreEqual(resultsBeforeUpdate, resultsAfterUpdate);

			Assert.AreEqual(8, resultSetCacheUnderTest.GetResultSet().Count);
			Assert.AreEqual(null, resultSetCacheUnderTest.GetResultSet()[0]["StoredString"]);
			Assert.AreEqual("Item 0", resultSetCacheUnderTest.GetResultSet()[1]["StoredString"]);
			Assert.AreEqual("Item 1", resultSetCacheUnderTest.GetResultSet()[2]["StoredString"]);
			Assert.AreEqual("Item 2", resultSetCacheUnderTest.GetResultSet()[3]["StoredString"]);
			Assert.AreEqual("Item 3", resultSetCacheUnderTest.GetResultSet()[4]["StoredString"]);
			Assert.AreEqual("Item 4", resultSetCacheUnderTest.GetResultSet()[5]["StoredString"]);
			Assert.AreEqual("Item 5", resultSetCacheUnderTest.GetResultSet()[6]["StoredString"]);
			Assert.AreEqual("Item 6", resultSetCacheUnderTest.GetResultSet()[7]["StoredString"]);
		}
Esempio n. 20
0
		public void MultipleQueries_QueriedFieldsAreIdentical_ReturnsOnlyOneRecordToken()
		{
			ResultSetCache<TestItem> resultSetCacheUnderTest = new ResultSetCache<TestItem>(_repository, _sortDefinitions, _results, _queryToCache);

			QueryAdapter<TestItem> secondQueryToCache = new QueryAdapter<TestItem>();

			secondQueryToCache.In("Child").Show("StoredString");
			ResultSet<TestItem> results = _repository.GetItemsMatching(secondQueryToCache);

			resultSetCacheUnderTest.Add(results, secondQueryToCache);

			TestItem itemCreatedAfterCache = _repository.CreateItem();
			itemCreatedAfterCache.StoredString = "Item 6";
			itemCreatedAfterCache.Child.StoredString = "Item 6";
			_repository.SaveItem(itemCreatedAfterCache);
			resultSetCacheUnderTest.UpdateItemInCache(itemCreatedAfterCache);

			Assert.AreEqual(7, resultSetCacheUnderTest.GetResultSet().Count);
			Assert.AreEqual("Item 0", resultSetCacheUnderTest.GetResultSet()[0]["StoredString"]);
			Assert.AreEqual("Item 1", resultSetCacheUnderTest.GetResultSet()[1]["StoredString"]);
			Assert.AreEqual("Item 2", resultSetCacheUnderTest.GetResultSet()[2]["StoredString"]);
			Assert.AreEqual("Item 3", resultSetCacheUnderTest.GetResultSet()[3]["StoredString"]);
			Assert.AreEqual("Item 4", resultSetCacheUnderTest.GetResultSet()[4]["StoredString"]);
			Assert.AreEqual("Item 5", resultSetCacheUnderTest.GetResultSet()[5]["StoredString"]);
			Assert.AreEqual("Item 6", resultSetCacheUnderTest.GetResultSet()[6]["StoredString"]);
		}
Esempio n. 21
0
		public void UpdateItemInCache_ItemDoesNotExistInCacheButDoesInRepository_ItemIsAddedToResultSetAndSortedCorrectly()
		{
			ResultSetCache<TestItem> resultSetCacheUnderTest = new ResultSetCache<TestItem>(_repository, _sortDefinitions, _results, _queryToCache);

			QueryAdapter<TestItem> secondQueryToCache = new QueryAdapter<TestItem>();

			secondQueryToCache.In("Child").Show("StoredString");
			ResultSet<TestItem> results = _repository.GetItemsMatching(secondQueryToCache);

			resultSetCacheUnderTest.Add(results, secondQueryToCache);

			TestItem itemCreatedAfterCache = _repository.CreateItem();
			itemCreatedAfterCache.StoredString = "Item 6";
			_repository.SaveItem(itemCreatedAfterCache);
			resultSetCacheUnderTest.UpdateItemInCache(itemCreatedAfterCache);

			Assert.AreEqual(8, resultSetCacheUnderTest.GetResultSet().Count);
			Assert.AreEqual(null, resultSetCacheUnderTest.GetResultSet()[0]["StoredString"]);
			Assert.AreEqual("Item 0", resultSetCacheUnderTest.GetResultSet()[1]["StoredString"]);
			Assert.AreEqual("Item 1", resultSetCacheUnderTest.GetResultSet()[2]["StoredString"]);
			Assert.AreEqual("Item 2", resultSetCacheUnderTest.GetResultSet()[3]["StoredString"]);
			Assert.AreEqual("Item 3", resultSetCacheUnderTest.GetResultSet()[4]["StoredString"]);
			Assert.AreEqual("Item 4", resultSetCacheUnderTest.GetResultSet()[5]["StoredString"]);
			Assert.AreEqual("Item 5", resultSetCacheUnderTest.GetResultSet()[6]["StoredString"]);
			Assert.AreEqual("Item 6", resultSetCacheUnderTest.GetResultSet()[7]["StoredString"]);
		}
Esempio n. 22
0
		public void DeleteAllItemsFromCache_AllItemsAreDeleted()
		{
			ResultSetCache<TestItem> resultSetCacheUnderTest = new ResultSetCache<TestItem>(_repository, _sortDefinitions, _results, _queryToCache);

			QueryAdapter<TestItem> secondQueryToCache = new QueryAdapter<TestItem>();
			secondQueryToCache.In("Child").Show("StoredString");
			ResultSet<TestItem> results = _repository.GetItemsMatching(secondQueryToCache);

			resultSetCacheUnderTest.Add(results, secondQueryToCache);

			resultSetCacheUnderTest.DeleteAllItemsFromCache();
			Assert.AreEqual(0, resultSetCacheUnderTest.GetResultSet().Count);
		}
Esempio n. 23
0
		public void DeleteAllItemsFromCache_AllItemsAreDeleted()
		{
			ResultSetCache<TestItem> resultSetCacheUnderTest = new ResultSetCache<TestItem>(_repository, _sortDefinitions, _results, _queryToCache);
			resultSetCacheUnderTest.DeleteAllItemsFromCache();
			Assert.AreEqual(0, resultSetCacheUnderTest.GetResultSet().Count);
		}
Esempio n. 24
0
		public void DeleteItemFromCacheById_Item_ItemIsNoLongerInResultSet()
		{
			TestItem itemToDelete = _repository.CreateItem();
			itemToDelete.StoredList = PopulateListWith("Item 5", "Item 4");
			_repository.SaveItem(itemToDelete);

			_results = _repository.GetItemsMatching(_queryToCache);
			ResultSetCache<TestItem> resultSetCacheUnderTest = new ResultSetCache<TestItem>(_repository, _sortDefinitions, _results, _queryToCache);
			resultSetCacheUnderTest.DeleteItemFromCache(_repository.GetId(itemToDelete));

			//Would be a better test but ResultSets don't support equality checks
			//Assert.AreEqual(resultsBeforeUpdate, resultsAfterUpdate);

			Assert.AreEqual(4, resultSetCacheUnderTest.GetResultSet().Count);
			Assert.AreEqual("Item 0", resultSetCacheUnderTest.GetResultSet()[0]["StoredList"]);
			Assert.AreEqual("Item 1", resultSetCacheUnderTest.GetResultSet()[1]["StoredList"]);
			Assert.AreEqual("Item 2", resultSetCacheUnderTest.GetResultSet()[2]["StoredList"]);
			Assert.AreEqual("Item 3", resultSetCacheUnderTest.GetResultSet()[3]["StoredList"]);
		}
Esempio n. 25
0
		public void UpdateItemInCache_ItemHasNotChanged_ResultSetIsNotChanged()
		{
			TestItem unmodifiedItem = _repository.CreateItem();
			unmodifiedItem.StoredList = PopulateListWith("Item 5", "Item 4");
			_repository.SaveItem(unmodifiedItem);

			_results = _repository.GetItemsMatching(_queryToCache);
			ResultSetCache<TestItem> resultSetCacheUnderTest = new ResultSetCache<TestItem>(_repository, _sortDefinitions, _results, _queryToCache);

			resultSetCacheUnderTest.UpdateItemInCache(unmodifiedItem);

			//Would be a better test but ResultSets don't support equality checks
			//Assert.AreEqual(resultsBeforeUpdate, resultsAfterUpdate);

			Assert.AreEqual(6, resultSetCacheUnderTest.GetResultSet().Count);
			Assert.AreEqual("Item 0", resultSetCacheUnderTest.GetResultSet()[0]["StoredList"]);
			Assert.AreEqual("Item 1", resultSetCacheUnderTest.GetResultSet()[1]["StoredList"]);
			Assert.AreEqual("Item 2", resultSetCacheUnderTest.GetResultSet()[2]["StoredList"]);
			Assert.AreEqual("Item 3", resultSetCacheUnderTest.GetResultSet()[3]["StoredList"]);
			Assert.AreEqual("Item 4", resultSetCacheUnderTest.GetResultSet()[4]["StoredList"]);
			Assert.AreEqual("Item 5", resultSetCacheUnderTest.GetResultSet()[5]["StoredList"]);
		}
Esempio n. 26
0
		public void UpdateItemInCache_ItemExists_ResultSetIsUpdatedAndSorted()
		{
			TestItem itemToModify = _repository.CreateItem();
			itemToModify.StoredList = PopulateListWith("Change Me!", "Me 2!");
			_repository.SaveItem(itemToModify);

			_results = _repository.GetItemsMatching(_queryToCache);
			ResultSetCache<TestItem> resultSetCacheUnderTest = new ResultSetCache<TestItem>(_repository, _sortDefinitions, _results, _queryToCache);

			itemToModify.StoredList = PopulateListWith("Item 5", "Item 4");
			_repository.SaveItem(itemToModify);
			resultSetCacheUnderTest.UpdateItemInCache(itemToModify);

			Assert.AreEqual(6, resultSetCacheUnderTest.GetResultSet().Count);
			Assert.AreEqual("Item 0", resultSetCacheUnderTest.GetResultSet()[0]["StoredList"]);
			Assert.AreEqual("Item 1", resultSetCacheUnderTest.GetResultSet()[1]["StoredList"]);
			Assert.AreEqual("Item 2", resultSetCacheUnderTest.GetResultSet()[2]["StoredList"]);
			Assert.AreEqual("Item 3", resultSetCacheUnderTest.GetResultSet()[3]["StoredList"]);
			Assert.AreEqual("Item 4", resultSetCacheUnderTest.GetResultSet()[4]["StoredList"]);
			Assert.AreEqual("Item 5", resultSetCacheUnderTest.GetResultSet()[5]["StoredList"]);
		}
Esempio n. 27
0
		public void UpdateItemInCache_ItemDoesNotExistInCacheButDoesInRepository_ItemIsAddedToResultSetAndSortedCorrectly()
		{
			ResultSetCache<TestItem> resultSetCacheUnderTest = new ResultSetCache<TestItem>(_repository, _sortDefinitions, _results, _queryToCache);

			TestItem itemCreatedAfterCache = _repository.CreateItem();
			itemCreatedAfterCache.StoredString = "Item 1";
			_repository.SaveItem(itemCreatedAfterCache);
			resultSetCacheUnderTest.UpdateItemInCache(itemCreatedAfterCache);

			Assert.AreEqual(4, resultSetCacheUnderTest.GetResultSet().Count);
			Assert.AreEqual("Item 0", resultSetCacheUnderTest.GetResultSet()[0]["StoredString"]);
			Assert.AreEqual("Item 1", resultSetCacheUnderTest.GetResultSet()[1]["StoredString"]);
			Assert.AreEqual("Item 2", resultSetCacheUnderTest.GetResultSet()[2]["StoredString"]);
			Assert.AreEqual("Item 3", resultSetCacheUnderTest.GetResultSet()[3]["StoredString"]);
		}
Esempio n. 28
0
		public void UpdateItemInCache_ItemExists_ResultSetIsUpdatedAndSorted()
		{
			TestItem itemToModify = _repository.CreateItem();
			itemToModify.StoredString = "Item 5";
			_repository.SaveItem(itemToModify);

			_results = _repository.GetItemsMatching(_queryToCache);
			ResultSetCache<TestItem> resultSetCacheUnderTest = new ResultSetCache<TestItem>(_repository, _sortDefinitions, _results, _queryToCache);

			itemToModify.StoredString = "Item 1";
			_repository.SaveItem(itemToModify);
			resultSetCacheUnderTest.UpdateItemInCache(itemToModify);

			Assert.AreEqual(4, resultSetCacheUnderTest.GetResultSet().Count);
			Assert.AreEqual("Item 0", resultSetCacheUnderTest.GetResultSet()[0]["StoredString"]);
			Assert.AreEqual("Item 1", resultSetCacheUnderTest.GetResultSet()[1]["StoredString"]);
			Assert.AreEqual("Item 2", resultSetCacheUnderTest.GetResultSet()[2]["StoredString"]);
			Assert.AreEqual("Item 3", resultSetCacheUnderTest.GetResultSet()[3]["StoredString"]);
		}