public void GetApplicationSettings_Should_Have_Correct_Key_Mappings_And_Values()
        {
            // Arrange
            string configFilePath = GetConfigPath("test.config");

            // Act
            FullTrustConfigReaderWriter configManager = new FullTrustConfigReaderWriter(configFilePath);
            ApplicationSettings appSettings = configManager.GetApplicationSettings();

            // Assert
            Assert.That(appSettings.AdminRoleName, Is.EqualTo("Admin-test"), "AdminRoleName");
            Assert.That(appSettings.AttachmentsRoutePath, Is.EqualTo("AttachmentsRoutePathTest"), "AttachmentsRoutePath");
            Assert.That(appSettings.AttachmentsFolder, Is.EqualTo("/Attachments-test"), "AttachmentsFolder");
            Assert.That(appSettings.UseObjectCache, Is.True, "UseObjectCache");
            Assert.That(appSettings.UseBrowserCache, Is.True, "UseBrowserCache");
            Assert.That(appSettings.ConnectionStringName, Is.EqualTo("Roadkill-test"), "ConnectionStringName");
            Assert.That(appSettings.DataStoreType, Is.EqualTo(DataStoreType.Sqlite), "DatabaseType");
            Assert.That(appSettings.EditorRoleName, Is.EqualTo("Editor-test"), "EditorRoleName");
            Assert.That(appSettings.IgnoreSearchIndexErrors, Is.True, "IgnoreSearchIndexErrors");
            Assert.That(appSettings.Installed, Is.True, "Installed");
            Assert.That(appSettings.IsPublicSite, Is.False, "IsPublicSite");
            Assert.That(appSettings.LdapConnectionString, Is.EqualTo("ldapstring-test"), "LdapConnectionString");
            Assert.That(appSettings.LdapPassword, Is.EqualTo("ldappassword-test"), "LdapPassword");
            Assert.That(appSettings.LdapUsername, Is.EqualTo("ldapusername-test"), "LdapUsername");
            Assert.That(appSettings.LoggingTypes, Is.EqualTo("All"), "LoggingType");
            Assert.That(appSettings.LogErrorsOnly, Is.False, "LogErrorsOnly");
            Assert.That(appSettings.UseHtmlWhiteList, Is.EqualTo(false), "UseHtmlWhiteList");
            Assert.That(appSettings.UserServiceType, Is.EqualTo("DefaultUserManager-test"), "DefaultUserManager");
            Assert.That(appSettings.UseWindowsAuthentication, Is.False, "UseWindowsAuthentication");
        }
Пример #2
0
        public void Configuration(IAppBuilder app)
        {
            // Get the settings from the web.config
            ConfigReaderWriter configReader = new FullTrustConfigReaderWriter("");
            ApplicationSettings applicationSettings = configReader.GetApplicationSettings();

            // Configure StructureMap dependencies
            var iocSetup = new DependencyManager(applicationSettings);
            iocSetup.Configure();
            iocSetup.ConfigureMvc();

            // Logging
            Log.ConfigureLogging(applicationSettings);

            // Filters
            GlobalFilters.Filters.Add(new HandleErrorAttribute());

            // Areas are used for:
            // - Site settings (for a cleaner view structure)
            // This should be called before the other routes, for some reason.
            AreaRegistration.RegisterAllAreas();

            // Register routes and JS/CSS bundles
            Routing.RegisterApi(GlobalConfiguration.Configuration);
            Routing.Register(RouteTable.Routes);

            // Custom view engine registration (to add directory search paths for Theme views)
            ExtendedRazorViewEngine.Register();

            app.UseWebApi(new HttpConfiguration());

            Log.Information("Application started");
        }
        public void GetApplicationSettings_Should_Find_Connection_Value_From_Connection_Setting()
        {
            // Arrange
            string configFilePath = GetConfigPath("test.config");

            // Act
            FullTrustConfigReaderWriter configManager = new FullTrustConfigReaderWriter(configFilePath);
            ApplicationSettings appSettings = configManager.GetApplicationSettings();

            // Assert
            Assert.That(appSettings.ConnectionString, Is.EqualTo("connectionstring-test"), "ConnectionStringName");
        }
        public void GetApplicationSettings_Should_Use_Default_Values_When_Optional_Settings_Have_Missing_Values()
        {
            // Arrange
            string configFilePath = GetConfigPath("test-optional-values.config");

            // Act
            FullTrustConfigReaderWriter configManager = new FullTrustConfigReaderWriter(configFilePath);
            ApplicationSettings appSettings = configManager.GetApplicationSettings();

            // Assert
            Assert.That(appSettings.AttachmentsRoutePath, Is.EqualTo("Attachments"), "AttachmentsRoutePath");
            Assert.That(appSettings.DataStoreType, Is.EqualTo(DataStoreType.SqlServer2005), "DatabaseType");
            Assert.That(appSettings.IgnoreSearchIndexErrors, Is.False, "IgnoreSearchIndexErrors");
            Assert.That(appSettings.IsPublicSite, Is.True, "IsPublicSite");
            Assert.That(appSettings.LdapConnectionString, Is.EqualTo(""), "LdapConnectionString");
            Assert.That(appSettings.LdapPassword, Is.EqualTo(""), "LdapPassword");
            Assert.That(appSettings.LdapUsername, Is.EqualTo(""), "LdapUsername");
            Assert.That(appSettings.LoggingTypes, Is.EqualTo("None"), "LoggingType");
            Assert.That(appSettings.LogErrorsOnly, Is.True, "LoggingType");
            Assert.That(appSettings.UseHtmlWhiteList, Is.EqualTo(true), "UseHtmlWhiteList");
            Assert.That(appSettings.UserServiceType, Is.EqualTo(""), "DefaultUserManager");
        }
		public void Save_Should_Persist_All_ApplicationSettings()
		{
			// Arrange
			string configFilePath = GetConfigPath("test-empty.config");
			SettingsViewModel viewModel = new SettingsViewModel()
			{
				AdminRoleName = "admin role name",
				AttachmentsFolder = @"c:\AttachmentsFolder",
				UseObjectCache = true,
				UseBrowserCache = true,
				ConnectionString = "connection string",
				DatabaseName = "MongoDB",
				EditorRoleName = "editor role name",
				LdapConnectionString = "ldap connection string",
				LdapUsername = "******",
				LdapPassword = "******",
				UseWindowsAuth = true,
				IsPublicSite = false,
				IgnoreSearchIndexErrors = false
			};

			// Act
			FullTrustConfigReaderWriter configManager = new FullTrustConfigReaderWriter(configFilePath);
			configManager.Save(viewModel);

			ApplicationSettings appSettings = configManager.GetApplicationSettings();

			// Assert
			Assert.That(appSettings.AdminRoleName, Is.EqualTo(viewModel.AdminRoleName), "AdminRoleName");
			Assert.That(appSettings.AttachmentsFolder, Is.EqualTo(viewModel.AttachmentsFolder), "AttachmentsFolder");
			Assert.That(appSettings.UseObjectCache, Is.EqualTo(viewModel.UseObjectCache), "UseObjectCache");
			Assert.That(appSettings.UseBrowserCache, Is.EqualTo(viewModel.UseBrowserCache), "UseBrowserCache");
			Assert.That(appSettings.ConnectionString, Is.EqualTo(viewModel.ConnectionString), "ConnectionStringName");
			Assert.That(appSettings.DatabaseName, Is.EqualTo("MongoDB"), "DatabaseName");
			Assert.That(appSettings.EditorRoleName, Is.EqualTo(viewModel.EditorRoleName), "EditorRoleName");
			Assert.That(appSettings.IgnoreSearchIndexErrors, Is.EqualTo(viewModel.IgnoreSearchIndexErrors), "IgnoreSearchIndexErrors");
			Assert.That(appSettings.IsPublicSite, Is.EqualTo(viewModel.IsPublicSite), "IsPublicSite");
			Assert.That(appSettings.LdapConnectionString, Is.EqualTo(viewModel.LdapConnectionString), "LdapConnectionString");
			Assert.That(appSettings.LdapPassword, Is.EqualTo(viewModel.LdapPassword), "LdapPassword");
			Assert.That(appSettings.LdapUsername, Is.EqualTo(viewModel.LdapUsername), "LdapUsername");
			Assert.That(appSettings.UseWindowsAuthentication, Is.EqualTo(viewModel.UseWindowsAuth), "UseWindowsAuthentication");
			Assert.That(appSettings.Installed, Is.True, "Installed");
		}
		public void getapplicationsettings_should_use_default_values_when_optional_settings_have_missing_values()
		{
			// Arrange
			string configFilePath = GetConfigPath("test-optional-values.config");

			// Act
			FullTrustConfigReaderWriter configManager = new FullTrustConfigReaderWriter(configFilePath);
			ApplicationSettings appSettings = configManager.GetApplicationSettings();

			// Assert
			Assert.That(appSettings.AttachmentsRoutePath, Is.EqualTo("Attachments"), "AttachmentsRoutePath");
			Assert.That(appSettings.ApiKeys, Is.Not.Null.And.Empty, "ApiKeys");
			Assert.That(appSettings.DatabaseName, Is.EqualTo("SqlServer2008"), "DatabaseName");
			Assert.That(appSettings.IgnoreSearchIndexErrors, Is.False, "IgnoreSearchIndexErrors");
			Assert.That(appSettings.IsPublicSite, Is.True, "IsPublicSite");
			Assert.That(appSettings.LdapConnectionString, Is.EqualTo(""), "LdapConnectionString");
			Assert.That(appSettings.LdapPassword, Is.EqualTo(""), "LdapPassword");
			Assert.That(appSettings.LdapUsername, Is.EqualTo(""), "LdapUsername");
			Assert.That(appSettings.UseHtmlWhiteList, Is.EqualTo(true), "UseHtmlWhiteList");
			Assert.That(appSettings.UserServiceType, Is.EqualTo(""), "DefaultUserManager");
		}
		public void getapplicationsettings_should_parse_api_keys()
		{
			// Arrange
			string configFilePath = GetConfigPath("test.config");

			// Act
			FullTrustConfigReaderWriter configManager = new FullTrustConfigReaderWriter(configFilePath);
			ApplicationSettings appSettings = configManager.GetApplicationSettings();

			// Assert
			Assert.That(appSettings.ApiKeys, Is.Not.Null, "ApiKeys");
			Assert.That(appSettings.ApiKeys.Count(), Is.EqualTo(3), "ApiKeys");
			Assert.That(appSettings.ApiKeys, Contains.Item("apikey1"), "Doesn't contain 'apikey1'");
			Assert.That(appSettings.ApiKeys, Contains.Item("apikey2"), "Doesn't contain 'apikey2'");
			Assert.That(appSettings.ApiKeys, Contains.Item("apikey3"), "Doesn't contain 'apikey3'");
		}
        public void RoadkillSection_Legacy_UserManagerType_Value_Is_Ignored()
        {
            // Arrange
            string configFilePath = GetConfigPath("test-legacy-values.config");

            // Act
            FullTrustConfigReaderWriter configManager = new FullTrustConfigReaderWriter(configFilePath);
            ApplicationSettings appSettings = configManager.GetApplicationSettings();

            // Assert
            Assert.That(appSettings.UserServiceType, Is.Null.Or.Empty, "UserManagerType [legacy test for userManagerType]");
        }
        public void RoadkillSection_Legacy_DatabaseType_Is_Used()
        {
            // Arrange
            string configFilePath = GetConfigPath("test-legacy-values.config");

            // Act
            FullTrustConfigReaderWriter configManager = new FullTrustConfigReaderWriter(configFilePath);
            ApplicationSettings appSettings = configManager.GetApplicationSettings();

            // Assert
            Assert.That(appSettings.DataStoreType, Is.EqualTo(DataStoreType.Sqlite), "DataStoreType [legacy test for databaseType]");
        }
        public void RoadkillSection_Legacy_CacheValues_Are_Ignored()
        {
            // Arrange
            string configFilePath = GetConfigPath("test-legacy-values.config");

            // Act
            FullTrustConfigReaderWriter configManager = new FullTrustConfigReaderWriter(configFilePath);
            ApplicationSettings appSettings = configManager.GetApplicationSettings();

            // Assert
            Assert.That(appSettings.UseObjectCache, Is.True, "UseObjectCache [legacy test for cacheEnabled]");
            Assert.That(appSettings.UseBrowserCache, Is.False, "UseBrowserCache [legacy test for cacheText]");
        }