예제 #1
0
            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");
            }
예제 #2
0
            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);
            }
예제 #3
0
            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");
            }
예제 #4
0
            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");
            }
예제 #5
0
            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);
            }