public void EvaluatesReturnStatement() { // Given IConfiguration configuration = GetConfiguration(@" { ""foo"": ""=> return $\""ABC {1+2} XYZ\"";"" }"); TestExecutionContext context = new TestExecutionContext(); context.ScriptHelper = new ScriptHelper(context); ReadOnlyConfigurationSettings settings = new ReadOnlyConfigurationSettings(context, configuration, null); // When bool result = settings.TryGetValue("foo", out object value); // Then result.ShouldBeTrue(); value.ShouldBe("ABC 3 XYZ"); }
public void EvaluatesIntExpression() { // Given IConfiguration configuration = GetConfiguration(@" { ""foo"": ""=> 1 + 2"" }"); TestExecutionContext context = new TestExecutionContext(); context.ScriptHelper = new ScriptHelper(context); ReadOnlyConfigurationSettings settings = new ReadOnlyConfigurationSettings(context, configuration, null); // When bool result = settings.TryGetValue("foo", out object value); // Then result.ShouldBeTrue(); value.ShouldBe(3); }
public void CanAccessOtherValuesInExpression() { // Given IConfiguration configuration = GetConfiguration(@" { ""foo"": ""=> $\""ABC {bar} XYZ\"""", ""bar"": 3 }"); TestExecutionContext context = new TestExecutionContext(); context.ScriptHelper = new ScriptHelper(context); ReadOnlyConfigurationSettings settings = new ReadOnlyConfigurationSettings(context, configuration, null); // When bool result = settings.TryGetValue("foo", out object value); // Then result.ShouldBeTrue(); value.ShouldBe("ABC 3 XYZ"); }
public void EvaluatesExpressionInNestedSection() { // Given IConfiguration configuration = GetConfiguration(@" { ""section0"": { ""foo"": ""=> $\""ABC {1+2} XYZ\"""" } }"); TestExecutionContext context = new TestExecutionContext(); context.ScriptHelper = new ScriptHelper(context); ReadOnlyConfigurationSettings settings = new ReadOnlyConfigurationSettings(context, configuration, null); // When bool result = settings.TryGetValue("section0:foo", out object value); // Then result.ShouldBeTrue(); value.ShouldBe("ABC 3 XYZ"); }
public void GetsOVerridenValue() { // Given IConfiguration configuration = GetConfiguration(@" { ""foo"": ""ABC {1+2} XYZ"" }"); TestExecutionContext context = new TestExecutionContext(); context.ScriptHelper = new ScriptHelper(context); Dictionary <string, object> overrides = new Dictionary <string, object> { { "foo", 123 } }; ReadOnlyConfigurationSettings settings = new ReadOnlyConfigurationSettings(context, configuration, overrides); // When bool result = settings.TryGetValue("foo", out object value); // Then result.ShouldBeTrue(); value.ShouldBe(123); }