Esempio n. 1
0
        public void GetValue_WhenNoValuesFound_ShouldReturnDefaultValue()
        {
            const int defaultValue = 1;
            var       sources      = new Dictionary <string, IValueSource>
            {
                { "source1", MockValueSource.With("key") } //no data
            };
            var provider = new ValueProvider(sources);

            var value = provider.GetValue("key", defaultValue);

            value.ShouldBe(defaultValue);
        }
Esempio n. 2
0
        public void TryGetValue_WhenValueFound_AndValueIsDefaultT_ShouldReturnTrue()
        {
            var sources = new Dictionary <string, IValueSource>
            {
                { "source1", MockValueSource.With("key", default(int)) }
            };
            var provider = new ValueProvider(sources);

            int outVal;
            var result = provider.TryGetValue("key", out outVal);

            result.ShouldBe(true);
        }
Esempio n. 3
0
        public void TryGetValue_WhenNoDataFound_ShouldReturnFalse()
        {
            var sources = new Dictionary <string, IValueSource>
            {
                { "source1", MockValueSource.With("key") } //no data
            };
            var provider = new ValueProvider(sources);

            int outVal;
            var result = provider.TryGetValue("key", out outVal);

            result.ShouldBe(false);
        }
Esempio n. 4
0
        public void GetValue_GivenMultipleValueSources_IncludingSourcesWithNoRelevantData_ShouldReturnFirstValueFromFirstValueSource()
        {
            var sources = new Dictionary <string, IValueSource>
            {
                { "source1", MockValueSource.With("key") }, //no data
                { "source2", MockValueSource.With("key", 3) },
                { "source3", MockValueSource.With("key", 9, 20, 3) }
            };
            var provider = new ValueProvider(sources);

            var value = provider.GetValue <int>("key");

            value.ShouldBe(3);
        }
Esempio n. 5
0
        public void GetValue_GivenMultipleValueSources_ShouldReturnFirstValueFromFirstValueSource()
        {
            var sources = new Dictionary <string, IValueSource>
            {
                { "source1", MockValueSource.With("key", 2, 4, 0) },
                { "source2", MockValueSource.With("key", 3) },
                { "source3", MockValueSource.With("key", 9, 20, 3) }
            };
            var provider = new ValueProvider(sources);

            var value = provider.GetValue <int>("key");

            value.ShouldBe(2);
        }
Esempio n. 6
0
        public void GetValues_GivenMultipleValueSources_ShouldReturnAllValuesFromAllSources()
        {
            var sources = new Dictionary <string, IValueSource>
            {
                { "source1", MockValueSource.With("key", 2, 4, 0) },
                { "source2", MockValueSource.With("key", 3) },
                { "source3", MockValueSource.With("key", 9, 20, 3) }
            };
            var provider = new ValueProvider(sources);

            var values = provider.GetValues <int>("key");

            values.ShouldBe(new[] { 2, 4, 0, 3, 9, 20, 3 });
        }
Esempio n. 7
0
        public void Preferring_GivenPreferredSources_ShouldCreateProviderThatContainsAllValueSources()
        {
            var sources = new Dictionary <string, IValueSource>
            {
                { "source1", MockValueSource.With("key", 1) },
                { "source2", MockValueSource.With("key", 2) },
                { "source3", MockValueSource.With("key", 3) }
            };
            var provider = new ValueProvider(sources);

            var value = provider.Preferring("source3").GetValues <int>("key");

            value.ShouldBe(new[] { 1, 2, 3 }, ignoreOrder: true);
        }
Esempio n. 8
0
        public void Preferring_GivenPreferredSources_ShouldCreateProviderThatChecksPreferredSourcesForValuesBeforeOthers()
        {
            var sources = new Dictionary <string, IValueSource>
            {
                { "source1", MockValueSource.With("key", 1) },
                { "source2", MockValueSource.With("key", 2) },
                { "source3", MockValueSource.With("key", 3) }
            };
            var provider = new ValueProvider(sources);

            var value = provider.Preferring("source3").GetValue <int>("key");

            value.ShouldBe(3);
        }
Esempio n. 9
0
        public void Including_ShouldReturnNewObject()
        {
            var sources = new Dictionary <string, IValueSource>()
            {
                { "source1", MockValueSource.With("key") },
                { "source2", MockValueSource.With("key") },
                { "source3", MockValueSource.With("key") }
            };
            var provider = new ValueProvider(sources);

            var newProvider = provider.Excluding("source1");

            newProvider.ShouldNotBe(provider);
        }
Esempio n. 10
0
        public void TryGetValue_WhenValueFound_ShouldOutputValue()
        {
            var sources = new Dictionary <string, IValueSource>
            {
                { "source1", MockValueSource.With("key", 1) }
            };
            var provider = new ValueProvider(sources);

            int outVal;

            provider.TryGetValue("key", out outVal);

            outVal.ShouldBe(1);
        }