Example #1
0
        public void AddingAConfigContextWithIncorrectPlaneNameThrowsException()
        {
            ConfigPlane   sut           = new ConfigPlane("PlaneName");
            ConfigContext configContext = new ConfigContext("NotPlaneName", "ConfigContextName");

            Assert.That(() => sut.UpsertConfigContext(configContext), Throws.ArgumentException);
        }
Example #2
0
        public void NewDescriptorIsStoredWhenSpecified()
        {
            var sut = new ConfigPlane("");

            sut.PlaneDescriptor = new KeyValuePair <string, string>("MyPlaneDescriptorKey", "SomeValueThatIsIgnored");
            Assert.That(sut.PlaneDescriptor.Key.Equals("MyPlaneDescriptorKey", StringComparison.InvariantCulture));
            Assert.That(sut.PlaneDescriptor.Value.Equals(String.Empty, StringComparison.InvariantCulture));
        }
Example #3
0
        public void GetConfig_ReturnsNullIfKeyNotFound()
        {
            ConfigPlane sut = new ConfigPlane("MyPlane");

            sut.UpsertConfigValue("MyContext", "MyConfigKey", "MyConfigValue");
            sut.SearchContext = "MyContext";
            string configValue = sut.GetConfigValue("MyConfigUnkownKey");

            Assert.IsNull(configValue);
        }
Example #4
0
        public void GetConfigKeyReport_ReturnsCorrectConfigContextame()
        {
            ConfigPlane sut = new ConfigPlane("PlaneName");

            sut.SearchContext = "SomeContext";
            sut.UpsertConfigValue("SomeContext", "MyKey", "MyValue");
            var configKeyReport = sut.GetConfigKeyReport("MyKey");

            Assert.That(configKeyReport.ConfigContextName == "SomeContext");
        }
Example #5
0
        public void GetConfigKeyReport_ReturnsReportIfKeyFound()
        {
            ConfigPlane sut = new ConfigPlane("PlaneName");

            sut.SearchContext = "SomeContext";
            sut.UpsertConfigValue("SomeContext", "MyKey", "MyValue");
            var configKeyReport = sut.GetConfigKeyReport("MyKey");

            Assert.NotNull(configKeyReport);
        }
Example #6
0
        public void ChangingLevelNameAfterSetting_CausesException()
        {
            KeyValuePair <string, string> kvp = new KeyValuePair <string, string>("NewName", "Fred");
            ConfigPlane sut = new ConfigPlane("FirstName");

            Assert.That(
                () => sut.PlaneDescriptor = kvp,
                Throws.Exception
                );
        }
Example #7
0
        public void GetConfigKeyReport_ReturnsCorrectValuesForADefaultConfigSource()
        {
            ConfigPlane sut = new ConfigPlane("PlaneName");

            sut.SearchContext = "SomeContext";
            sut.UpsertDefaultConfigValue("MyKey", "MyValue");
            var configKeyReport = sut.GetConfigKeyReport("MyKey");

            Assert.That(configKeyReport.ConfigSource == ConfigKeySource.Default);
        }
Example #8
0
        public void TryGetValue_ReturnsFalseIfKeyNotFound()
        {
            ConfigPlane sut = new ConfigPlane("MyPlane");

            sut.UpsertConfigValue("MyContext", "MyConfigKey", "MyConfigValue");
            sut.SearchContext = "MyContext";
            string configValue;
            bool   result = sut.TryGetConfigValue("MyConfigUnkownKey", out configValue);

            Assert.IsFalse(result);
        }
Example #9
0
        public void GetConfig_ReturnsValueIfKeyFound()
        {
            ConfigPlane sut = new ConfigPlane("MyPlane");

            sut.UpsertConfigValue("MyContext", "MyConfigKey", "MyConfigValue");
            sut.SearchContext = "MyContext";
            string configValue = sut.GetConfigValue("MyConfigKey");

            Assert.IsNotNull(configValue);
            Assert.AreEqual(configValue, "MyConfigValue");
        }
Example #10
0
        public void GetValue_UsesDefaultIfNoConfigContextProvided()
        {
            ConfigPlane sut = new ConfigPlane("PlaneName");


            sut.UpsertDefaultConfigValue("SomeKey", "SomeValue");

            var configValue = sut.GetConfigValue("SomeKey");

            Assert.IsNotNull(configValue);
            Assert.That(configValue.Equals("SomeValue", StringComparison.InvariantCulture));
        }
Example #11
0
        public void AddingNewConfigContext_NewConfigContextStored()
        {
            ConfigPlane   sut           = new ConfigPlane("PlaneName");
            ConfigContext configContext = new ConfigContext("PlaneName", "ConfigContextName");

            sut.UpsertConfigContext(configContext);
            IConfigContext readConfigContext = sut.GetConfigContext("ConfigContextName");

            Assert.IsNotNull(readConfigContext);
            Assert.That(readConfigContext.PlaneDescriptor.Key == "PlaneName");
            Assert.That(readConfigContext.PlaneDescriptor.Value == "ConfigContextName");
        }
Example #12
0
        public void TryGetValue_OutputsNullIfKeyNotFound()
        {
            ConfigPlane sut = new ConfigPlane("MyPlane");

            sut.UpsertConfigValue("MyContext", "MyConfigKey", "MyConfigValue");
            sut.SearchContext = "MyContext";
            string configValue;

            sut.TryGetConfigValue("MyConfigUnkownKey", out configValue);

            Assert.IsNull(configValue);
        }
Example #13
0
        public void GetValue_AttemptsToGetValueFromChildIfNotFoundLocally()
        {
            var         child = MockRepository.GenerateMock <IConfigPlane>();
            ConfigPlane sut   = new ConfigPlane("MyPlane");

            sut.Child = child;


            sut.SearchContext = "MyContext";
            sut.GetConfigValue("MyConfigUnkownKey");

            child.AssertWasCalled(x => x.GetConfigValue(Arg <string> .Is.Equal("MyConfigUnkownKey")), options => options.Repeat.Once());
        }
Example #14
0
        public void TryGetValue_OutputsValueIfKeyFound()
        {
            ConfigPlane sut = new ConfigPlane("MyPlane");

            sut.UpsertConfigValue("MyContext", "MyConfigKey", "MyConfigValue");
            sut.SearchContext = "MyContext";
            string configValue;

            sut.TryGetConfigValue("MyConfigKey", out configValue);

            Assert.IsNotNull(configValue);
            Assert.AreEqual(configValue, "MyConfigValue");
        }
Example #15
0
        public void GetConfigKeyReport_ReturnsNullForUnknownKey()
        {
            ConfigPlane   sut            = new ConfigPlane("PlaneName");
            ConfigContext configContext1 = new ConfigContext("PlaneName", "ConfigContextName1");

            configContext1.UpsertConfigValue("TestConfig", "configContext1Value");
            sut.UpsertConfigContext(configContext1);

            sut.UpsertDefaultConfigValue("SomeKey", "SomeValue");
            sut.SearchContext = "ConfigContextName1";
            var configKeyReport = sut.GetConfigKeyReport("UnknownTestConfig");

            Assert.IsNull(configKeyReport);
        }
Example #16
0
        public void UpsertingConfigValue_WhereNoConfigContextExists_OneIsCreatedAndConfigStoredOnTheNewConfigContext()
        {
            string configValue;

            ConfigPlane sut = new ConfigPlane("PlaneName");

            sut.UpsertConfigValue("MyNewConfigContext", "MyKey", "MyValue");


            configValue = sut.GetConfigValue("MyNewConfigContext", "MyKey");
            Assert.IsNotNull(sut.GetConfigContext("MyNewConfigContext"));
            Assert.IsNotNull(configValue);
            Assert.That(configValue.Equals("MyValue", StringComparison.InvariantCulture));
        }
Example #17
0
        public void SettingContextToAnUnusedContext_GetConfigValueWillReturnValueFromDefault()
        {
            ConfigPlane   sut            = new ConfigPlane("PlaneName");
            ConfigContext configContext1 = new ConfigContext("PlaneName", "ConfigContextName1");

            configContext1.UpsertConfigValue("SomeKey", "configContext1Value");
            sut.UpsertConfigContext(configContext1);

            sut.UpsertDefaultConfigValue("SomeKey", "SomeValue");
            sut.SearchContext = "Invalid";
            var configValue = sut.GetConfigValue("SomeKey");

            Assert.IsNotNull(configValue);
            Assert.That(configValue.Equals("SomeValue", StringComparison.InvariantCulture));
        }
Example #18
0
        public void GetValue_UsesDefaultIfNotFoundOnConfigContext()
        {
            ConfigPlane   sut            = new ConfigPlane("PlaneName");
            ConfigContext configContext1 = new ConfigContext("PlaneName", "ConfigContextName1");

            configContext1.UpsertConfigValue("TestConfig", "configContext1Value");
            sut.UpsertConfigContext(configContext1);

            sut.UpsertDefaultConfigValue("SomeKey", "SomeValue");

            var configValue = sut.GetConfigValue("ConfigContextName1", "SomeKey");

            Assert.IsNotNull(configValue);
            Assert.That(configValue.Equals("SomeValue", StringComparison.InvariantCulture));
        }
Example #19
0
        public void GetConfigKeyReport_ReportsFromChildIfKeyNotFound()
        {
            ConfigPlane sut   = new ConfigPlane("TopPlane");
            ConfigPlane child = new ConfigPlane("ChildPlane");

            child.SearchContext = "SomeContext";
            child.UpsertConfigValue("SomeContext", "MyKey", "MyValue");


            sut.Child         = child;
            sut.SearchContext = "SomeSearchContext";
            var configKeyReport = sut.GetConfigKeyReport("MyKey");


            Assert.NotNull(configKeyReport);
        }
Example #20
0
        public void TryGetConfigContext_OutputsNullIfNotPresent()
        {
            IConfigContext readConfigContext;
            ConfigPlane    sut            = new ConfigPlane("PlaneName");
            ConfigContext  configContext1 = new ConfigContext("PlaneName", "ConfigContextName1");

            configContext1.UpsertConfigValue("TestConfig", "configContext1Value");
            sut.UpsertConfigContext(configContext1);

            ConfigContext configContext2 = new ConfigContext("PlaneName", "ConfigContextName2");

            configContext2.UpsertConfigValue("TestConfig", "configContext2Value");
            sut.UpsertConfigContext(configContext2);
            sut.TryGetConfigContext("UnknownConfigContextName", out readConfigContext);
            Assert.IsNull(readConfigContext);
        }
Example #21
0
        public void TryGetConfigContext_ReturnsTrueIfPresent()
        {
            IConfigContext readConfigContext;
            ConfigPlane    sut            = new ConfigPlane("PlaneName");
            ConfigContext  configContext1 = new ConfigContext("PlaneName", "ConfigContextName1");

            configContext1.UpsertConfigValue("TestConfig", "configContext1Value");
            sut.UpsertConfigContext(configContext1);

            ConfigContext configContext2 = new ConfigContext("PlaneName", "ConfigContextName2");

            configContext2.UpsertConfigValue("TestConfig", "configContext2Value");
            sut.UpsertConfigContext(configContext2);

            Assert.IsTrue(sut.TryGetConfigContext("ConfigContextName2", out readConfigContext));
            Assert.IsNotNull(readConfigContext);
        }
Example #22
0
        public void TryGetConfigContext_OutputsValueIfPresent()
        {
            IConfigContext readConfigContext;
            ConfigPlane    sut            = new ConfigPlane("PlaneName");
            ConfigContext  configContext1 = new ConfigContext("PlaneName", "ConfigContextName1");

            configContext1.UpsertConfigValue("TestConfig", "configContext1Value");
            sut.UpsertConfigContext(configContext1);

            ConfigContext configContext2 = new ConfigContext("PlaneName", "ConfigContextName2");

            configContext2.UpsertConfigValue("TestConfig", "configContext2Value");
            sut.UpsertConfigContext(configContext2);

            Assert.IsTrue(sut.TryGetConfigContext("ConfigContextName2", out readConfigContext));
            Assert.That(readConfigContext.PlaneDescriptor.Value.Equals("ConfigContextName2", StringComparison.InvariantCulture));
        }
Example #23
0
        public void TryGetValue_PassesToChildIfKeyNotFound()
        {
            string configValue;

            var         child = MockRepository.GenerateMock <IConfigPlane>();
            ConfigPlane sut   = new ConfigPlane("MyPlane");

            sut.Child = child;

            sut.SearchContext = "MyContext";
            sut.TryGetConfigValue("MyConfigUnkownKey", out configValue);

            child.AssertWasCalled(x => x.TryGetConfigValue(Arg <string> .Is.Equal("MyConfigUnkownKey"),
                                                           out Arg <string> .Out("hello").Dummy
                                                           ), options => options.Repeat.Once()
                                  );
        }
Example #24
0
        public void GettingConfigContext_ReturnsNullIfNotPresent()
        {
            ConfigPlane   sut            = new ConfigPlane("PlaneName");
            ConfigContext configContext1 = new ConfigContext("PlaneName", "ConfigContextName1");

            configContext1.UpsertConfigValue("TestConfig", "configContext1Value");
            sut.UpsertConfigContext(configContext1);

            ConfigContext configContext2 = new ConfigContext("PlaneName", "ConfigContextName2");

            configContext2.UpsertConfigValue("TestConfig", "configContext2Value");
            sut.UpsertConfigContext(configContext2);

            IConfigContext readConfigContext = sut.GetConfigContext("UnknowConfigContextName");

            Assert.IsNull(readConfigContext);
        }
Example #25
0
        public void GetValue_UsesContextIfNoConfigContextNameprovided()
        {
            string configValue;

            ConfigPlane   sut            = new ConfigPlane("PlaneName");
            ConfigContext configContext1 = new ConfigContext("PlaneName", "ConfigContextName1");

            configContext1.UpsertConfigValue("TestConfig", "configContext1Value");
            sut.UpsertConfigContext(configContext1);

            sut.UpsertDefaultConfigValue("SomeKey", "SomeValue");
            sut.SearchContext = "ConfigContextName1";
            configValue       = sut.GetConfigValue("TestConfig");

            Assert.IsNotNull(configValue);
            Assert.That(configValue.Equals("configContext1Value", StringComparison.InvariantCulture));
        }
Example #26
0
        public void GetValue_UsesCorrectConfigContextForValue()
        {
            string configValue;

            ConfigPlane   sut            = new ConfigPlane("PlaneName");
            ConfigContext configContext1 = new ConfigContext("PlaneName", "ConfigContextName1");

            configContext1.UpsertConfigValue("TestConfig", "configContext1Value");
            sut.UpsertConfigContext(configContext1);

            ConfigContext configContext2 = new ConfigContext("PlaneName", "ConfigContextName2");

            configContext2.UpsertConfigValue("TestConfig", "configContext2Value");
            sut.UpsertConfigContext(configContext2);
            configValue = sut.GetConfigValue("ConfigContextName1", "TestConfig");

            Assert.IsNotNull(configValue);
            Assert.That(configValue.Equals("configContext1Value", StringComparison.InvariantCulture));
        }
Example #27
0
        public void GettingConfigContext_ReturnsConfigContextIfPresent()
        {
            ConfigPlane   sut            = new ConfigPlane("PlaneName");
            ConfigContext configContext1 = new ConfigContext("PlaneName", "ConfigContextName1");

            configContext1.UpsertConfigValue("TestConfig", "configContext1Value");
            sut.UpsertConfigContext(configContext1);

            ConfigContext configContext2 = new ConfigContext("PlaneName", "ConfigContextName2");

            configContext2.UpsertConfigValue("TestConfig", "configContext2Value");
            sut.UpsertConfigContext(configContext2);

            IConfigContext readConfigContext = sut.GetConfigContext("ConfigContextName2");

            Assert.IsNotNull(readConfigContext);
            Assert.That(readConfigContext.PlaneDescriptor.Key == "PlaneName");
            Assert.That(readConfigContext.PlaneDescriptor.Value == "ConfigContextName2");
        }
Example #28
0
        public void AddingExistingConfigContext_NewConfigContextSaved()
        {
            ConfigPlane   sut            = new ConfigPlane("PlaneName");
            ConfigContext configContext1 = new ConfigContext("PlaneName", "ConfigContextName");

            configContext1.UpsertConfigValue("TestConfig", "configContext1Value");
            sut.UpsertConfigContext(configContext1);

            ConfigContext configContext2 = new ConfigContext("PlaneName", "ConfigContextName");

            configContext2.UpsertConfigValue("TestConfig", "configContext2Value");
            sut.UpsertConfigContext(configContext2);

            IConfigContext readConfigContext = sut.GetConfigContext("ConfigContextName");

            Assert.IsNotNull(readConfigContext);
            Assert.That(readConfigContext.PlaneDescriptor.Key == "PlaneName");
            Assert.That(readConfigContext.PlaneDescriptor.Value == "ConfigContextName");

            Assert.That(readConfigContext.GetConfigValue("TestConfig").Equals("configContext2Value", StringComparison.InvariantCulture));
        }
Example #29
0
        public void TryGetValue_UsesDefaultValueIfNoValueOnConfigContext()
        {
            string configValue;

            ConfigPlane   sut            = new ConfigPlane("PlaneName");
            ConfigContext configContext1 = new ConfigContext("PlaneName", "ConfigContextName1");

            configContext1.UpsertConfigValue("TestConfig", "configContext1Value");
            sut.UpsertConfigContext(configContext1);

            ConfigContext configContext2 = new ConfigContext("PlaneName", "ConfigContextName2");

            configContext2.UpsertConfigValue("TestConfig", "configContext2Value");
            sut.UpsertConfigContext(configContext2);
            sut.SearchContext = "ConfigContextName1";
            sut.UpsertDefaultConfigValue("ConfigOnlyInDefault", "ADefaultValue");

            Assert.IsTrue(sut.TryGetConfigValue("ConfigOnlyInDefault", out configValue));

            Assert.IsNotNull(configValue);
            Assert.That(configValue.Equals("ADefaultValue", StringComparison.InvariantCulture));
        }
Example #30
0
        public void UsingInvalidContext_CausesException()
        {
            ConfigPlane sut = new ConfigPlane("PlaneName");

            Assert.That(() => sut.UpsertConfigValue("MyKey", "MyValue"), Throws.ArgumentException);
        }