/// <summary>
		/// Saves all settings that are stored in the database, to the configuration table.
		/// </summary>
		/// <param name="model">Summary data containing the settings.</param>
		/// <exception cref="DatabaseException">An datastore error occurred while saving the configuration.</exception>
		public void SaveSiteSettings(SettingsViewModel model)
		{
			try
			{
				SiteSettings siteSettings = new SiteSettings();
				siteSettings.AllowedFileTypes = model.AllowedFileTypes;
				siteSettings.AllowUserSignup = model.AllowUserSignup;
				siteSettings.IsRecaptchaEnabled = model.IsRecaptchaEnabled;
				siteSettings.MarkupType = model.MarkupType;
				siteSettings.RecaptchaPrivateKey = model.RecaptchaPrivateKey;
				siteSettings.RecaptchaPublicKey = model.RecaptchaPublicKey;
				siteSettings.SiteUrl = model.SiteUrl;
				siteSettings.SiteName = model.SiteName;
				siteSettings.Theme = model.Theme;

				// v2.0
				siteSettings.OverwriteExistingFiles = model.OverwriteExistingFiles;
				siteSettings.HeadContent = model.HeadContent;
				siteSettings.MenuMarkup = model.MenuMarkup;

                // Pipeline
                siteSettings.EnableMailChimp = model.EnableMailChimp;
                siteSettings.MailChimpApiKey = model.MailChimpApiKey;
                siteSettings.MailChimpListId = model.MailChimpListId;

				Repository.SaveSiteSettings(siteSettings);
			}
			catch (DatabaseException ex)
			{
				throw new DatabaseException(ex, "An exception occurred while saving the site configuration.");
			}
		}
Example #2
0
		/// <summary>
		/// Installs Roadkill with default settings and the provided datastory type and connection string.
		/// </summary>
		public ActionResult Unattended(string datastoreType, string connectionString)
		{
			if (ApplicationSettings.Installed)
				return RedirectToAction("Index", "Home");

			SettingsViewModel settingsModel = new SettingsViewModel();
			settingsModel.DataStoreTypeName = datastoreType;
			settingsModel.ConnectionString = connectionString;
			settingsModel.AllowedFileTypes = "jpg,png,gif,zip,xml,pdf";
			settingsModel.AttachmentsFolder = "~/App_Data/Attachments";
			settingsModel.MarkupType = "Creole";
			settingsModel.Theme = "Responsive";
			settingsModel.UseObjectCache = true;
			settingsModel.UseBrowserCache = true;
			settingsModel.AdminEmail = "admin@localhost";
			settingsModel.AdminPassword = "******";
			settingsModel.AdminRoleName = "admins";
			settingsModel.EditorRoleName = "editors";
			settingsModel.SiteName = "my site";
			settingsModel.SiteUrl = "http://localhost";

			FinalizeInstall(settingsModel);

			return Content("Unattended installation complete");
		}
		public void savesitesettings_should_save_all_values()
		{
			// Arrange
			SettingsViewModel expectedSettings = new SettingsViewModel();
			expectedSettings.AllowedFileTypes = "AllowedFileTypes";
			expectedSettings.Theme = "Mytheme";
			expectedSettings.SiteName = "Mysitename";
			expectedSettings.SiteUrl = "SiteUrl";
			expectedSettings.RecaptchaPrivateKey = "RecaptchaPrivateKey";
			expectedSettings.RecaptchaPublicKey = "RecaptchaPublicKey";
			expectedSettings.MarkupType = "MarkupType";
			expectedSettings.IsRecaptchaEnabled = true;
			expectedSettings.OverwriteExistingFiles = true;
			expectedSettings.HeadContent = "some head content";
			expectedSettings.MenuMarkup = "some menu markup";

			// Act
			_settingsService.SaveSiteSettings(expectedSettings);
			SiteSettings actualSettings = _settingsService.GetSiteSettings();

			// Assert
			Assert.That(actualSettings.AllowedFileTypes, Is.EqualTo(expectedSettings.AllowedFileTypes));
			Assert.That(actualSettings.Theme, Is.EqualTo(expectedSettings.Theme));
			Assert.That(actualSettings.SiteName, Is.EqualTo(expectedSettings.SiteName));
			Assert.That(actualSettings.SiteUrl, Is.EqualTo(expectedSettings.SiteUrl));
			Assert.That(actualSettings.RecaptchaPrivateKey, Is.EqualTo(expectedSettings.RecaptchaPrivateKey));
			Assert.That(actualSettings.RecaptchaPublicKey, Is.EqualTo(expectedSettings.RecaptchaPublicKey));
			Assert.That(actualSettings.MarkupType, Is.EqualTo(expectedSettings.MarkupType));
			Assert.That(actualSettings.IsRecaptchaEnabled, Is.EqualTo(expectedSettings.IsRecaptchaEnabled));
			Assert.That(actualSettings.OverwriteExistingFiles, Is.EqualTo(expectedSettings.OverwriteExistingFiles));
			Assert.That(actualSettings.HeadContent, Is.EqualTo(expectedSettings.HeadContent));
			Assert.That(actualSettings.MenuMarkup, Is.EqualTo(expectedSettings.MenuMarkup));
		}
Example #4
0
		/// <summary>
		/// Saves all settings that are stored in the database, to the configuration table.
		/// </summary>
		/// <param name="model">Summary data containing the settings.</param>
		/// <exception cref="DatabaseException">An datastore error occurred while saving the configuration.</exception>
		public void SaveSiteSettings(SettingsViewModel model)
		{
			try
			{
				SiteSettings siteSettings = new SiteSettings();
				siteSettings.AllowedFileTypes = model.AllowedFileTypes;
				siteSettings.AllowUserSignup = model.AllowUserSignup;
				siteSettings.IsRecaptchaEnabled = model.IsRecaptchaEnabled;
				siteSettings.MarkupType = model.MarkupType;
				siteSettings.RecaptchaPrivateKey = model.RecaptchaPrivateKey;
				siteSettings.RecaptchaPublicKey = model.RecaptchaPublicKey;
				siteSettings.SiteUrl = model.SiteUrl;
				siteSettings.SiteName = model.SiteName;
				siteSettings.Theme = model.Theme;

				// v2.0
				siteSettings.OverwriteExistingFiles = model.OverwriteExistingFiles;
				siteSettings.HeadContent = model.HeadContent;
				siteSettings.MenuMarkup = model.MenuMarkup;

				var repository = _repositoryFactory.GetSettingsRepository(_applicationSettings.DatabaseName, _applicationSettings.ConnectionString);
				repository.SaveSiteSettings(siteSettings);
			}
			catch (DatabaseException ex)
			{
				throw new DatabaseException(ex, "An exception occurred while saving the site configuration.");
			}
		}
        /// <summary>
        /// The default settings page that displays the current Roadkill settings.
        /// </summary>
        /// <returns>A <see cref="SettingsViewModel"/> as the model.</returns>
        public ActionResult Index()
        {
            SiteSettings siteSettings = SettingsService.GetSiteSettings();
            SettingsViewModel model = new SettingsViewModel(ApplicationSettings, siteSettings);

            return View(model);
        }
Example #6
0
		/// <summary>
		/// The default settings page that displays the current Roadkill settings.
		/// </summary>
		/// <returns>A <see cref="SettingsViewModel"/> as the model.</returns>
		public ActionResult Index()
		{
			Configuration.SiteSettings siteSettings = SettingsService.GetSiteSettings();
			SettingsViewModel model = new SettingsViewModel(ApplicationSettings, siteSettings);
			model.SetSupportedDatabases(SettingsService.GetSupportedDatabases());

			return View(model);
		}
Example #7
0
		public override void Save(SettingsViewModel settings)
		{
			Saved = true;

			// The bare minimum needed to test the installer
			ApplicationSettings.ConnectionString = settings.ConnectionString;
			ApplicationSettings.DataStoreType = DataStoreType.ByName(settings.DataStoreTypeName);
			ApplicationSettings.UseBrowserCache = settings.UseBrowserCache;
			ApplicationSettings.UseObjectCache = settings.UseObjectCache;
		}
        public void Index_POST_Should_Accept_HttpPost_Only()
        {
            // Arrange
            SettingsViewModel model = new SettingsViewModel();

            // Act
            ViewResult result = _settingsController.Index(model) as ViewResult;

            // Assert
            _settingsController.AssertHttpPostOnly(x => x.Index(model));
        }
		public void install_should_not_add_adminuser_when_windows_auth_is_true()
		{
			// Arrange
			var model = new SettingsViewModel();
			model.UseWindowsAuth = true;

			// Act
			_installationService.Install(model);

			// Assert
			Assert.That(_installerRepository.AddAdminUserCalled, Is.False);
		}
Example #10
0
		/// <summary>
		/// Creates the database schema tables.
		/// </summary>
		/// <param name="model">The settings data.</param>
		/// <exception cref="DatabaseException">An datastore error occurred while creating the database tables.</exception>
		public void CreateTables(SettingsViewModel model)
		{
			try
			{
				DataStoreType dataStoreType = DataStoreType.ByName(model.DataStoreTypeName);
				Repository.Install(dataStoreType, model.ConnectionString, model.UseObjectCache);
			}
			catch (DatabaseException ex)
			{
				throw new DatabaseException(ex, "An exception occurred while creating the site schema tables.");
			}
		}
        public void Finalize_Should_Add_AdminUser_When_Windows_Auth_Is_False()
        {
            // Arrange
            SettingsViewModel existingModel = new SettingsViewModel();
            existingModel.UseWindowsAuth = false;
            SetMockDataStoreType(existingModel);

            // Act
            _installController.FinalizeInstall(existingModel);

            // Assert
            UserViewModel adminUser = _userService.ListAdmins().FirstOrDefault();
            Assert.That(adminUser, Is.Not.Null);
        }
        public void CreateTables_Calls_Repository_Install()
        {
            // Arrange
            SettingsViewModel model = new SettingsViewModel();
            model.DataStoreTypeName = "SQLite";
            model.ConnectionString = "Data Source=somefile.sqlite;";
            model.UseObjectCache = true;

            // Act
            _settingsService.CreateTables(model);

            // Assert
            Assert.That(_repository.InstalledConnectionString, Is.EqualTo(model.ConnectionString));
            Assert.That(_repository.InstalledDataStoreType, Is.EqualTo(DataStoreType.Sqlite));
            Assert.That(_repository.InstalledEnableCache, Is.EqualTo(model.UseObjectCache));
        }
		public void index_post_should_return_viewresult_and_save_settings()
		{
			// Arrange
			SettingsViewModel model = new SettingsViewModel();
			model.MenuMarkup = "some new markup";

			// Act
			ViewResult result = _settingsController.Index(model) as ViewResult;

			// Assert
			Assert.That(result, Is.Not.Null, "ViewResult");
			SettingsViewModel resultModel = result.ModelFromActionResult<SettingsViewModel>();
			Assert.That(resultModel, Is.Not.Null, "model");

			Assert.That(_settingsRepository.GetSiteSettings().MenuMarkup, Is.EqualTo("some new markup"));
		}
        public void Finalize_Should_Install_And_Save_Site_Settings()
        {
            // Arrange
            SettingsViewModel existingModel = new SettingsViewModel();
            existingModel.Theme = "ChewbaccaOnHolidayTheme";
            SetMockDataStoreType(existingModel);

            // Act
            _installController.FinalizeInstall(existingModel);

            // Assert
            RepositoryMock repository = (RepositoryMock) ObjectFactory.GetInstance<IRepository>();
            Assert.That(repository.Installed, Is.True);
            SiteSettings settings = _settingsService.GetSiteSettings();
            Assert.That(settings.Theme, Is.EqualTo("ChewbaccaOnHolidayTheme"));
        }
Example #15
0
		public ActionResult Index(SettingsViewModel model)
		{
			if (ModelState.IsValid)
			{
				_configReaderWriter.Save(model);
			
				_settingsService.SaveSiteSettings(model);
				_siteCache.RemoveMenuCacheItems();

				// Refresh the AttachmentsDirectoryPath using the absolute attachments path, as it's calculated in the constructor
				ApplicationSettings appSettings = _configReaderWriter.GetApplicationSettings();
				model.FillFromApplicationSettings(appSettings);
				model.UpdateSuccessful = true;
			}

			return View(model);
		}
		public void install_should_create_schema_add_new_admin_user_and_save_settings()
		{
			// Arrange
			var expectedModel = new SettingsViewModel()
			{
				ConnectionString = "connection string",
				DatabaseName = "MongoDb",

				AllowedFileTypes = "AllowedFileTypes",
				Theme = "Mytheme",
				SiteName = "Mysitename",
				SiteUrl = "SiteUrl",
				RecaptchaPrivateKey = "RecaptchaPrivateKey",
				RecaptchaPublicKey = "RecaptchaPublicKey",
				MarkupType = "MarkupType",
				IsRecaptchaEnabled = true,
				OverwriteExistingFiles = true,
				HeadContent = "some head content",
				MenuMarkup = "some menu markup",
			};

			// Act
			_installationService.Install(expectedModel);

			// Assert
			Assert.That(_installerRepository.AddAdminUserCalled, Is.True);
			Assert.That(_installerRepository.SaveSettingsCalled, Is.True);
			Assert.That(_installerRepository.CreateSchemaCalled, Is.True);

			Assert.That(_installerRepository.ConnectionString, Is.EqualTo(expectedModel.ConnectionString));
			Assert.That(_installerRepository.DatabaseName, Is.EqualTo(expectedModel.DatabaseName));

			SiteSettings siteSettings = _installerRepository.SiteSettings;
			Assert.That(siteSettings.AllowedFileTypes, Is.EqualTo(expectedModel.AllowedFileTypes));
			Assert.That(siteSettings.Theme, Is.EqualTo(expectedModel.Theme));
			Assert.That(siteSettings.SiteName, Is.EqualTo(expectedModel.SiteName));
			Assert.That(siteSettings.SiteUrl, Is.EqualTo(expectedModel.SiteUrl));
			Assert.That(siteSettings.RecaptchaPrivateKey, Is.EqualTo(expectedModel.RecaptchaPrivateKey));
			Assert.That(siteSettings.RecaptchaPublicKey, Is.EqualTo(expectedModel.RecaptchaPublicKey));
			Assert.That(siteSettings.MarkupType, Is.EqualTo(expectedModel.MarkupType));
			Assert.That(siteSettings.IsRecaptchaEnabled, Is.EqualTo(expectedModel.IsRecaptchaEnabled));
			Assert.That(siteSettings.OverwriteExistingFiles, Is.EqualTo(expectedModel.OverwriteExistingFiles));
			Assert.That(siteSettings.HeadContent, Is.EqualTo(expectedModel.HeadContent));
			Assert.That(siteSettings.MenuMarkup, Is.EqualTo(expectedModel.MenuMarkup));
		}
Example #17
0
		public void Install(SettingsViewModel model)
		{
			try
			{
				IInstallerRepository installerRepository = _getRepositoryFunc(model.DatabaseName, model.ConnectionString);
				installerRepository.CreateSchema();

				if (model.UseWindowsAuth == false)
				{
					installerRepository.AddAdminUser(model.AdminEmail, "admin", model.AdminPassword);
				}

				SiteSettings siteSettings = new SiteSettings();
				siteSettings.AllowedFileTypes = model.AllowedFileTypes;
				siteSettings.AllowUserSignup = model.AllowUserSignup;
				siteSettings.IsRecaptchaEnabled = model.IsRecaptchaEnabled;
				siteSettings.MarkupType = model.MarkupType;
				siteSettings.RecaptchaPrivateKey = model.RecaptchaPrivateKey;
				siteSettings.RecaptchaPublicKey = model.RecaptchaPublicKey;
				siteSettings.SiteUrl = model.SiteUrl;
				siteSettings.SiteName = model.SiteName;
				siteSettings.Theme = model.Theme;

				// v2.0
				siteSettings.OverwriteExistingFiles = model.OverwriteExistingFiles;
				siteSettings.HeadContent = model.HeadContent;
				siteSettings.MenuMarkup = model.MenuMarkup;
				installerRepository.SaveSettings(siteSettings);

				// Attachments handler needs re-registering
				var appSettings = Locator.GetInstance<ApplicationSettings>();
				var fileService = Locator.GetInstance<IFileService>();
				AttachmentRouteHandler.RegisterRoute(appSettings, RouteTable.Routes, fileService);
			}
			catch (DatabaseException ex)
			{
				throw new DatabaseException(ex, "An exception occurred while saving the site configuration.");
			}
		}
Example #18
0
		/// <summary>
		/// Resets DataStoreType.AllTypes to have just one type, "mock datastore"
		/// </summary>
		/// <param name="existingModel"></param>
		private void SetMockDataStoreType(SettingsViewModel existingModel)
		{
			string typeName = typeof(RepositoryMock).AssemblyQualifiedName;
			DataStoreType mockDataStoreType = new DataStoreType("mock datastore", "mock", typeName);
			List<DataStoreType> datastoreTypes = new List<DataStoreType>() { mockDataStoreType };
			DataStoreType.AllTypes = datastoreTypes;

			existingModel.DataStoreTypeName = "mock datastore";
		}
Example #19
0
		public void UnattendedSetup_Should_Add_Admin_User_And_Set_Default_Site_Settings()
		{
			// Arrange
			SettingsViewModel existingModel = new SettingsViewModel();
			SetMockDataStoreType(existingModel);

			// Act
			ActionResult result = _installController.Unattended("mock datastore", "fake connection string");

			// Assert
			ContentResult contentResult = result.AssertResultIs<ContentResult>();
			Assert.That(contentResult.Content, Is.EqualTo("Unattended installation complete"));

			UserViewModel adminUser = _userService.ListAdmins().FirstOrDefault(); // check admin
			Assert.That(adminUser, Is.Not.Null);

			ApplicationSettings appSettings = _configReaderWriter.ApplicationSettings; // check settings
			Assert.That(appSettings.DataStoreType.Name, Is.EqualTo("mock datastore"));
			Assert.That(appSettings.ConnectionString, Is.EqualTo("fake connection string"));
			Assert.That(appSettings.UseObjectCache, Is.True);
			Assert.That(appSettings.UseBrowserCache, Is.True);

			SiteSettings settings = _settingsService.GetSiteSettings();		
			Assert.That(settings.AllowedFileTypes, Is.EqualTo("jpg,png,gif,zip,xml,pdf"));
			Assert.That(settings.MarkupType, Is.EqualTo("Creole"));
			Assert.That(settings.Theme, Is.EqualTo("Responsive"));
			Assert.That(settings.SiteName, Is.EqualTo("my site"));
			Assert.That(settings.SiteUrl, Is.EqualTo("http://localhost"));
		}
Example #20
0
		public void Finalize_Should_Save_Config_Settings()
		{
			// Arrange
			SettingsViewModel existingModel = new SettingsViewModel();
			existingModel.Theme = "Responsive"; // don't test everything, that's done elsewhere in the ConfigReaderWriterTests
			SetMockDataStoreType(existingModel);

			// Act
			_installController.FinalizeInstall(existingModel);

			// Assert
			Assert.That(_configReaderWriter.Saved, Is.True);
		}
Example #21
0
		public void Finalize_Should_Set_PublicSite_And_IgnoreSearchErrors_To_True()
		{
			// Arrange
			SettingsViewModel existingModel = new SettingsViewModel();
			SetMockDataStoreType(existingModel);

			// Act
			_installController.FinalizeInstall(existingModel);

			// Assert
			Assert.That(existingModel.IgnoreSearchIndexErrors, Is.True);
			Assert.That(existingModel.IsPublicSite, Is.True);
		}
Example #22
0
		public void Step5_Should_Reset_Install_State_And_Add_ModelState_Error_When_Exception_Is_Thrown()
		{
			// Arrange
			string exceptionMessage = RepositoryThrowsExceptionsMock.ExceptionMessage;

			SettingsViewModel existingModel = new SettingsViewModel();
			SetMockDataStoreType(existingModel);
			DataStoreType.AllTypes.First().CustomRepositoryType = typeof(RepositoryThrowsExceptionsMock).AssemblyQualifiedName;

			// Act
			ActionResult result = _installController.Step5(existingModel);

			// Assert
			Assert.That(_configReaderWriter.InstallStateReset, Is.True);

			string error = _installController.ModelState["An error ocurred installing"].Errors[0].ErrorMessage;
			Assert.That(error, Is.StringStarting(exceptionMessage), error);
		}
Example #23
0
		public void Step5_Should_Finalize_Setup()
		{
			// Arrange
			SettingsViewModel existingModel = new SettingsViewModel();
			SetMockDataStoreType(existingModel);

			// Act
			ActionResult result = _installController.Step5(existingModel);

			// Assert
			ViewResult viewResult = result.AssertResultIs<ViewResult>();
			viewResult.AssertViewRendered();

			SettingsViewModel model = viewResult.ModelFromActionResult<SettingsViewModel>();
			Assert.NotNull(model, "Null model");
		}
Example #24
0
		public void Step4_Should_Set_Model_Defaults_For_Attachments_Theme_And_Cache()
		{
			// Arrange
			SettingsViewModel existingModel = new SettingsViewModel();

			// Act
			ActionResult result = _installController.Step4(existingModel);

			// Assert
			ViewResult viewResult = result.AssertResultIs<ViewResult>();
			viewResult.AssertViewRendered();

			SettingsViewModel model = viewResult.ModelFromActionResult<SettingsViewModel>();
			Assert.NotNull(model, "Null model");

			Assert.That(model.AllowedFileTypes, Is.EqualTo("jpg,png,gif,zip,xml,pdf"));
			Assert.That(model.AttachmentsFolder, Is.EqualTo("~/App_Data/Attachments"));
			Assert.That(model.MarkupType, Is.EqualTo("Creole"));
			Assert.That(model.Theme, Is.EqualTo("Responsive"));
			Assert.That(model.UseObjectCache, Is.True);
			Assert.That(model.UseBrowserCache, Is.False);
		}
Example #25
0
		public void Step3b_Should_Set_Model_Default_Roles_And_LDAP_ConnectionString()
		{
			// Arrange
			SettingsViewModel existingModel = new SettingsViewModel();

			// Act
			ActionResult result = _installController.Step3b(existingModel);

			// Assert
			ViewResult viewResult = result.AssertResultIs<ViewResult>();
			viewResult.AssertViewRendered();

			SettingsViewModel model = viewResult.ModelFromActionResult<SettingsViewModel>();
			Assert.NotNull(model, "Null model");

			Assert.That(model.AdminRoleName, Is.EqualTo("Admin"));
			Assert.That(model.EditorRoleName, Is.EqualTo("Editor"));
			Assert.That(model.LdapConnectionString, Is.EqualTo("LDAP://"));
		}
Example #26
0
		public void Step3b_Should_Return_WindowsAuth_ViewResult_When_WindowsAuth_Is_True()
		{
			// Arrange
			SettingsViewModel existingModel = new SettingsViewModel();
			existingModel.UseWindowsAuth = true;

			// Act
			ActionResult result = _installController.Step3b(existingModel);

			// Assert
			ViewResult viewResult = result.AssertResultIs<ViewResult>();
			Assert.That(viewResult.ViewName, Is.EqualTo("Step3WindowsAuth"));
		}
Example #27
0
		public void Step3_Should_Return_ViewResult_With_SettingsViewModel()
		{
			// Arrange
			SettingsViewModel existingModel = new SettingsViewModel();
			existingModel.ConnectionString = "connectionstring";
			existingModel.SiteUrl = "siteurl";
			existingModel.SiteName = "sitename";

			// Act
			ActionResult result = _installController.Step3(existingModel);

			// Assert
			ViewResult viewResult = result.AssertResultIs<ViewResult>();
			viewResult.AssertViewRendered();

			SettingsViewModel model = viewResult.ModelFromActionResult<SettingsViewModel>();
			Assert.NotNull(model, "Null model");

			/* The view is responsible for passing these across, 
			   but this gives a rough indication that no data is lost between steps */
			Assert.That(model.ConnectionString, Is.EqualTo(existingModel.ConnectionString));
			Assert.That(model.SiteUrl, Is.EqualTo(existingModel.SiteUrl));
			Assert.That(model.SiteName, Is.EqualTo(existingModel.SiteName));
		}
        public void SaveSiteSettings_Should_Persist_All_Values()
        {
            // Arrange
            ApplicationSettings appSettings = new ApplicationSettings();
            SiteSettings siteSettings = new SiteSettings()
            {
                AllowedFileTypes = "jpg, png, gif",
                AllowUserSignup = true,
                IsRecaptchaEnabled = true,
                MarkupType = "markuptype",
                RecaptchaPrivateKey = "privatekey",
                RecaptchaPublicKey = "publickey",
                SiteName = "sitename",
                SiteUrl = "siteurl",
                Theme = "theme",
            };
            SettingsViewModel validConfigSettings = new SettingsViewModel()
            {
                AllowedFileTypes = "jpg, png, gif",
                AllowUserSignup = true,
                IsRecaptchaEnabled = true,
                MarkupType = "markuptype",
                RecaptchaPrivateKey = "privatekey",
                RecaptchaPublicKey = "publickey",
                SiteName = "sitename",
                SiteUrl = "siteurl",
                Theme = "theme",
            };

            RepositoryMock repository = new RepositoryMock();

            DependencyManager iocSetup = new DependencyManager(appSettings, repository, new UserContext(null)); // context isn't used
            iocSetup.Configure();
            SettingsService settingsService = new SettingsService(appSettings, repository);

            // Act
            settingsService.SaveSiteSettings(validConfigSettings);

            // Assert
            SiteSettings actualSettings = settingsService.GetSiteSettings();

            Assert.That(actualSettings.AllowedFileTypes.Contains("jpg"), "AllowedFileTypes jpg");
            Assert.That(actualSettings.AllowedFileTypes.Contains("gif"), "AllowedFileTypes gif");
            Assert.That(actualSettings.AllowedFileTypes.Contains("png"), "AllowedFileTypes png");
            Assert.That(actualSettings.AllowUserSignup, Is.True, "AllowUserSignup");
            Assert.That(actualSettings.IsRecaptchaEnabled, Is.True, "IsRecaptchaEnabled");
            Assert.That(actualSettings.MarkupType, Is.EqualTo("markuptype"), "MarkupType");
            Assert.That(actualSettings.RecaptchaPrivateKey, Is.EqualTo("privatekey"), "RecaptchaPrivateKey");
            Assert.That(actualSettings.RecaptchaPublicKey, Is.EqualTo("publickey"), "RecaptchaPublicKey");
            Assert.That(actualSettings.SiteName, Is.EqualTo("sitename"), "SiteName");
            Assert.That(actualSettings.SiteUrl, Is.EqualTo("siteurl"), "SiteUrl");
            Assert.That(actualSettings.Theme, Is.EqualTo("theme"), "Theme");
        }
Example #29
0
		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");
		}
		/// <summary>
		/// Saves the configuration settings. This will save a subset of the <see cref="SettingsViewModel" /> based on
		/// the values that match those found in the <see cref="RoadkillSection" />
		/// </summary>
		/// <param name="settings">The application settings.</param>
		/// <exception cref="InstallerException">An exception occurred while updating the settings to the web.config</exception>
		public override void Save(SettingsViewModel settings)
		{
			try
			{
				if (settings.UseWindowsAuth)
					WriteConfigForWindowsAuth();
				else
					WriteConfigForFormsAuth();

				// Create a "Roadkill" connection string, or use the existing one if it exists.
				ConnectionStringSettings roadkillConnection = new ConnectionStringSettings("Roadkill", settings.ConnectionString);

				if (_config.ConnectionStrings.ConnectionStrings["Roadkill"] == null)
					_config.ConnectionStrings.ConnectionStrings.Add(roadkillConnection);
				else
					_config.ConnectionStrings.ConnectionStrings["Roadkill"].ConnectionString = settings.ConnectionString;

				// The roadkill section
				DataStoreType dataStoreType = DataStoreType.ByName(settings.DataStoreTypeName);
				RoadkillSection section = _config.GetSection("roadkill") as RoadkillSection;
				section.AdminRoleName = settings.AdminRoleName;
				section.AttachmentsFolder = settings.AttachmentsFolder;
				section.AzureContainer = settings.AzureContainer;
				section.UseObjectCache = settings.UseObjectCache;
				section.UseBrowserCache = settings.UseBrowserCache;
				section.ConnectionStringName = "Roadkill";
				section.DataStoreType = dataStoreType.Name;
				section.EditorRoleName = settings.EditorRoleName;
				section.LdapConnectionString = settings.LdapConnectionString;
				section.LdapUsername = settings.LdapUsername;
				section.LdapPassword = settings.LdapPassword;
				section.RepositoryType = dataStoreType.CustomRepositoryType;
				section.UseWindowsAuthentication = settings.UseWindowsAuth;
				section.Version = ApplicationSettings.FileVersion.ToString();

				// For first time installs: these need to be explicit as the DefaultValue="" in the attribute doesn't determine the value when saving.
				section.IsPublicSite = settings.IsPublicSite;
				section.IgnoreSearchIndexErrors = settings.IgnoreSearchIndexErrors;	
				section.Installed = true;

				_config.Save(ConfigurationSaveMode.Minimal);
			}
			catch (ConfigurationErrorsException ex)
			{
				throw new InstallerException(ex, "An exception occurred while updating the settings to the web.config");
			}
		}