Exemplo n.º 1
0
        public void allpagescreatedby_should_load_from_cache()
        {
            string adminCacheKey  = CacheKeys.AllPagesCreatedByKey("admin");
            string editorCacheKey = CacheKeys.AllPagesCreatedByKey("editor");

            // Arrange
            SettingsRepositoryMock settingsRepository = new SettingsRepositoryMock();
            PageRepositoryMock     pageRepository     = new PageRepositoryMock();
            CacheMock listCache = new CacheMock();

            PageService   pageService = CreatePageService(null, listCache, settingsRepository, pageRepository);
            PageViewModel adminModel  = CreatePageViewModel();
            PageViewModel editorModel = CreatePageViewModel("editor");

            listCache.Add(CacheKeys.AllPagesCreatedByKey("admin"), new List <PageViewModel>()
            {
                adminModel
            }, new CacheItemPolicy());
            listCache.Add(CacheKeys.AllPagesCreatedByKey("editor"), new List <PageViewModel>()
            {
                editorModel
            }, new CacheItemPolicy());

            // Act
            IEnumerable <PageViewModel> actualList = pageService.AllPagesCreatedBy("admin");

            // Assert
            Assert.That(actualList, Contains.Item(adminModel));
            Assert.That(actualList, Is.Not.Contains(editorModel));
        }
Exemplo n.º 2
0
        public void allpagescreatedby_should_add_to_cache_when_cache_is_empty()
        {
            // Arrange
            string adminCacheKey = CacheKeys.AllPagesCreatedByKey("admin");

            SettingsRepositoryMock settingsRepository = new SettingsRepositoryMock();
            PageRepositoryMock     pageRepository     = new PageRepositoryMock();

            pageRepository.AddNewPage(new Page()
            {
                Title = "1"
            }, "text", "admin", DateTime.UtcNow);
            pageRepository.AddNewPage(new Page()
            {
                Title = "2"
            }, "text", "admin", DateTime.UtcNow);
            pageRepository.AddNewPage(new Page()
            {
                Title = "3"
            }, "text", "editor", DateTime.UtcNow);

            CacheMock   listCache   = new CacheMock();
            PageService pageService = CreatePageService(null, listCache, settingsRepository, pageRepository);

            // Act
            pageService.AllPagesCreatedBy("admin");

            // Assert
            Assert.That(listCache.CacheItems.Count, Is.EqualTo(1));
            Assert.That(listCache.CacheItems.FirstOrDefault().Key, Is.EqualTo(adminCacheKey));
        }
Exemplo n.º 3
0
        public void AllPagesCreatedBy_Should_Add_To_Cache_When_Cache_Is_Empty()
        {
            // Arrange
            string adminCacheKey = CacheKeys.AllPagesCreatedByKey("admin");

            RepositoryMock repository = new RepositoryMock();

            repository.AddNewPage(new Page()
            {
                Title = "1"
            }, "text", "admin", DateTime.UtcNow);
            repository.AddNewPage(new Page()
            {
                Title = "2"
            }, "text", "admin", DateTime.UtcNow);
            repository.AddNewPage(new Page()
            {
                Title = "3"
            }, "text", "editor", DateTime.UtcNow);

            CacheMock   listCache   = new CacheMock();
            PageService pageService = CreatePageService(null, listCache, repository);

            // Act
            pageService.AllPagesCreatedBy("admin");

            // Assert
            Assert.That(listCache.CacheItems.Count, Is.EqualTo(1));
            Assert.That(listCache.CacheItems.FirstOrDefault().Key, Is.EqualTo(adminCacheKey));
        }