public ActionResult Edit(PluginViewModel model) { TextPlugin plugin = _pluginFactory.GetTextPlugin(model.Id); if (plugin == null) return RedirectToAction("Index"); // Update the plugin settings with the values from the summary plugin.Settings.IsEnabled = model.IsEnabled; foreach (SettingValue summaryValue in model.SettingValues) { SettingValue pluginValue = plugin.Settings.Values.FirstOrDefault(x => x.Name == summaryValue.Name); if (pluginValue != null) pluginValue.Value = summaryValue.Value; } // Update the plugin last saved date - this is important for 304 modified tracking // when the browser caching option is turned on. SiteSettings settings = SettingsService.GetSiteSettings(); settings.PluginLastSaveDate = DateTime.UtcNow; SettingsViewModel settingsViewModel = new SettingsViewModel(ApplicationSettings, settings); SettingsService.SaveSiteSettings(settingsViewModel); // Save and clear the cached settings _repository.SaveTextPluginSettings(plugin); _siteCache.RemovePluginSettings(plugin); // Clear all other caches if the plugin has been enabled or disabled. _viewModelCache.RemoveAll(); _listCache.RemoveAll(); return RedirectToAction("Index"); }
public void constructor_should_create_settingvalues() { // Arrange + Act PluginViewModel model = new PluginViewModel(); // Assert Assert.That(model.SettingValues, Is.Not.Null); }
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 ActionResult Edit(string id) { // Guards if (string.IsNullOrEmpty(id)) return RedirectToAction("Index"); TextPlugin plugin = _pluginFactory.GetTextPlugin(id); if (plugin == null) return RedirectToAction("Index"); PluginViewModel model = new PluginViewModel() { Id = plugin.Id, DatabaseId = plugin.DatabaseId, Name = plugin.Name, Description = plugin.Description, }; // Try to load the settings from the database, fall back to defaults model.SettingValues = new List<SettingValue>(plugin.Settings.Values); model.IsEnabled = plugin.Settings.IsEnabled; return View(model); }
public void Edit_POST_Should_Save_Setting_Values_To_Repository_From_Model_And_Clear_SiteCache() { // Arrange _pageViewModelCache.Add(1, new PageViewModel()); // dummmy items _listCache.Add("a key", new List<string>() { "1", "2" }); TextPluginStub plugin = new TextPluginStub(); plugin.Repository = _repository; plugin.PluginCache = _siteCache; plugin.Settings.SetValue("name1", "default-value1"); plugin.Settings.SetValue("name2", "default-value2"); _pluginFactory.RegisterTextPlugin(plugin); PluginViewModel model = new PluginViewModel(); model.Id = plugin.Id; model.SettingValues = new List<SettingValue>(); model.SettingValues.Add(new SettingValue() { Name = "name1", Value = "new-value1" }); model.SettingValues.Add(new SettingValue() { Name = "name2", Value = "new-value2" }); // Act ViewResult result = _controller.Edit(model) as ViewResult; // Assert List<SettingValue> values = _repository.TextPlugins[0].Settings.Values.ToList(); Assert.That(values[0].Value, Is.EqualTo("new-value1")); Assert.That(values[1].Value, Is.EqualTo("new-value2")); Assert.That(_memoryCache.Count(), Is.EqualTo(0)); }