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); }
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); }
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); }
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); }
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); }
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 }); }
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); }
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); }
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); }
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); }