public void CacheDisabledByDefault()
        {
            var configurationBuilder = new ConfigurationBuilder();
            var memorySource         = new MemorySource();

            configurationBuilder.AddSources(memorySource);

            memorySource.Add("test.string.property", "test");
            var testConfigInstance = configurationBuilder.Build <StringPropertyDto>();

            Assert.AreEqual("test", testConfigInstance.StringProperty);

            memorySource.Add("test.string.property", "test2");
            testConfigInstance = configurationBuilder.Build <StringPropertyDto>();
            Assert.AreEqual("test2", testConfigInstance.StringProperty);
        }
        public void CacheAcceptsTheConfiguredExpiration()
        {
            var configurationBuilder = new ConfigurationBuilder();
            var memorySource         = new MemorySource();

            configurationBuilder.AddSources(memorySource);
            configurationBuilder.CacheExpiration = TimeSpan.FromSeconds(1);

            memorySource.Add("test.string.property", "test");
            var testConfigInstance = configurationBuilder.Build <StringPropertyDto>();

            Assert.AreEqual("test", testConfigInstance.StringProperty);

            memorySource.Add("test.string.property", "test2");
            Thread.Sleep(500);
            testConfigInstance = configurationBuilder.Build <StringPropertyDto>();
            Assert.AreEqual("test", testConfigInstance.StringProperty);

            Thread.Sleep(1500);
            testConfigInstance = configurationBuilder.Build <StringPropertyDto>();
            Assert.AreEqual("test2", testConfigInstance.StringProperty);
        }
        public void WhenSpecifiedThePropertiesPrefixIsUsed()
        {
            var propertySource1 = new MemorySource();

            propertySource1.Add("testPrefix.testPropertyName", "testValue");

            ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();

            configurationBuilder.AddSources(propertySource1);

            var configDto = configurationBuilder.Build <PropertyWithPrefixDto>(propertiesPrefix: "testPrefix.");

            Assert.AreEqual("testValue", configDto.testProperty);
        }
        public void NonDecoratedPropertiesAreByDefaultIgnored()
        {
            var propertySource1 = new MemorySource();

            propertySource1.Add("NonDecoratedTestProperty", "testValue");

            ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();

            configurationBuilder.AddSources(propertySource1);

            var configDto = configurationBuilder.Build <NonDecoratedPropertyDto>();

            Assert.IsNull(configDto.NonDecoratedTestProperty);
        }
        public void WhenActiveNonDecoratedPropertiesArePopulatedUsingTheNameOfThePropertyItself()
        {
            var propertySource1 = new MemorySource();

            propertySource1.Add("NonDecoratedTestProperty", "testValue");

            ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();

            configurationBuilder.AddSources(propertySource1);
            configurationBuilder.HandleNonDecoratedProperties = true;

            var configDto = configurationBuilder.Build <NonDecoratedPropertyDto>();

            Assert.AreEqual("testValue", configDto.NonDecoratedTestProperty);
        }
        public void ConfigurationSetByASourceIsNotMistakenlyOverwrittenBySubsequentSources()
        {
            string testPropertyName = "testPropertyName";
            var    propertySource1  = new MemorySource();

            propertySource1.Add(testPropertyName, "1");

            var propertySource2 = new MemorySource();

            ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();

            configurationBuilder.AddSources(propertySource1, propertySource2);

            string obtainedValue;

            Assert.IsTrue(configurationBuilder.TryGetStringValue(testPropertyName, out obtainedValue));
            Assert.AreEqual("1", obtainedValue);
        }
        public void ConfigurationIsOverwrittenInTheProvidedSourceOrder()
        {
            string testPropertyName = "testPropertyName";
            var    propertySource1  = new MemorySource();

            propertySource1.Add(testPropertyName, "1");

            var propertySource2 = new MemorySource();

            propertySource2.Add(testPropertyName, "2");

            ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();

            configurationBuilder.AddSources(propertySource1, propertySource2);

            string obtainedValue;

            Assert.IsTrue(configurationBuilder.TryGetStringValue(testPropertyName, out obtainedValue));
            Assert.AreEqual("2", obtainedValue);
        }