/// <summary>
        /// Tests the database connection, changing the current registered repository.
        /// </summary>
        /// <param name="connectionString">The connection string.</param>
        /// <returns>Any error messages or an empty string if no errors occurred.</returns>
        public static string TestDbConnection(string connectionString, string databaseType)
        {
            try
            {
                DataStoreType dataStoreType = DataStoreType.ByName(databaseType);
                if (dataStoreType == null)
                {
                    dataStoreType = DataStoreType.ByName("SQLServer2005");
                }

                IRepository repository = ChangeRepository(dataStoreType, connectionString, false);
                repository.TestConnection(dataStoreType, connectionString);
                return("");
            }
            catch (Exception e)
            {
                return(e.ToString());
            }
            finally
            {
                // Restore to their previous state
                ApplicationSettings appSettings = ObjectFactory.GetInstance <ApplicationSettings>();
                IRepository         repository  = ChangeRepository(appSettings.DataStoreType, appSettings.ConnectionString, false);
            }
        }
Exemple #2
0
        public void Configuration_Page_Shows_All_Settings()
        {
            // Arrange
            LoginAsAdmin();

            // Act
            Driver.FindElement(By.CssSelector("a[href='/settings']")).Click();

            // Assert
            Assert.That(Driver.ElementValue("#SiteName"), Is.EqualTo("Acceptance Tests"));
            Assert.That(Driver.ElementValue("#SiteUrl"), Is.EqualTo("http://*****:*****@"~/App_Data/Attachments"));
            Assert.That(Driver.ElementValue("#AllowedFileTypes"), Is.EqualTo("jpg,png,gif,zip,xml,pdf"));

            Assert.False(Driver.IsCheckboxChecked("UseWindowsAuth"));
            Assert.True(Driver.IsCheckboxChecked("AllowUserSignup"));
            Assert.False(Driver.IsCheckboxChecked("IsRecaptchaEnabled"));
            Assert.False(Driver.IsCheckboxChecked("UseObjectCache"));
            Assert.False(Driver.IsCheckboxChecked("UseBrowserCache"));

            Assert.That(Driver.FindElements(By.CssSelector("#DataStoreTypeName option")).Count, Is.EqualTo(DataStoreType.AllTypes.Count()));
            SelectElement element = new SelectElement(Driver.FindElement(By.CssSelector("#DataStoreTypeName")));

            Assert.That(element.SelectedOption.GetAttribute("value"), Is.EqualTo(DataStoreType.ByName("SqlServer2012").Name));
            Assert.That(Driver.SelectedIndex("#MarkupType"), Is.EqualTo(0));
            Assert.That(Driver.SelectedIndex("#Theme"), Is.EqualTo(3));
            Assert.False(Driver.IsCheckboxChecked("OverwriteExistingFiles"));
            Assert.That(Driver.ElementValue("#HeadContent"), Is.EqualTo(""));
            Assert.That(Driver.ElementValue("#MenuMarkup"), Is.EqualTo("* %mainpage%\r\n* %categories%\r\n* %allpages%\r\n* %newpage%\r\n* %managefiles%\r\n* %sitesettings%\r\n\r\n"));
        }
        internal void FinalizeInstall(SettingsViewModel model)
        {
            // The name as a string is passed through each step, so parse it
            DataStoreType dataStoreType = DataStoreType.ByName(model.DataStoreTypeName);

            model.DataStoreTypeName = dataStoreType.Name;

            // Update all repository references for the dependencies of this class
            // (changing the For() in StructureMap won't do this as the references have already been created).
            _repository = RepositoryManager.ChangeRepository(dataStoreType, model.ConnectionString, model.UseObjectCache);
            UserService.UpdateRepository(_repository);
            _settingsService.UpdateRepository(_repository);
            _searchService.UpdateRepository(_repository);

            // Default these two properties for installations
            model.IgnoreSearchIndexErrors = true;
            model.IsPublicSite            = true;

            // Update the web.config first, so all connections can be referenced.
            _configReaderWriter.Save(model);

            // Create the roadkill schema and save the configuration settings
            _settingsService.CreateTables(model);
            _settingsService.SaveSiteSettings(model);

            // Add a user if we're not using AD.
            if (!model.UseWindowsAuth)
            {
                UserService.AddUser(model.AdminEmail, "admin", model.AdminPassword, true, false);
            }

            // Create a blank search index
            _searchService.CreateIndex();
        }
Exemple #4
0
        public void ByName_Should_Throw_DatabaseException_If_DataStoreType_Not_Found()
        {
            // Arrange
            IEnumerable <DataStoreType> dataStoreTypes = DataStoreType.AllTypes;

            // Act + Assert
            DataStoreType datastoreType = DataStoreType.ByName("thunderbird");
        }
        /// <summary>
        /// Gets the current application settings, which is usually cached settings from the <see cref="Load" /> method.
        /// </summary>
        /// <returns>
        /// A new <see cref="ApplicationSettings" /> instance
        /// </returns>
        public override ApplicationSettings GetApplicationSettings()
        {
            ApplicationSettings appSettings = new ApplicationSettings();

            appSettings.AdminRoleName         = _section.AdminRoleName;
            appSettings.AttachmentsFolder     = _section.AttachmentsFolder;
            appSettings.AttachmentsRoutePath  = _section.AttachmentsRoutePath;
            appSettings.AzureConnectionString = _section.AzureConnectionString;
            appSettings.AzureContainer        = _section.AzureContainer;

            appSettings.ConnectionStringName = _section.ConnectionStringName;
            appSettings.ConnectionString     = _config.ConnectionStrings.ConnectionStrings[_section.ConnectionStringName].ConnectionString;
            if (string.IsNullOrEmpty(appSettings.ConnectionString))
            {
                appSettings.ConnectionString = ConfigurationManager.ConnectionStrings[_section.ConnectionStringName].ConnectionString;
            }

            if (string.IsNullOrEmpty(appSettings.ConnectionString))
            {
                Log.Warn("ConnectionString property is null/empty.");
            }

            // Ignore the legacy useCache and cacheText section keys, as the behaviour has changed.
            appSettings.UseObjectCache  = _section.UseObjectCache;
            appSettings.UseBrowserCache = _section.UseBrowserCache;

            // Look for the legacy database type key
            string dataStoreType = _section.DataStoreType;

            if (string.IsNullOrEmpty(dataStoreType) && !string.IsNullOrEmpty(_section.DatabaseType))
            {
                dataStoreType = _section.DatabaseType;
            }

            appSettings.LoggingTypes            = _section.Logging;
            appSettings.LogErrorsOnly           = _section.LogErrorsOnly;
            appSettings.DataStoreType           = DataStoreType.ByName(dataStoreType);
            appSettings.ConnectionStringName    = _section.ConnectionStringName;
            appSettings.EditorRoleName          = _section.EditorRoleName;
            appSettings.IgnoreSearchIndexErrors = _section.IgnoreSearchIndexErrors;
            appSettings.IsPublicSite            = _section.IsPublicSite;
            appSettings.Installed                = _section.Installed;
            appSettings.LdapConnectionString     = _section.LdapConnectionString;
            appSettings.LdapUsername             = _section.LdapUsername;
            appSettings.LdapPassword             = _section.LdapPassword;
            appSettings.RepositoryType           = _section.RepositoryType;
            appSettings.UseAzureFileStorage      = _section.UseAzureFileStorage;
            appSettings.UseHtmlWhiteList         = _section.UseHtmlWhiteList;
            appSettings.UserServiceType          = _section.UserServiceType;
            appSettings.UseWindowsAuthentication = _section.UseWindowsAuthentication;
            appSettings.UpgradeRequired          = UpgradeChecker.IsUpgradeRequired(_section.Version);

            appSettings.UseGoogleAnalytics = _section.UseGoogleAnalytics;
            appSettings.GAName             = _section.GAName;
            appSettings.GANumber           = _section.GANumber;

            return(appSettings);
        }
        /// <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();
                section.UseGoogleAnalytics = settings.UseGoogleAnalytics;
                section.GAName             = settings.GAName;
                section.GANumber           = settings.GANumber;

                // 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");
            }
        }
        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;
        }
Exemple #8
0
        public void ByName_Should_Find_DataStoreType_And_Be_Case_Insensitive()
        {
            // Arrange
            IEnumerable <DataStoreType> dataStoreTypes = DataStoreType.AllTypes;

            // Act
            DataStoreType datastoreType = DataStoreType.ByName("mOngoDB");

            // Assert
            Assert.That(datastoreType.Name, Is.EqualTo("MongoDB"));
        }
 /// <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.");
     }
 }
Exemple #10
0
        public void Schema_Upgrade_Should_Contain_SQL(string dbType)
        {
            // Arrange
            SchemaBase    schema    = DataStoreType.ByName(dbType).Schema;
            DbCommandStub dbCommand = new DbCommandStub();

            // Act
            schema.Upgrade(dbCommand);

            // Assert
            Assert.That(dbCommand.CommandText, Is.StringContaining("CREATE"));
        }