Пример #1
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"]);
        }
Пример #2
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"]);
        }
Пример #3
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"]);
        }
Пример #4
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"]);
        }
Пример #5
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"]);
        }
Пример #6
0
        public void ResultSetContainsIdenticalRecordTokens_Throws()
        {
            PalasoTestItem itemFromWhichToCreateIdenticalRecordTokens = dataMapper.CreateItem();

            itemFromWhichToCreateIdenticalRecordTokens.StoredString = "Get me twice!";

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

            query1.Show("StoredString");
            QueryAdapter <PalasoTestItem> query2 = new QueryAdapter <PalasoTestItem>();

            query2.Show("StoredString");

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

            resultSetCacheUnderTest.Add(dataMapper.GetItemsMatching(query1), query1);
            Assert.Throws <ArgumentException>(() => resultSetCacheUnderTest.Add(dataMapper.GetItemsMatching(query2), query2));
        }
Пример #7
0
        public void Add_QueryNull_Throws()
        {
            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);

            Assert.Throws <ArgumentNullException>(() => resultSetCacheUnderTest.Add(results, null));
        }
Пример #8
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);
        }
Пример #9
0
		public void ResultSetContainsIdenticalRecordTokens_Throws()
		{
			TestItem itemFromWhichToCreateIdenticalRecordTokens = _repository.CreateItem();

			itemFromWhichToCreateIdenticalRecordTokens.StoredString = "Get me twice!";

			QueryAdapter<TestItem> query1 = new QueryAdapter<TestItem>();
			query1.Show("StoredString");
			QueryAdapter<TestItem> query2 = new QueryAdapter<TestItem>();
			query2.Show("StoredString");

			ResultSetCache<TestItem> resultSetCacheUnderTest = new ResultSetCache<TestItem>(_repository, _sortDefinitions);
			resultSetCacheUnderTest.Add(_repository.GetItemsMatching(query1), query1);
			resultSetCacheUnderTest.Add(_repository.GetItemsMatching(query2), query2);
		}
Пример #10
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);
		}
Пример #11
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"]);
		}
Пример #12
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"]);
		}
Пример #13
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"]);
		}
Пример #14
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"]);
		}
Пример #15
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"]);
		}
Пример #16
0
		public void Add_QueryNull_Throws()
		{
			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, null);
		}