Пример #1
0
        public async Task SendRadarrMovie_SendingFailed()
        {
            RadarrMock.Setup(x => x.GetSettingsAsync())
            .ReturnsAsync(F.Build <RadarrSettings>().With(x => x.Enabled, true).Create());
            RadarrApiMock.Setup(x => x.AddMovie(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>(),
                                                It.IsAny <Uri>(), It.IsAny <bool>())).Returns(new RadarrAddMovie {
                Error = new RadarrError {
                    message = "Movie Already Added"
                }
            });

            CacheMock.Setup(x => x.GetOrSet <List <SonarrRootFolder> >(CacheKeys.RadarrRootFolders, It.IsAny <Func <List <SonarrRootFolder> > >(), It.IsAny <int>()))
            .Returns(F.CreateMany <SonarrRootFolder>().ToList());

            var model = F.Create <RequestedModel>();

            var result = await Sender.Send(model, 2.ToString());


            Assert.That(result.Result, Is.False);
            Assert.That(result.Error, Is.True);
            Assert.That(result.MovieSendingEnabled, Is.True);

            RadarrApiMock.Verify(x => x.AddMovie(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <int>(), 2, It.IsAny <string>(), It.IsAny <string>(),
                                                 It.IsAny <Uri>(), It.IsAny <bool>()), Times.Once);
        }
Пример #2
0
        public void Should_Replace_Markdown_With_External_Link()
        {
            // Arrange
            string menuMarkup   = "* [First link](http://www.google.com)\r\n";
            string expectedHtml = "<ul><li><a href=\"http://www.google.com\" rel=\"nofollow\" class=\"external-link\">First link</a></li></ul>";

            RepositoryMock repository = new RepositoryMock();

            repository.SiteSettings            = new SiteSettings();
            repository.SiteSettings.MarkupType = "Markdown";
            repository.SiteSettings.MenuMarkup = menuMarkup;

            UserContextStub     userContext         = new UserContextStub();
            ApplicationSettings applicationSettings = new ApplicationSettings();

            applicationSettings.Installed = true;

            CacheMock cache     = new CacheMock();
            SiteCache siteCache = new SiteCache(applicationSettings, cache);

            MarkupConverter converter = new MarkupConverter(applicationSettings, repository, _pluginFactory);
            MenuParser      parser    = new MenuParser(converter, repository, siteCache, userContext);

            // Act
            string actualHtml = parser.GetMenu();

            // Assert
            Assert.That(actualHtml, Is.EqualTo(expectedHtml));
        }
Пример #3
0
        public void Should_Replace_Known_Tokens_When_Logged_In_As_Editor()
        {
            // Arrange
            string menuMarkup   = "* %categories%\r\n\r\n%allpages%\r\n%mainpage%\r\n%newpage%\r\n%managefiles%\r\n%sitesettings%\r\n";
            string expectedHtml = "<ul><li><a href=\"/pages/alltags\">Categories</a></li></ul>" +
                                  "<a href=\"/pages/allpages\">All pages</a>" +
                                  "<a href=\"/\">Main Page</a>" +
                                  "<a href=\"/pages/new\">New page</a><a href=\"/filemanager\">Manage files</a>";

            RepositoryMock repository = new RepositoryMock();

            repository.SiteSettings            = new SiteSettings();
            repository.SiteSettings.MarkupType = "Markdown";
            repository.SiteSettings.MenuMarkup = menuMarkup;

            UserContextStub userContext = new UserContextStub();

            userContext.IsAdmin    = false;
            userContext.IsLoggedIn = true;

            ApplicationSettings applicationSettings = new ApplicationSettings();

            applicationSettings.Installed = true;
            CacheMock cache     = new CacheMock();
            SiteCache siteCache = new SiteCache(applicationSettings, cache);

            MarkupConverter converter = new MarkupConverter(applicationSettings, repository, _pluginFactory);
            MenuParser      parser    = new MenuParser(converter, repository, siteCache, userContext);

            // Act
            string actualHtml = parser.GetMenu();

            // Assert
            Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml);
        }
Пример #4
0
        public void addpage_should_clear_list_and_pagesummary_caches()
        {
            // Arrange
            SettingsRepositoryMock settingsRepository = new SettingsRepositoryMock();
            PageRepositoryMock     pageRepository     = new PageRepositoryMock();
            CacheMock pageModelCache = new CacheMock();
            CacheMock listCache      = new CacheMock();

            PageService   pageService   = CreatePageService(pageModelCache, listCache, settingsRepository, pageRepository);
            PageViewModel expectedModel = CreatePageViewModel();

            AddPageCacheItem(pageModelCache, "key", expectedModel);
            AddListCacheItem(listCache, "key", new List <string>()
            {
                "tag1", "tag2"
            });

            // Act
            pageService.AddPage(new PageViewModel()
            {
                Title = "totoro"
            });

            // Assert
            Assert.That(pageModelCache.CacheItems.Count, Is.EqualTo(0));
            Assert.That(listCache.CacheItems.Count, Is.EqualTo(0));
        }
Пример #5
0
        public void RemoveAll_Should_Remove_SiteCache_Keys_Only()
        {
            // Arrange
            CacheMock cache = new CacheMock();

            cache.Add("list.blah", "xyz", new CacheItemPolicy());
            ApplicationSettings settings  = new ApplicationSettings();
            SiteCache           siteCache = new SiteCache(settings, cache);

            siteCache.AddMenu("menu html");
            siteCache.AddLoggedInMenu("logged in menu html");
            siteCache.AddAdminMenu("admin menu html");

            TextPluginStub plugin = new TextPluginStub();

            plugin.PluginCache = siteCache;
            plugin.Repository  = new RepositoryMock();
            plugin.Settings.SetValue("foo", "bar");

            // Act
            siteCache.RemoveAll();

            // Assert
            Assert.That(cache.Count(), Is.EqualTo(1));
        }
Пример #6
0
        public void findbytag_should_load_from_cache()
        {
            string tag1CacheKey = CacheKeys.PagesByTagKey("tag1");
            string tag2CacheKey = CacheKeys.PagesByTagKey("tag2");

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

            PageService   pageService = CreatePageService(null, listCache, settingsRepository, pageRepository);
            PageViewModel tag1Model   = CreatePageViewModel();

            tag1Model.RawTags = "tag1";
            PageViewModel tag2Model = CreatePageViewModel();

            tag2Model.RawTags = "tag2";

            listCache.Add(tag1CacheKey, new List <PageViewModel>()
            {
                tag1Model
            }, new CacheItemPolicy());
            listCache.Add(tag2CacheKey, new List <PageViewModel>()
            {
                tag2Model
            }, new CacheItemPolicy());

            // Act
            IEnumerable <PageViewModel> actualList = pageService.FindByTag("tag1");

            // Assert
            Assert.That(actualList, Contains.Item(tag1Model));
            Assert.That(actualList, Is.Not.Contains(tag2Model));
        }
Пример #7
0
        public void updatepage_should_remove_homepage_from_cache_when_homepage_is_updated()
        {
            // Arrange
            SettingsRepositoryMock settingsRepository = new SettingsRepositoryMock();
            PageRepositoryMock     pageRepository     = new PageRepositoryMock();

            pageRepository.AddNewPage(new Page()
            {
                Tags = "homepage"
            }, "text", "admin", DateTime.UtcNow);

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

            PageViewModel homepageModel = CreatePageViewModel();

            homepageModel.RawTags = "homepage";
            pageCache.Add(CacheKeys.HomepageKey(), homepageModel, new CacheItemPolicy());

            // Act
            pageService.UpdatePage(homepageModel);

            // Assert
            Assert.That(pageCache.CacheItems.Count, Is.EqualTo(0));
        }
Пример #8
0
        public void removeall_should_remove_listcache_keys_only()
        {
            // Arrange
            CacheMock cache = new CacheMock();

            cache.Add("site.blah", "xyz", new CacheItemPolicy());

            ApplicationSettings settings = new ApplicationSettings()
            {
                UseObjectCache = true
            };

            List <string> tagCacheItems1 = new List <string>()
            {
                "1", "2"
            };
            List <string> tagCacheItems2 = new List <string>()
            {
                "1", "2"
            };

            AddToCache(cache, "all.tags1", tagCacheItems1);
            AddToCache(cache, "all.tags2", tagCacheItems2);

            ListCache listCache = new ListCache(settings, cache);

            // Act
            listCache.RemoveAll();

            // Assert
            Assert.That(cache.Count(), Is.EqualTo(1));
        }
Пример #9
0
        public void should_getallkeys()
        {
            // Arrange
            CacheMock           cache    = new CacheMock();
            ApplicationSettings settings = new ApplicationSettings()
            {
                UseObjectCache = true
            };

            List <string> tagCacheItems1 = new List <string>()
            {
                "1", "2"
            };
            List <string> tagCacheItems2 = new List <string>()
            {
                "a", "b"
            };
            ListCache listCache = new ListCache(settings, cache);

            // Act
            listCache.Add("all.tags1", tagCacheItems1);
            listCache.Add("all.tags2", tagCacheItems2);

            // Assert
            List <string> keys = listCache.GetAllKeys().ToList();

            Assert.That(keys, Contains.Item(CacheKeys.ListCacheKey("all.tags1")));
            Assert.That(keys, Contains.Item(CacheKeys.ListCacheKey("all.tags2")));
        }
Пример #10
0
        public void should_not_add_if_cache_disabled()
        {
            // Arrange
            CacheMock           cache    = new CacheMock();
            ApplicationSettings settings = new ApplicationSettings()
            {
                UseObjectCache = false
            };

            List <string> tagCacheItems = new List <string>()
            {
                "1", "2"
            };
            ListCache listCache = new ListCache(settings, cache);

            // Act
            listCache.Add("all.tags", tagCacheItems);

            // Assert
            var tags = listCache.Get <string>("all.tags");

            Assert.That(tags, Is.Null);

            IEnumerable <string> keys = listCache.GetAllKeys();

            Assert.That(keys.Count(), Is.EqualTo(0));
        }
Пример #11
0
        public void should_not_removeall_if_cache_disabled()
        {
            // Arrange
            CacheMock           cache    = new CacheMock();
            ApplicationSettings settings = new ApplicationSettings()
            {
                UseObjectCache = false
            };

            List <string> tagCacheItems1 = new List <string>()
            {
                "1", "2"
            };
            List <string> tagCacheItems2 = new List <string>()
            {
                "1", "2"
            };

            AddToCache(cache, "all.tags1", tagCacheItems1);
            AddToCache(cache, "all.tags2", tagCacheItems2);

            ListCache listCache = new ListCache(settings, cache);

            // Act
            listCache.RemoveAll();

            // Assert
            var tags1 = cache.CacheItems.FirstOrDefault(x => x.Key.Contains("all.tags1"));
            var tags2 = cache.CacheItems.FirstOrDefault(x => x.Key.Contains("all.tags2"));

            Assert.That(tags1, Is.Not.Null);
            Assert.That(tags2, Is.Not.Null);
        }
Пример #12
0
        public void should_removeall_items()
        {
            // Arrange
            CacheMock           cache    = new CacheMock();
            ApplicationSettings settings = new ApplicationSettings()
            {
                UseObjectCache = true
            };

            List <string> tagCacheItems1 = new List <string>()
            {
                "1", "2"
            };
            List <string> tagCacheItems2 = new List <string>()
            {
                "1", "2"
            };

            AddToCache(cache, "all.tags1", tagCacheItems1);
            AddToCache(cache, "all.tags2", tagCacheItems2);

            ListCache listCache = new ListCache(settings, cache);

            // Act
            listCache.RemoveAll();

            // Assert
            Assert.That(cache.CacheItems.Count, Is.EqualTo(0));
        }
Пример #13
0
        public void Settings_Should_Load_From_Repository_When_Cache_Is_Not_Set()
        {
            // Arrange
            CacheMock           cache           = new CacheMock();
            ApplicationSettings appSettings     = new ApplicationSettings();
            Mock <IPluginCache> pluginCacheMock = new Mock <IPluginCache>();

            PluginSettings expectedPluginSettings = new PluginSettings("mockplugin", "1.0");

            expectedPluginSettings.SetValue("repository", "test");
            RepositoryMock repository = new RepositoryMock();

            repository.PluginSettings = expectedPluginSettings;

            TextPluginStub plugin = new TextPluginStub();

            plugin.PluginCache = pluginCacheMock.Object;
            plugin.Repository  = repository;

            // Act
            PluginSettings actualPluginSettings = plugin.Settings;

            // Assert
            Assert.That(actualPluginSettings, Is.Not.Null);
            Assert.That(actualPluginSettings.GetValue("repository"), Is.EqualTo("test"));
        }
Пример #14
0
        public void Settings_Should_Return_Member_Instance_On_Second_Call_And_Not_Load_From_Cache_Or_Repository()
        {
            // Arrange
            CacheMock           cache           = new CacheMock();
            ApplicationSettings appSettings     = new ApplicationSettings();
            Mock <IPluginCache> pluginCacheMock = new Mock <IPluginCache>();
            Mock <IRepository>  mockRepository  = new Mock <IRepository>();

            TextPluginStub plugin = new TextPluginStub();

            plugin.PluginCache = pluginCacheMock.Object;
            plugin.Repository  = mockRepository.Object;

            // Act
            PluginSettings settings = plugin.Settings;

            settings = plugin.Settings;

            // Assert
            Assert.That(settings, Is.Not.Null);
            pluginCacheMock.Verify(x => x.GetPluginSettings(plugin), Times.Once);             // 1st time only
            pluginCacheMock.Verify(x => x.UpdatePluginSettings(plugin), Times.Once);
            mockRepository.Verify(x => x.GetTextPluginSettings(plugin.DatabaseId), Times.Once);
            mockRepository.Verify(x => x.SaveTextPluginSettings(plugin), Times.Once);
        }
Пример #15
0
        public void deletepage_should_clear_list_and_pagesummary_caches()
        {
            // Arrange
            SettingsRepositoryMock settingsRepository = new SettingsRepositoryMock();
            PageRepositoryMock     pageRepository     = new PageRepositoryMock();

            pageRepository.AddNewPage(new Page(), "text", "admin", DateTime.UtcNow);
            CacheMock pageCache = new CacheMock();
            CacheMock listCache = new CacheMock();

            PageService   pageService   = CreatePageService(pageCache, listCache, settingsRepository, pageRepository);
            PageViewModel expectedModel = CreatePageViewModel();

            AddPageCacheItem(pageCache, "key", expectedModel);
            AddListCacheItem(listCache, "key", new List <string>()
            {
                "tag1", "tag2"
            });

            // Act
            pageService.DeletePage(1);

            // Assert
            Assert.That(pageCache.CacheItems.Count, Is.EqualTo(0));
            Assert.That(listCache.CacheItems.Count, Is.EqualTo(0));
        }
Пример #16
0
        public void should_remove_item()
        {
            // Arrange
            CacheMock           cache    = new CacheMock();
            ApplicationSettings settings = new ApplicationSettings()
            {
                UseObjectCache = true
            };

            List <string> tagCacheItems = new List <string>()
            {
                "1", "2"
            };

            AddToCache(cache, "all.tags", tagCacheItems);

            ListCache listCache = new ListCache(settings, cache);

            // Act
            listCache.Remove("all.tags");

            // Assert
            var tags = cache.CacheItems.FirstOrDefault();

            Assert.That(tags, Is.Null);
        }
Пример #17
0
        public void getbyid_should_add_to_cache_when_pagesummary_does_not_exist_in_cache()
        {
            // Arrange
            SettingsRepositoryMock settingsRepository = new SettingsRepositoryMock();
            PageRepositoryMock     pageRepository     = new PageRepositoryMock();
            CacheMock   pageModelCache = new CacheMock();
            PageService pageService    = CreatePageService(pageModelCache, null, settingsRepository, pageRepository);

            PageViewModel expectedModel = CreatePageViewModel();

            expectedModel = pageService.AddPage(expectedModel);             // get it back to update the version no.

            // Act
            pageService.GetById(1);

            // Assert
            CacheItem cacheItem = pageModelCache.CacheItems.First();
            string    cacheKey  = CacheKeys.PageViewModelKey(1, PageViewModelCache.LATEST_VERSION_NUMBER);

            Assert.That(cacheItem.Key, Is.EqualTo(cacheKey));

            PageViewModel actualModel = (PageViewModel)cacheItem.Value;

            Assert.That(actualModel.Id, Is.EqualTo(expectedModel.Id));
            Assert.That(actualModel.VersionNumber, Is.EqualTo(expectedModel.VersionNumber));
            Assert.That(actualModel.Title, Is.EqualTo(expectedModel.Title));
        }
        public void TrackingContextIsCachedForSolicitResponseOutboundMessage()
        {
            var transmitWorkId = Guid.NewGuid().ToString();

            var trackingContext = new TrackingContext {
                ProcessActivityId        = ActivityId.NewActivityId(),
                ProcessingStepActivityId = ActivityId.NewActivityId(),
                MessagingStepActivityId  = ActivityId.NewActivityId()
            };

            MessageMock.Setup(m => m.GetProperty(BtsProperties.IsSolicitResponse)).Returns(true);
            MessageMock.Setup(m => m.GetProperty(BtsProperties.OutboundTransportLocation)).Returns("outbound-transport-location");
            MessageMock.Setup(m => m.GetProperty(BtsProperties.TransmitWorkId)).Returns(transmitWorkId);
            MessageMock.Setup(m => m.GetProperty(TrackingProperties.ProcessActivityId)).Returns(trackingContext.ProcessActivityId);
            MessageMock.Setup(m => m.GetProperty(TrackingProperties.ProcessingStepActivityId)).Returns(trackingContext.ProcessingStepActivityId);
            MessageMock.Setup(m => m.GetProperty(TrackingProperties.MessagingStepActivityId)).Returns(trackingContext.MessagingStepActivityId);

            CacheMock.Setup(c => c.Set(transmitWorkId, trackingContext, 60 + 1));

            var sut = CreateActivityTracker();

            sut.Execute(PipelineContextMock.Object, MessageMock.Object);

            CacheMock.VerifyAll();
        }
Пример #19
0
        public void findbytag_should_add_to_cache_when_cache_is_empty()
        {
            // Arrange
            string cacheKey = CacheKeys.PagesByTagKey("tag1");

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

            pageRepository.AddNewPage(new Page()
            {
                Title = "1", Tags = "tag1"
            }, "text", "admin", DateTime.UtcNow);
            pageRepository.AddNewPage(new Page()
            {
                Title = "2", Tags = "tag2"
            }, "text", "admin", DateTime.UtcNow);
            pageRepository.AddNewPage(new Page()
            {
                Title = "2", Tags = "tag3"
            }, "text", "admin", DateTime.UtcNow);

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

            // Act
            pageService.FindByTag("tag1");

            // Assert
            Assert.That(listCache.CacheItems.Count, Is.EqualTo(1));
            Assert.That(listCache.CacheItems.FirstOrDefault().Key, Is.EqualTo(cacheKey));
        }
        public void TrackingContextIsRestoredForSolicitResponseInboundMessageUnlessNegativeCacheDuration()
        {
            var transmitWorkId = Guid.NewGuid().ToString();

            var trackingContext = new TrackingContext {
                ProcessActivityId        = ActivityId.NewActivityId(),
                ProcessingStepActivityId = ActivityId.NewActivityId(),
                MessagingStepActivityId  = ActivityId.NewActivityId()
            };

            MessageMock.Setup(m => m.GetProperty(BtsProperties.IsSolicitResponse)).Returns(true);
            MessageMock.Setup(m => m.GetProperty(BtsProperties.InboundTransportLocation)).Returns("inbound-transport-location");
            MessageMock.Setup(m => m.GetProperty(BtsProperties.TransmitWorkId)).Returns(transmitWorkId);

            var sut = CreateActivityTracker();

            sut.TrackingContextCacheDuration = TimeSpan.FromSeconds(-1);

            sut.Execute(PipelineContextMock.Object, MessageMock.Object);

            CacheMock.VerifyAll();

            // verifies that TrackingContext fields have been restored in message.Context
            MessageMock.Verify(m => m.SetProperty(TrackingProperties.ProcessActivityId, trackingContext.ProcessActivityId), Times.Never());
            MessageMock.Verify(m => m.SetProperty(TrackingProperties.ProcessingStepActivityId, trackingContext.ProcessingStepActivityId), Times.Never());
            MessageMock.Verify(m => m.SetProperty(TrackingProperties.MessagingStepActivityId, trackingContext.MessagingStepActivityId), Times.Never());
        }
Пример #21
0
        public void renametag_should_clear_listcache()
        {
            // Arrange
            string tag1CacheKey = CacheKeys.PagesByTagKey("tag1");
            SettingsRepositoryMock settingsRepository = new SettingsRepositoryMock();
            PageRepositoryMock     pageRepository     = new PageRepositoryMock();

            pageRepository.AddNewPage(new Page()
            {
                Tags = "homepage, tag1"
            }, "text1", "admin", DateTime.UtcNow);

            CacheMock     listCache     = new CacheMock();
            PageViewModel homepageModel = CreatePageViewModel();
            PageViewModel page1Model    = CreatePageViewModel();

            AddListCacheItem(listCache, tag1CacheKey, new List <PageViewModel>()
            {
                homepageModel, page1Model
            });

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

            // Act
            pageService.RenameTag("tag1", "some.other.tag");             // calls UpdatePage, which clears the cache

            // Assert
            Assert.That(listCache.CacheItems.Count, Is.EqualTo(0));
        }
Пример #22
0
        public void AllPages_Should_Add_To_Cache_When_Cache_Is_Empty(bool loadPageContent)
        {
            // Arrange
            string cacheKey = (loadPageContent) ? (CacheKeys.AllPagesWithContent()) : (CacheKeys.AllPages());

            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);

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

            // Act
            pageService.AllPages(loadPageContent);

            // Assert
            Assert.That(listCache.CacheItems.Count, Is.EqualTo(1));
            Assert.That(listCache.CacheItems.FirstOrDefault().Key, Is.EqualTo(cacheKey));
        }
Пример #23
0
        public void GetPluginSettings_Should_Return_Plugin_Settings()
        {
            // Arrange
            CacheMock           cache     = new CacheMock();
            ApplicationSettings settings  = new ApplicationSettings();
            SiteCache           siteCache = new SiteCache(settings, cache);

            TextPluginStub plugin = new TextPluginStub("id1", "", "");

            plugin.PluginCache = siteCache;
            plugin.Repository  = new RepositoryMock();
            plugin.Settings.SetValue("foo", "bar");

            TextPluginStub plugin2 = new TextPluginStub("id2", "", "");

            plugin2.PluginCache = siteCache;
            plugin2.Repository  = new RepositoryMock();
            plugin2.Settings.SetValue("foo", "bar2");

            // Act
            PluginSettings pluginSettings = siteCache.GetPluginSettings(plugin);

            // Assert
            Assert.That(pluginSettings.Values.Count(), Is.EqualTo(1));
            Assert.That(pluginSettings.GetValue("foo"), Is.EqualTo("bar"));
        }
Пример #24
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));
        }
Пример #25
0
        public void Should_Remove_Empty_UL_Tags_For_Logged_In_Tokens_When_Not_Logged_In(string markupType, string expectedHtml)
        {
            // Arrange - \r\n is important so the markdown is valid
            string menuMarkup = "%mainpage%\r\n\r\n* %newpage%\r\n* %managefiles%\r\n* %sitesettings%\r\n";

            RepositoryMock repository = new RepositoryMock();

            repository.SiteSettings            = new SiteSettings();
            repository.SiteSettings.MarkupType = markupType;
            repository.SiteSettings.MenuMarkup = menuMarkup;

            UserContextStub userContext = new UserContextStub();

            userContext.IsLoggedIn = false;

            ApplicationSettings applicationSettings = new ApplicationSettings();

            applicationSettings.Installed = true;
            CacheMock cache     = new CacheMock();
            SiteCache siteCache = new SiteCache(applicationSettings, cache);

            MarkupConverter converter = new MarkupConverter(applicationSettings, repository, _pluginFactory);
            MenuParser      parser    = new MenuParser(converter, repository, siteCache, userContext);

            // Act
            string actualHtml = parser.GetMenu();

            // Assert
            Assert.That(actualHtml, Is.EqualTo(expectedHtml));
        }
Пример #26
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));
        }
Пример #27
0
        public void Should_Replace_Markdown_With_Internal_Link()
        {
            // Arrange
            string menuMarkup   = "* [First link](my-page)\r\n";
            string expectedHtml = "<ul><li><a href=\"/wiki/1/my-page\">First link</a></li></ul>";

            RepositoryMock repository = new RepositoryMock();

            repository.AddNewPage(new Page()
            {
                Title = "my page", Id = 1
            }, "text", "user", DateTime.Now);

            repository.SiteSettings            = new SiteSettings();
            repository.SiteSettings.MarkupType = "Markdown";
            repository.SiteSettings.MenuMarkup = menuMarkup;

            UserContextStub     userContext         = new UserContextStub();
            ApplicationSettings applicationSettings = new ApplicationSettings();

            applicationSettings.Installed = true;

            CacheMock cache     = new CacheMock();
            SiteCache siteCache = new SiteCache(applicationSettings, cache);

            MarkupConverter converter = new MarkupConverter(applicationSettings, repository, _pluginFactory);
            MenuParser      parser    = new MenuParser(converter, repository, siteCache, userContext);

            // Act
            string actualHtml = parser.GetMenu();

            // Assert
            Assert.That(actualHtml, Is.EqualTo(expectedHtml));
        }
Пример #28
0
        public void alltags_should_add_to_cache_when_cache_is_empty()
        {
            // Arrange
            SettingsRepositoryMock settingsRepository = new SettingsRepositoryMock();
            PageRepositoryMock     pageRepository     = new PageRepositoryMock();

            pageRepository.AddNewPage(new Page()
            {
                Tags = "tag1;tag2"
            }, "text", "admin", DateTime.UtcNow);
            pageRepository.AddNewPage(new Page()
            {
                Tags = "tag3;tag4"
            }, "text", "admin", DateTime.UtcNow);

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

            // Act
            pageService.AllTags();

            // Assert
            Assert.That(listCache.CacheItems.Count, Is.EqualTo(1));
            Assert.That(listCache.CacheItems.FirstOrDefault().Key, Is.EqualTo(CacheKeys.AllTags()));
        }
Пример #29
0
        public void ParseTokensXsltGoodXsltWithCacheTest()
        {
            var    expectedText = "Hello, World!";
            string xmlDocument  = $"<?xml version=\"1.0\"?><hello-world><greeting>{expectedText}</greeting></hello-world>";
            var    serviceInfo  = new ServiceInfo()
            {
                Tokens = new[]
                {
                    new XsltTokenInfo
                    {
                        Id   = Guid.NewGuid(),
                        Name = "Test token",
                        Xslt = "<xsl:template match=\"/hello-world\"><xsl:value-of select=\"greeting\"/></xsl:template>"
                    }
                }
            };
            string expected = $"{expectedText}";

            var cache = new CacheMock();

            var sut = new TokenService(cache);

            IEnumerable <TokenResponse> _      = sut.ParseTokens("cacheRegion", xmlDocument, serviceInfo.Tokens).ToArray();
            IEnumerable <TokenResponse> actual = sut.ParseTokens("cacheRegion", xmlDocument, serviceInfo.Tokens).ToArray();

            Assert.IsTrue(actual.Any());

            TokenResponse token = actual.First();

            Assert.AreEqual(TokenResponseStatus.Found, token.Status);
            Assert.AreEqual(expected, token.Value);
        }
Пример #30
0
        public void ResultOfMethodCallWithSameComplexTypeIsCached()
        {
            var testModule = new InlineModule(m => m.Bind <CacheMock>().ToSelf());

            using (var kernel = new StandardKernel(new LinFuModule(), new CacheModule(), testModule))
            {
                var obj = kernel.Get <CacheMock>();

                CacheMock.ResetCounts();

                string result;

                var simple1 = new SimpleObject();
                var simple2 = new SimpleObject();

                result = obj.Convert(simple1);
                Assert.That(result, Is.EqualTo(simple1.ToString()));
                Assert.That(CacheMock.ConvertCount, Is.EqualTo(1));

                result = obj.Convert(simple1);
                Assert.That(result, Is.EqualTo(simple1.ToString()));
                Assert.That(CacheMock.ConvertCount, Is.EqualTo(1));

                result = obj.Convert(simple2);
                Assert.That(result, Is.EqualTo(simple2.ToString()));
                Assert.That(CacheMock.ConvertCount, Is.EqualTo(2));
            }
        }