public void GetSet_ForResultOrderWhichHasBeenSet_ReturnsNull()
        {
            // arrange
            var sut      = new EntrySearchCache();
            var criteria = new EntryCriteria
            {
                PageNumber = 1,
                PageSize   = 5
            };

            var list = new List <Entry>
            {
                new Entry
                {
                    Author = "admin",
                    Title  = "lorem"
                }
            };

            var results = new SearchResults <Entry>(list, false);

            // act
            sut.Set(criteria, ListOrder.Descending, results);
            var result = sut.Get(criteria, ListOrder.Ascending);

            // assert
            Assert.That(result, Is.Null);
        }
        public void Get_NullCriteria_Throws()
        {
            // arrange
            var sut = new EntrySearchCache();

            // act, assert
            var ex = Assert.Throws <ArgumentNullException>(() => sut.Get(null, ListOrder.Descending));

            Assert.That(ex.ParamName, Is.EqualTo("criteria"));
        }
        public void Set_NullEntries_Throws()
        {
            // arrange
            var sut = new EntrySearchCache();

            // act, assert
            var ex = Assert.Throws <ArgumentNullException>(() => sut.Set(EntryCriteria.AllEntries, ListOrder.Descending, null));

            Assert.That(ex.ParamName, Is.EqualTo("entries"));
        }
        public void Get_ForCriteriaNotSet_ReturnsNull()
        {
            // arrange
            var sut      = new EntrySearchCache();
            var criteria = new EntryCriteria
            {
                PageNumber = 1,
                PageSize   = 5
            };

            // act
            var result = sut.Get(criteria, ListOrder.Descending);

            // assert
            Assert.That(result, Is.Null);
        }
        public void ClearCache_EntriesPreviouslySet_EntriesNoLongerSet()
        {
            // arrange
            var innerCache = new Cache <EntrySearchCacheKey>("test cache", 500)
            {
                Enabled = true
            };

            var cacheManager = Mock.Of <BaseCacheManager>(x =>
                                                          x.GetNamedInstance <EntrySearchCacheKey>(It.IsAny <string>(), It.IsAny <long>(), true) == innerCache
                                                          );

            var sut      = new EntrySearchCache(cacheManager);
            var criteria = new EntryCriteria
            {
                PageNumber = 1,
                PageSize   = 5
            };

            var list = new List <Entry>
            {
                new Entry
                {
                    Author = "admin",
                    Title  = "lorem"
                }
            };

            var results = new SearchResults <Entry>(list, false);

            sut.Set(criteria, ListOrder.Descending, results);

            // act
            sut.ClearCache();

            // assert
            var result = sut.Get(criteria, ListOrder.Descending);

            Assert.That(result, Is.Null);
        }
        public void GetSet_ForCriteriaWhichHasBeenSet_ReturnsListPreviouslySet()
        {
            // arrange
            var innerCache = new Cache <EntrySearchCacheKey>("test cache", 500)
            {
                Enabled = true
            };

            var cacheManager = Mock.Of <BaseCacheManager>(x =>
                                                          x.GetNamedInstance <EntrySearchCacheKey>(It.IsAny <string>(), It.IsAny <long>(), true) == innerCache
                                                          );

            var sut      = new EntrySearchCache(cacheManager);
            var criteria = new EntryCriteria
            {
                PageNumber = 1,
                PageSize   = 5
            };

            var list = new List <Entry>
            {
                new Entry
                {
                    Author = "admin",
                    Title  = "lorem"
                }
            };

            var results = new SearchResults <Entry>(list, false);

            // act
            sut.Set(criteria, ListOrder.Descending, results);
            var result = sut.Get(criteria, ListOrder.Descending);

            // assert
            Assert.That(result.Results, Is.EquivalentTo(list));
        }