public void index_should_return_viewresult_and_model_with_2_pluginmodels_ordered_by_name() { // Arrange TextPluginStub pluginB = new TextPluginStub("b id", "b name", "b desc"); pluginB.Repository = _settingsRepository; pluginB.PluginCache = new SiteCache(CacheMock.RoadkillCache); TextPluginStub pluginA = new TextPluginStub("a id", "a name", "a desc"); pluginA.Repository = _settingsRepository; pluginA.PluginCache = _siteCache; _pluginFactory.RegisterTextPlugin(pluginB); // reverse the order to test the ordering _pluginFactory.RegisterTextPlugin(pluginA); // Act ViewResult result = _controller.Index() as ViewResult; // Assert Assert.That(result, Is.Not.Null); IEnumerable<PluginViewModel> pluginModels = result.ModelFromActionResult<IEnumerable<PluginViewModel>>(); Assert.NotNull(pluginModels, "Null model"); List<PluginViewModel> pageModelList = pluginModels.ToList(); Assert.That(pageModelList.Count(), Is.EqualTo(2)); Assert.That(pageModelList[0].Name, Is.EqualTo("a name")); Assert.That(pageModelList[1].Name, Is.EqualTo("b name")); }
public void DatabaseId_Should_Default_Version_To_1_If_Version_Is_Empty() { // Arrange TextPluginStub plugin = new TextPluginStub("", "", "", ""); // Act + Assert PluginSettings settings = plugin.Settings; }
public void PluginVirtualPath_Should_Throw_Exception_When_Id_Is_Empty() { // Arrange string id = ""; TextPluginStub plugin = new TextPluginStub(id, "name", "description"); // Act + Assert string path = plugin.PluginVirtualPath; }
public void DatabaseId_Should_Throw_Exception_When_Id_Is_Empty() { // Arrange string id = ""; TextPluginStub plugin = new TextPluginStub(id, "name", "description"); // Act + Assert Guid databaseId = plugin.DatabaseId; }
public void Constructor_Should_Set_Cacheable_To_True() { // Arrange RepositoryMock repository = new RepositoryMock(); ApplicationSettings appSettings = new ApplicationSettings(); TextPluginStub plugin = new TextPluginStub(); // Act + Assert Assert.That(plugin.IsCacheable, Is.True); }
public void pluginvirtualpath_should_contain_plugin_id_and_no_trailing_slash() { // Arrange TextPluginStub plugin = new TextPluginStub("Plugin1", "name", "desc"); // Act string virtualPath = plugin.PluginVirtualPath; // Assert Assert.That(virtualPath, Is.StringContaining("Plugin1")); Assert.That(virtualPath, Is.StringStarting("~/Plugins/")); Assert.That(virtualPath, Is.Not.StringEnding("/")); }
public void PluginVirtualPath_Should_Contain_Plugin_Id_And_No_Trailing_Slash() { // Arrange TextPluginStub plugin = new TextPluginStub("Plugin1", "name", "desc"); // Act string virtualPath = plugin.PluginVirtualPath; // Assert Assert.That(virtualPath, Is.StringContaining("Plugin1")); Assert.That(virtualPath, Is.StringStarting("~/Plugins/")); Assert.That(virtualPath, Is.Not.StringEnding("/")); }
public void DatabaseId_Should_Be_Different_Based_On_Id() { // Arrange TextPluginStub plugin1 = new TextPluginStub("PluginId1", "name", "desc"); TextPluginStub plugin2 = new TextPluginStub("PluginId2", "name", "desc"); // Act Guid id1 = plugin1.DatabaseId; Guid id2 = plugin2.DatabaseId; // Assert Assert.That(id1, Is.Not.EqualTo(id2)); }
public void databaseid_should_be_different_based_on_id() { // Arrange TextPluginStub plugin1 = new TextPluginStub("PluginId1", "name", "desc"); TextPluginStub plugin2 = new TextPluginStub("PluginId2", "name", "desc"); // Act Guid id1 = plugin1.DatabaseId; Guid id2 = plugin2.DatabaseId; // Assert Assert.That(id1, Is.Not.EqualTo(id2)); }
public void GetCssLink_Should_Contain_File_And_Expected_Html() { // Arrange TextPluginStub plugin = new TextPluginStub("PluginId", "name", "desc"); string expectedHtml = "\t\t" + @"<link href=""~/Plugins/PluginId/file.css?version={PluginVersion}"" rel=""stylesheet"" type=""text/css"" />" + "\n"; expectedHtml = expectedHtml.Replace("{PluginVersion}", plugin.Version); // Act string actualHtml = plugin.GetCssLink("file.css"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public void savepluginsettings_and_gettextpluginsettings() { // Arrange PluginSettings expectedSettings = new PluginSettings("mockplugin", "1.0"); expectedSettings.SetValue("somekey1", "thevalue1"); expectedSettings.SetValue("somekey2", "thevalue2"); TextPluginStub plugin = new TextPluginStub(Repository, _siteCache); plugin.Settings.SetValue("somekey1", "thevalue1"); plugin.Settings.SetValue("somekey2", "thevalue2"); // Act Repository.SaveTextPluginSettings(plugin); PluginSettings actualSettings = Repository.GetTextPluginSettings(plugin.DatabaseId); // Assert Assert.That(actualSettings.GetValue("somekey1"), Is.EqualTo("thevalue1")); Assert.That(actualSettings.GetValue("somekey2"), Is.EqualTo("thevalue2")); }
public void constructor_should_convert_textplugin_to_properties_and_description_newlines_to_br() { // Arrange TextPluginStub plugin = new TextPluginStub("myid", "my name", "my description\r\nsome new text"); plugin.Repository = new SettingsRepositoryMock(); plugin.PluginCache = new SiteCache(CacheMock.RoadkillCache); plugin.Settings.IsEnabled = true; // Act PluginViewModel model = new PluginViewModel(plugin); // Assert Assert.That(model.SettingValues, Is.Not.Null); Assert.That(model.Id, Is.EqualTo(plugin.Id)); Assert.That(model.Name, Is.EqualTo(plugin.Name)); Assert.That(model.IsEnabled, Is.True); Assert.That(model.DatabaseId, Is.EqualTo(plugin.DatabaseId)); Assert.That(model.Description, Is.EqualTo("my description<br/><br/>some new text")); }
public void Constructor_Should_Convert_TextPlugin_To_Properties_And_Description_Newlines_To_Br() { // Arrange TextPluginStub plugin = new TextPluginStub("myid", "my name", "my description\r\nsome new text"); plugin.Repository = new RepositoryMock(); plugin.PluginCache = new SiteCache(new ApplicationSettings(), CacheMock.RoadkillCache); plugin.Settings.IsEnabled = true; // Act PluginViewModel model = new PluginViewModel(plugin); // Assert Assert.That(model.SettingValues, Is.Not.Null); Assert.That(model.Id, Is.EqualTo(plugin.Id)); Assert.That(model.Name, Is.EqualTo(plugin.Name)); Assert.That(model.IsEnabled, Is.True); Assert.That(model.DatabaseId, Is.EqualTo(plugin.DatabaseId)); Assert.That(model.Description, Is.EqualTo("my description<br/><br/>some new text")); }
public void Edit_GET_Should_Load_Settings_From_Repository() { // Arrange TextPluginStub plugin = new TextPluginStub(); plugin.Repository = _repository; plugin.PluginCache = _siteCache; plugin.Settings.SetValue("name1", "default-value1"); plugin.Settings.SetValue("name2", "default-value2"); RepositoryMock repositoryMock = new RepositoryMock(); repositoryMock.SaveTextPluginSettings(plugin); repositoryMock.TextPlugins[0].Settings.SetValue("name1", "value1"); repositoryMock.TextPlugins[0].Settings.SetValue("name2", "value2"); _pluginFactory.RegisterTextPlugin(plugin); // Act ViewResult result = _controller.Edit(plugin.Id) as ViewResult; // Assert PluginViewModel model = result.ModelFromActionResult<PluginViewModel>(); Assert.That(model.SettingValues[0].Value, Is.EqualTo("value1")); Assert.That(model.SettingValues[1].Value, Is.EqualTo("value2")); }
public void should_fire_afterparse_in_textplugin_and_output_should_not_be_cleaned() { // Arrange string markupFragment = "Here is some markup **some bold**"; string expectedHtml = "<p>Here is some markup <strong style='color:green'><iframe src='javascript:alert(test)'>some bold</strong>\n</p>"; TextPluginStub plugin = new TextPluginStub(); plugin.Repository = new SettingsRepositoryMock(); plugin.PluginCache = new SiteCache(CacheMock.RoadkillCache); plugin.Settings.IsEnabled = true; _pluginFactory.RegisterTextPlugin(plugin); // Act string actualHtml = _markupConverter.ToHtml(markupFragment); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
public void should_fire_beforeparse_in_textplugin() { // Arrange string markupFragment = "This is my ~~~usertoken~~~"; string expectedHtml = "<p>This is my <span>usertoken</span>\n</p>"; TextPluginStub plugin = new TextPluginStub(); plugin.Repository = new SettingsRepositoryMock(); plugin.PluginCache = new SiteCache(CacheMock.RoadkillCache); plugin.Settings.IsEnabled = true; _pluginFactory.RegisterTextPlugin(plugin); // Act string actualHtml = _markupConverter.ToHtml(markupFragment); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
public void pagecontent_constructor_should_fill_properties_and_parse_markup() { // Arrange PageContent content = new PageContent(); content.Page = new Page(); content.Page.Id = 3; content.Page.Title = "my title"; content.Page.CreatedBy = "me"; content.Page.CreatedOn = DateTime.Now; content.Page.IsLocked = true; content.Page.ModifiedBy = "me2"; content.Page.ModifiedOn = DateTime.Now.AddDays(1); content.Page.Tags = "tag1,tag2,tag3"; content.Text = "some text **in bold**"; content.VersionNumber = 5; TextPluginStub plugin = new TextPluginStub(); plugin.IsCacheable = false; plugin.HeadContent = "head content"; plugin.FooterContent = "footer content"; plugin.PreContainerHtml = "pre container"; plugin.PostContainerHtml = "post container"; plugin.PluginCache = new SiteCache(CacheMock.RoadkillCache); plugin.Repository = _settingsRepository; plugin.Settings.IsEnabled = true; _pluginFactory.RegisterTextPlugin(plugin); // Act PageViewModel model = new PageViewModel(content, _markupConverter); // Assert Assert.That(model.Id, Is.EqualTo(content.Page.Id)); Assert.That(model.Title, Is.EqualTo(content.Page.Title)); Assert.That(model.CreatedBy, Is.EqualTo(content.Page.CreatedBy)); Assert.That(model.ModifiedBy, Is.EqualTo(content.Page.ModifiedBy)); Assert.That(model.VersionNumber, Is.EqualTo(content.VersionNumber)); Assert.That(model.Content, Is.EqualTo(content.Text)); Assert.That(model.CreatedOn, Is.EqualTo(content.Page.CreatedOn)); Assert.That(model.CreatedOn.Kind, Is.EqualTo(DateTimeKind.Utc)); Assert.That(model.ModifiedOn, Is.EqualTo(content.Page.ModifiedOn)); Assert.That(model.ModifiedOn.Kind, Is.EqualTo(DateTimeKind.Utc)); Assert.That(model.Tags.Count(), Is.EqualTo(3)); Assert.That(model.Tags, Contains.Item("tag1")); Assert.That(model.Tags, Contains.Item("tag2")); Assert.That(model.Tags, Contains.Item("tag3")); // (this extra html is from the plugin) Assert.That(model.ContentAsHtml, Is.EqualTo("<p>some text <strong style='color:green'><iframe src='javascript:alert(test)'>in bold</strong>\n</p>"), model.ContentAsHtml); Assert.That(model.IsCacheable, Is.EqualTo(plugin.IsCacheable)); Assert.That(model.PluginHeadHtml, Is.EqualTo(plugin.HeadContent)); Assert.That(model.PluginFooterHtml, Is.EqualTo(plugin.FooterContent)); Assert.That(model.PluginPreContainer, Is.EqualTo(plugin.PreContainerHtml)); Assert.That(model.PluginPostContainer, Is.EqualTo(plugin.PostContainerHtml)); }
public void Should_Ignore_TextPlugins_BeforeParse_When_IsEnabled_Is_False() { // Arrange string markupFragment = "This is my ~~~usertoken~~~"; string expectedHtml = "<p>This is my <span>usertoken</span>\n</p>"; TextPluginStub plugin = new TextPluginStub(); plugin.Repository = new RepositoryMock(); plugin.PluginCache = new SiteCache(new ApplicationSettings(), CacheMock.RoadkillCache); _pluginFactory.RegisterTextPlugin(plugin); // Act string actualHtml = _markupConverter.ToHtml(markupFragment); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
public void Should_Ignore_TextPlugins_AfterParse_When_IsEnabled_Is_False() { // Arrange string markupFragment = "Here is some markup **some bold**"; string expectedHtml = "<p>Here is some markup <strong style='color:green'><iframe src='javascript:alert(test)'>some bold</strong>\n</p>"; TextPluginStub plugin = new TextPluginStub(); plugin.Repository = new RepositoryMock(); plugin.PluginCache = new SiteCache(new ApplicationSettings(), CacheMock.RoadkillCache); _pluginFactory.RegisterTextPlugin(plugin); // Act string actualHtml = _markupConverter.ToHtml(markupFragment); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
public void Settings_Should_Load_From_Cache_When_Settings_Exist_In_Cache() { // Arrange CacheMock cache = new CacheMock(); ApplicationSettings appSettings = new ApplicationSettings(); Mock<IPluginCache> pluginCacheMock = new Mock<IPluginCache>(); PluginSettings expectedPluginSettings = new PluginSettings("mockplugin", "1.0"); expectedPluginSettings.SetValue("cache", "test"); TextPluginStub plugin = new TextPluginStub(); plugin.PluginCache = pluginCacheMock.Object; pluginCacheMock.Setup(x => x.GetPluginSettings(plugin)).Returns(expectedPluginSettings); // Act PluginSettings actualPluginSettings = plugin.Settings; // Assert Assert.That(actualPluginSettings, Is.Not.Null); Assert.That(actualPluginSettings.GetValue("cache"), Is.EqualTo("test")); }
public void SetHeadJsOnLoadedFunction_Should_Be_Added_To_Javascript() { // Arrange TextPluginStub plugin = new TextPluginStub(); plugin.AddScript("pluginscript.js", "script1"); plugin.SetHeadJsOnLoadedFunction("alert('done')"); string expectedHtml = @"<script type=""text/javascript"">" + @"head.js({ ""script1"", ""pluginscript.js"" },function() { alert('done') })" + "</script>\n"; // Act string actualHtml = plugin.GetJavascriptHtml(); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public void Settings_Should_Save_To_Repository_When_Repository_Has_No_Settings() { // Arrange CacheMock cache = new CacheMock(); ApplicationSettings appSettings = new ApplicationSettings(); Mock<IPluginCache> pluginCacheMock = new Mock<IPluginCache>(); RepositoryMock repository = new RepositoryMock(); 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(repository.TextPlugins.Count, Is.EqualTo(1)); Assert.That(repository.TextPlugins.FirstOrDefault(), Is.EqualTo(plugin)); }
public void Settings_Should_Throw_Exception_If_SiteCache_Is_Not_Set() { // Arrange TextPluginStub plugin = new TextPluginStub(); // Act + Assert PluginSettings settings = plugin.Settings; }
public void Settings_Should_Default_Version_To_1_If_Version_Is_Empty() { // Arrange CacheMock cache = new CacheMock(); ApplicationSettings appSettings = new ApplicationSettings(); Mock<IPluginCache> pluginCacheMock = new Mock<IPluginCache>(); RepositoryMock repository = new RepositoryMock(); TextPluginStub plugin = new TextPluginStub("id", "name", "desc", ""); plugin.PluginCache = pluginCacheMock.Object; plugin.Repository = repository; // Act PluginSettings actualPluginSettings = plugin.Settings; // Assert Assert.That(actualPluginSettings.Version, Is.EqualTo("1.0")); }
public void Settings_Should_Throw_Exception_If_Id_Is_Not_Set() { // Arrange CacheMock cache = new CacheMock(); ApplicationSettings appSettings = new ApplicationSettings(); Mock<IPluginCache> pluginCacheMock = new Mock<IPluginCache>(); RepositoryMock repository = new RepositoryMock(); TextPluginStub plugin = new TextPluginStub("","","",""); plugin.PluginCache = pluginCacheMock.Object; plugin.Repository = repository; // Act + Assert PluginSettings actualPluginSettings = plugin.Settings; }
public void Settings_Should_Throw_Exception_If_Repository_Is_Not_Set() { // Arrange TextPluginStub plugin = new TextPluginStub(); plugin.PluginCache = new SiteCache(null, new CacheMock()); // Act + Assert PluginSettings settings = plugin.Settings; }
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")); }
public void GetJavascriptHtml_Should_Contain_Scripts_With_HeadJs() { // Arrange TextPlugin plugin = new TextPluginStub(); plugin.AddScript("pluginscript.js", "script1"); string expectedHtml = @"<script type=""text/javascript"">" + @"head.js({ ""script1"", ""pluginscript.js"" },function() { })" + "</script>\n"; // Act string actualHtml = plugin.GetJavascriptHtml(); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public void Settings_Should_Create_Instance_When_Repository_Has_No_Settings() { // Arrange CacheMock cache = new CacheMock(); ApplicationSettings appSettings = new ApplicationSettings(); Mock<IPluginCache> pluginCacheMock = new Mock<IPluginCache>(); RepositoryMock repository = new RepositoryMock(); 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.Values.Count(), Is.EqualTo(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); }