Beispiel #1
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"]);
        }
Beispiel #2
0
        public void UpdateItemInCache_ItemDoesNotExistInRepository_Throws()
        {
            ResultSetCache <PalasoTestItem> resultSetCacheUnderTest = new ResultSetCache <PalasoTestItem>(_dataMapper, _sortDefinitions, _results, _queryToCache);
            PalasoTestItem itemNotInRepository = new PalasoTestItem();

            Assert.Throws <ArgumentOutOfRangeException>(() => resultSetCacheUnderTest.UpdateItemInCache(itemNotInRepository));
        }
Beispiel #3
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"]);
        }
Beispiel #4
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"]);
        }
Beispiel #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"]);
        }
Beispiel #6
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"]);
        }
        public void DeleteItemById_ItemDeletedInBothRepositories()
        {
            PalasoTestItem item = _synchronic.CreateItem();

            _synchronic.DeleteItem(_synchronic.GetId(item));
            Assert.AreEqual(0, _primary.CountAllItems());
            Assert.AreEqual(0, _secondary.CountAllItems());
        }
Beispiel #8
0
 public void Setup()
 {
     item               = new PalasoTestItem("top", 1, DateTime.UtcNow);
     item.Child         = new PalasoChildTestItem(null, 24, DateTime.Now);
     item.ChildItemList = new List <PalasoChildTestItem>();
     item.ChildItemList.Add(new PalasoChildTestItem("1", 1, DateTime.Now));
     item.ChildItemList.Add(new PalasoChildTestItem("2", 2, DateTime.Now));
     item.ChildItemList.Add(new PalasoChildTestItem("3", 3, DateTime.Now));
 }
        public void ChangeItem_ItemChangedInBothRepositories()
        {
            PalasoTestItem item = _synchronic.CreateItem();

            item.StoredString = "changed";
            _synchronic.SaveItem(item);
            Assert.AreEqual("changed", _primary.GetItem(_primary.GetAllItems()[0]).StoredString);
            Assert.AreEqual("changed", _secondary.GetItem(_secondary.GetAllItems()[0]).StoredString);
        }
        public void CreateItem_ItemExistsInBothRepositories()
        {
            PalasoTestItem item = _synchronic.CreateItem();

            _synchronic.SaveItem(item);
            Assert.AreEqual(item, _primary.GetItem(_primary.GetAllItems()[0]));
            Assert.AreEqual(item, _secondary.GetItem(_secondary.GetAllItems()[0]));
            Assert.AreEqual(1, _primary.CountAllItems());
            Assert.AreEqual(1, _secondary.CountAllItems());
        }
Beispiel #11
0
        private void PopulateRepositoryWithItemsForQuerying(MemoryDataMapper <PalasoTestItem> dataMapper)
        {
            PalasoTestItem[] items = new PalasoTestItem[2];
            items[0]            = dataMapper.CreateItem();
            items[0].StoredList = PopulateListWith("Item 1", "Item 3");
            dataMapper.SaveItem(items[0]);

            items[1]            = dataMapper.CreateItem();
            items[1].StoredList = PopulateListWith("Item 2", "Item 0");
            dataMapper.SaveItem(items[1]);
        }
Beispiel #12
0
        private void PopulateRepositoryWithItemsForQuerying(MemoryDataMapper <PalasoTestItem> dataMapper)
        {
            var items = new PalasoTestItem[3];

            items[0] = dataMapper.CreateItem();
            items[0].StoredString = "Item 3";
            dataMapper.SaveItem(items[0]);
            items[1] = dataMapper.CreateItem();
            items[1].StoredString = "Item 0";
            dataMapper.SaveItem(items[1]);
            items[2] = dataMapper.CreateItem();
            items[2].StoredString = "Item 2";
            dataMapper.SaveItem(items[2]);
        }
Beispiel #13
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"]);
        }
        public void StartWithItemsInBothButPrimaryNewer_NewestOneWins()
        {
            PalasoTestItem item = _secondary.CreateItem();

            item.StoredString = "item one";
            _secondary.SaveItem(item);
            item = _primary.CreateItem();
            item.StoredString = "item two";
            _primary.SaveItem(item);
            _synchronic.Dispose();
            _synchronic = new SynchronicRepository <PalasoTestItem>(_primary, _secondary);
            Assert.AreEqual(1, _primary.CountAllItems());
            Assert.AreEqual(1, _secondary.CountAllItems());
            Assert.AreEqual("item two", _primary.GetItem(_primary.GetAllItems()[0]).StoredString);
            Assert.AreEqual("item two", _secondary.GetItem(_secondary.GetAllItems()[0]).StoredString);
        }
Beispiel #15
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));
        }
        public void StartWithItemsInSecondary_ItemsCopiedToPrimary()
        {
            PalasoTestItem item = _secondary.CreateItem();

            item.StoredString = "item one";
            item = _secondary.CreateItem();
            item.StoredString = "item two";
            _synchronic.Dispose();
            _synchronic = new SynchronicRepository <PalasoTestItem>(_primary, _secondary);
            Assert.AreEqual(2, _primary.CountAllItems());
            var strings = new List <string>(2)
            {
                _primary.GetItem(_primary.GetAllItems()[0]).StoredString,
                _primary.GetItem(_primary.GetAllItems()[1]).StoredString
            };

            Assert.Contains("item one", strings);
            Assert.Contains("item two", strings);
        }
Beispiel #17
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"]);
        }
Beispiel #18
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"]);
        }
Beispiel #19
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"]);
        }
Beispiel #20
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"]);
        }
Beispiel #21
0
 public void Setup()
 {
     item = new PalasoTestItem();
 }