Esempio n. 1
0
        public void OpenNamedConnectionThrowsIfNoConnectionFound()
        {
            // Arrange
            IConfigurationManager mockConfigurationManager = new MockConfigurationManager();

            // Act & Assert
            Assert.Throws <InvalidOperationException>(() => Database.OpenNamedConnection("foo", mockConfigurationManager), "Connection string \"foo\" was not found.");
        }
        public void TestClearData()
        {
            var configurationManager = new MockConfigurationManager();

            configurationManager.ClearData();
            Assert.That(configurationManager.ActiveSolutionPlatform, Is.Null);
            Assert.That(configurationManager.ActiveSolutionConfiguration, Is.Null);
            Assert.That(configurationManager.AvailableSolutionConfigurations, Is.Empty);
            Assert.That(configurationManager.AvailableSolutionPlatforms, Is.Empty);
            Assert.That(configurationManager.Projects, Is.Empty);
        }
Esempio n. 3
0
        public void Update_AppConfig_AuditFilePath_Default_Not_Expected()
        {
            const string expectedPath2 = "SomeOtherPath";

            var mockConfig = new MockConfigurationManager();

            Config.ConfigureSettings(mockConfig);

            Config.Server.AuditFilePath = expectedPath2;
            Assert.AreEqual(expectedPath2, Config.Server.AuditFilePath);
        }
        public void Constructor_WithNullConfiguration_Throws()
        {
            // Arrange
            XmlNode                emptySection         = CreateEmptyXmlNode();
            IHttpContext           httpContext          = null;
            IConfigurationManager  configurationManager = new MockConfigurationManager(emptySection);
            IRewriterConfiguration configuration        = null;

            // Act/Assert
            ExceptionAssert.Throws <ArgumentNullException>(() =>
                                                           new RewriterEngine(httpContext, configurationManager, configuration));
        }
Esempio n. 5
0
        public void NoAppSettingTest()
        {
            var configurationManager     = new MockConfigurationManager();
            var appSettingLayoutRenderer = new AppSettingLayoutRenderer
            {
                ConfigurationManager = configurationManager,
                Name = "notFound",
            };

            var rendered = appSettingLayoutRenderer.Render(LogEventInfo.CreateNullEvent());

            Assert.Equal(string.Empty, rendered);
        }
        public void ValidSolutionContextSetIsOnlyTrueIfProjectsExistAndConfigurationAndPlatformWasSet()
        {
            var configurationManager = new MockConfigurationManager();

            configurationManager.ClearData();
            Assert.That(configurationManager.ValidSolutionContextSet, Is.False);
            configurationManager.Projects.Add(new Project());
            Assert.That(configurationManager.ValidSolutionContextSet, Is.False);
            configurationManager.ActiveSolutionConfiguration = "Debug";
            Assert.That(configurationManager.ValidSolutionContextSet, Is.False);
            configurationManager.ActiveSolutionPlatform = "Any CPU";
            Assert.That(configurationManager.ValidSolutionContextSet, Is.True);
        }
        public void ProjectSolutionContextIsSetWhenSettingActiveConfiguration()
        {
            var configurationManager = new MockConfigurationManager();

            Assert.That(configurationManager.Projects[0].ActiveConfiguration, Is.Null);
            configurationManager.ActiveSolutionConfiguration = "Debug";
            configurationManager.ActiveSolutionPlatform      = "Any CPU";
            var activeConfiguration = configurationManager.Projects[0].ActiveConfiguration;

            Assert.That(activeConfiguration, Is.Not.Null);
            Assert.That(activeConfiguration.SolutionConfiguration, Is.EqualTo("Debug"));
            Assert.That(activeConfiguration.SolutionPlatform, Is.EqualTo("Any CPU"));
        }
Esempio n. 8
0
        public void FallbackToDefaultTest()
        {
            var configurationManager = new MockConfigurationManager();
            const string expected = "UseDefault";
            var appSettingLayoutRenderer = new AppSettingLayoutRenderer
            {
                ConfigurationManager = configurationManager,
                Name = "notFound",
                Default = "UseDefault",
            };

            var rendered = appSettingLayoutRenderer.Render(LogEventInfo.CreateNullEvent());

            Assert.Equal(expected, rendered);
        }
Esempio n. 9
0
        public void UseAppSettingTest()
        {
            var configurationManager = new MockConfigurationManager();
            const string expected = "appSettingTestValue";
            configurationManager.AppSettings["appSettingTestKey"] = expected;
            var appSettingLayoutRenderer = new AppSettingLayoutRenderer
            {
                ConfigurationManager = configurationManager,
                Name = "appSettingTestKey",
            };

            var rendered = appSettingLayoutRenderer.Render(LogEventInfo.CreateNullEvent());

            Assert.Equal(expected, rendered);
        }
Esempio n. 10
0
        public void FallbackToDefaultTest()
        {
            var          configurationManager     = new MockConfigurationManager();
            const string expected                 = "UseDefault";
            var          appSettingLayoutRenderer = new AppSettingLayoutRenderer
            {
                ConfigurationManager = configurationManager,
                Name    = "notFound",
                Default = "UseDefault",
            };

            var rendered = appSettingLayoutRenderer.Render(LogEventInfo.CreateNullEvent());

            Assert.Equal(expected, rendered);
        }
Esempio n. 11
0
        public void UseAppSettingTest()
        {
            var          configurationManager = new MockConfigurationManager();
            const string expected             = "appSettingTestValue";

            configurationManager.AppSettings["appSettingTestKey"] = expected;
            var appSettingLayoutRenderer = new AppSettingLayoutRenderer
            {
                ConfigurationManager = configurationManager,
                Name = "appSettingTestKey",
            };

            var rendered = appSettingLayoutRenderer.Render(LogEventInfo.CreateNullEvent());

            Assert.Equal(expected, rendered);
        }
        public void AppSettingOverridesDefaultTest()
        {
            var          configurationManager = new MockConfigurationManager();
            const string expected             = "appSettingTestValue";

            configurationManager.AppSettings["appSettingTestKey"] = expected;
            var appSettingLayoutRenderer = new AppSettingLayoutRenderer2
            {
                ConfigurationManager = configurationManager,
                Item    = "appSettingTestKey",
                Default = "UseDefault",
            };

            var rendered = appSettingLayoutRenderer.Render(LogEventInfo.CreateNullEvent());

            Assert.Equal(expected, rendered);
        }
Esempio n. 13
0
        public void OpenNamedConnectionUsesConnectionStringFromConfigurationIfExists()
        {
            // Arrange
            MockConfigurationManager mockConfigurationManager = new MockConfigurationManager();
            Mock <DbConnection>      mockConnection           = new Mock <DbConnection>();

            mockConnection.Setup(m => m.ConnectionString).Returns("connection string");
            Mock <MockDbProviderFactory> mockProviderFactory = new Mock <MockDbProviderFactory>();

            mockProviderFactory.Setup(m => m.CreateConnection("connection string")).Returns(mockConnection.Object);
            mockConfigurationManager.AddConnection("foo", new ConnectionConfiguration(mockProviderFactory.Object, "connection string"));

            // Act
            Database db = Database.OpenNamedConnection("foo", mockConfigurationManager);

            // Assert
            Assert.Equal("connection string", db.Connection.ConnectionString);
        }
Esempio n. 14
0
        public void Get_AppConfig_Configuration()
        {
            const string expectedPath = @"C:\ProgramData\Warewolf\Audits";
            var          mockConfig   = new MockConfigurationManager();

            Config.ConfigureSettings(mockConfig);

            var settings = Config.Server.Get();

            Assert.AreEqual(7, settings.GetType().GetProperties().Length);

            Assert.AreEqual((ushort)0, settings.WebServerPort);
            Assert.AreEqual((ushort)0, settings.WebServerSslPort);
            Assert.AreEqual(null, settings.SslCertificateName);
            Assert.AreEqual(false, settings.CollectUsageStats);
            Assert.AreEqual(0, settings.DaysToKeepTempFiles);
            Assert.AreEqual(expectedPath, settings.AuditFilePath);
            Assert.AreEqual(true, settings.EnableDetailedLogging);
        }
        public void UseConnectionStringTest()
        {
            var          configurationManager = new MockConfigurationManager();
            const string expected             = "Hello Connection";

            configurationManager.ConnectionStrings["myConnection"] = new ConnectionStringSettings()
            {
                ConnectionString = expected
            };
            var appSettingLayoutRenderer = new AppSettingLayoutRenderer2
            {
                ConfigurationManager = configurationManager,
                Item = "ConnectionStrings.myConnection",
            };

            var rendered = appSettingLayoutRenderer.Render(LogEventInfo.CreateNullEvent());

            Assert.Equal(expected, rendered);
        }
        public void ResetLastKnownGoodLifetime()
        {
            TestUtilities.WriteHeader($"{this}.ResetLastKnownGoodLifetime");
            var context = new CompareContext();

            var validConfig = new OpenIdConnectConfiguration()
            {
                TokenEndpoint = Default.Issuer + "oauth/token", Issuer = Default.Issuer
            };
            var configurationManager = new MockConfigurationManager <OpenIdConnectConfiguration>(validConfig);

            // set and retrieve config in order to set the first access time
            configurationManager.LastKnownGoodConfiguration = validConfig;
            var lkg = configurationManager.LastKnownGoodConfiguration;
            var lkgConfigFirstUseField = typeof(BaseConfigurationManager).GetField("_lastKnownGoodConfigFirstUse", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            var lkgConfigFirstUse1     = lkgConfigFirstUseField.GetValue(configurationManager as BaseConfigurationManager);

            Thread.Sleep(1);

            // set and retrieve config again to reset first access time
            configurationManager.LastKnownGoodConfiguration = validConfig;
            lkg = configurationManager.LastKnownGoodConfiguration;
            var lkgConfigFirstUse2 = lkgConfigFirstUseField.GetValue(configurationManager as BaseConfigurationManager);

            if (lkgConfigFirstUse1 == null)
            {
                context.AddDiff("Last known good first use time was not properly set for the first configuration.");
            }

            if (lkgConfigFirstUse2 == null)
            {
                context.AddDiff("Last known good first use time was not properly set for the second configuration.");
            }

            //LKG config first use was not reset when a new configuration was set
            if (lkgConfigFirstUse1.Equals(lkgConfigFirstUse2))
            {
                context.AddDiff("Last known good first use time was not reset when a new LKG configuration was set.");
            }

            TestUtilities.AssertFailIfErrors(context);
        }
Esempio n. 17
0
        public void NoAppSettingTest()
        {
            var configurationManager = new MockConfigurationManager();
            var appSettingLayoutRenderer = new AppSettingLayoutRenderer
            {
                ConfigurationManager = configurationManager,
                Name = "notFound",
            };

            var rendered = appSettingLayoutRenderer.Render(LogEventInfo.CreateNullEvent());

            Assert.Equal(string.Empty, rendered);
        }