diff --git a/Directory.Build.props b/Directory.Build.props index 39d1fb2..9dd5762 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,6 @@ - 1.0.12 + 1.0.13 Lucas Breedlove Queuebal Copyright © 2025 Queuebal diff --git a/Queuebal.Expressions/AssignExpression.cs b/Queuebal.Expressions/AssignExpression.cs new file mode 100644 index 0000000..fd74a41 --- /dev/null +++ b/Queuebal.Expressions/AssignExpression.cs @@ -0,0 +1,39 @@ +using Queuebal.Json; + +namespace Queuebal.Expressions; + + +/// +/// Assigns a value to an existing variable in the VariableProvider. +/// +public class AssignExpression : Expression +{ + public static string ExpressionType { get; } = "Assign"; + + /// + /// The name of the variable to assign a value to. + /// + public required string VariableName { get; set; } + + /// + /// The expression that evaluates to the value to assign to the variable. + /// + public required IExpression Value { get; set; } + + /// + /// Executes the assignment statement. + /// + /// The context in which the statement is executed. + protected override JSONValue EvaluateExpression(ExpressionContext context, JSONValue inputValue) + { + var value = Value.Evaluate(context, inputValue); + try + { + return context.VariableProvider.SetValue(VariableName, value); + } + catch (KeyNotFoundException) + { + throw new InvalidOperationException($"Variable '{VariableName}' is not declared."); + } + } +} diff --git a/Queuebal.Expressions/DeclareAndAssignExpression.cs b/Queuebal.Expressions/DeclareAndAssignExpression.cs index 2bf6e56..e4c3139 100644 --- a/Queuebal.Expressions/DeclareAndAssignExpression.cs +++ b/Queuebal.Expressions/DeclareAndAssignExpression.cs @@ -4,7 +4,7 @@ namespace Queuebal.Expressions; /// -/// Declares a variable in the current DataProviderScope and assigns it a value. +/// Declares a variable in the current VariableProviderScope and assigns it a value. /// This expression is used to create a new variable and initialize it with a value. /// If the variable already exists, an exception is thrown. /// @@ -28,13 +28,13 @@ public class DeclareAndAssignExpression : Expression /// The context in which the statement is executed. protected override JSONValue EvaluateExpression(ExpressionContext context, JSONValue inputValue) { - if (context.DataProvider.GetValueInCurrentScope(VariableName) != null) + if (context.VariableProvider.GetValueInCurrentScope(VariableName) != null) { throw new InvalidOperationException($"Variable '{VariableName}' is already declared."); } var newValue = Value.Evaluate(context, inputValue); - context.DataProvider.AddValue(VariableName, newValue); + context.VariableProvider.AddValue(VariableName, newValue); return newValue; } } \ No newline at end of file diff --git a/Queuebal.Expressions/DictExpression.cs b/Queuebal.Expressions/DictExpression.cs index 3d3f6c0..3fc64f8 100644 --- a/Queuebal.Expressions/DictExpression.cs +++ b/Queuebal.Expressions/DictExpression.cs @@ -30,7 +30,7 @@ protected override JSONValue EvaluateExpression(ExpressionContext context, JSONV var output = new Dictionary(); foreach (var kv in Value) { - var key = Tokenizer.Evaluate(kv.Key, context.DataProvider); + var key = Tokenizer.Evaluate(kv.Key, context.VariableProvider); if (!key.IsString) { throw new InvalidOperationException("Dict keys must evaluate to a string."); diff --git a/Queuebal.Expressions/ExpressionContext.cs b/Queuebal.Expressions/ExpressionContext.cs index 59feded..70301bb 100644 --- a/Queuebal.Expressions/ExpressionContext.cs +++ b/Queuebal.Expressions/ExpressionContext.cs @@ -11,14 +11,14 @@ public class ExpressionContext /// /// Initializes a new instance of the class. /// - /// The dataprovider used to resolve variable values when evaluating an expression. - public ExpressionContext(DataProvider dataProvider) + /// The dataprovider used to resolve variable values when evaluating an expression. + public ExpressionContext(VariableProvider variableProvider) { - DataProvider = dataProvider; + VariableProvider = variableProvider; } /// - /// The DataProvider used when evaluating expressions. + /// The VariableProvider used when evaluating expressions. /// - public DataProvider DataProvider { get; } + public VariableProvider VariableProvider { get; } } diff --git a/Queuebal.Expressions/IExpression.cs b/Queuebal.Expressions/IExpression.cs index abb0ae5..a6672b2 100644 --- a/Queuebal.Expressions/IExpression.cs +++ b/Queuebal.Expressions/IExpression.cs @@ -49,14 +49,14 @@ public JSONValue Evaluate(ExpressionContext context, JSONValue inputValue) // represents a variable value in the context's data provider if (inputValue.IsString) { - inputValue = Tokenizer.Evaluate(inputValue.StringValue, context.DataProvider); + inputValue = Tokenizer.Evaluate(inputValue.StringValue, context.VariableProvider); } // Evaluate the expression with the provided context and input value var result = EvaluateExpression(context, inputValue); if (result.IsString) { - result = Tokenizer.Evaluate(result.StringValue, context.DataProvider); + result = Tokenizer.Evaluate(result.StringValue, context.VariableProvider); } return result; diff --git a/Queuebal.Expressions/IMutation.cs b/Queuebal.Expressions/IMutation.cs index f8b45a7..8c76446 100644 --- a/Queuebal.Expressions/IMutation.cs +++ b/Queuebal.Expressions/IMutation.cs @@ -50,7 +50,7 @@ public JSONValue Evaluate(ExpressionContext context, JSONValue inputValue) if (result.IsString) { // If the result is a string, evaluate it as a token - result = Tokenizer.Evaluate(result.StringValue, context.DataProvider); + result = Tokenizer.Evaluate(result.StringValue, context.VariableProvider); } return result; } diff --git a/Queuebal.Json.Data/DataProvider.cs b/Queuebal.Json.Data/DataProvider.cs index c91f4e0..2ae16b2 100644 --- a/Queuebal.Json.Data/DataProvider.cs +++ b/Queuebal.Json.Data/DataProvider.cs @@ -4,43 +4,43 @@ namespace Queuebal.Json.Data; /// Provides disposable access to a data provider scope. -public class DataProviderScopeAccess : IDisposable +public class VariableProviderScopeAccess : IDisposable { /// Is the scope access disposed of yet. private int _disposed = 0; - /// The DataProvider the scope was added to. - private readonly DataProvider _dataProvider; + /// The VariableProvider the scope was added to. + private readonly VariableProvider _variableProvider; - /// The DataProviderScope that was added to the DataProvider. - private readonly DataProviderScope _scope; + /// The VariableProviderScope that was added to the VariableProvider. + private readonly VariableProviderScope _scope; /// - /// Initializes a new instance of the DataProviderScopeAccess object, and pushes - /// the scope onto the scope stack of the given DataProvider. + /// Initializes a new instance of the VariableProviderScopeAccess object, and pushes + /// the scope onto the scope stack of the given VariableProvider. /// - /// The DataProvider to add the scope to. - /// The scope to add to the DataProvider. - public DataProviderScopeAccess(DataProvider dataProvider, DataProviderScope scope) + /// The VariableProvider to add the scope to. + /// The scope to add to the VariableProvider. + public VariableProviderScopeAccess(VariableProvider variableProvider, VariableProviderScope scope) { - _dataProvider = dataProvider; + _variableProvider = variableProvider; _scope = scope; - _dataProvider.PushScope(scope); + _variableProvider.PushScope(scope); } - ~DataProviderScopeAccess() + ~VariableProviderScopeAccess() { Dispose(false); } /// - /// Gets the scope that was added to the DataProvider. + /// Gets the scope that was added to the VariableProvider. /// - public DataProviderScope Scope => _scope; + public VariableProviderScope Scope => _scope; /// - /// Disposes of the DataProviderScopeAccess and removes the DataProviderScope from the DataProvider. + /// Disposes of the VariableProviderScopeAccess and removes the VariableProviderScope from the VariableProvider. /// public void Dispose() { @@ -48,7 +48,7 @@ public void Dispose() } /// - /// Disposes of the DataProviderScopeAccess and removes the DataProviderScope from the DataProvider. + /// Disposes of the VariableProviderScopeAccess and removes the VariableProviderScope from the VariableProvider. /// private void Dispose(bool disposing) { @@ -59,16 +59,16 @@ private void Dispose(bool disposing) if (disposing) { - _dataProvider.RemoveScope(_scope); + _variableProvider.RemoveScope(_scope); } } } /// -/// Defines a Scope for a DataProvider to store values in. +/// Defines a Scope for a VariableProvider to store values in. /// -public class DataProviderScope +public class VariableProviderScope { /// /// The name of the scope. @@ -81,10 +81,10 @@ public class DataProviderScope private readonly Dictionary _values = new(); /// - /// Initializes a new instance of a DataProviderScope, with the specified name. + /// Initializes a new instance of a VariableProviderScope, with the specified name. /// /// The name of the new scope. - public DataProviderScope(string scopeName, Dictionary? values = null) + public VariableProviderScope(string scopeName, Dictionary? values = null) { _scopeName = scopeName; if (values != null) @@ -97,7 +97,7 @@ public DataProviderScope(string scopeName, Dictionary? values } /// - /// Gets the name of the DataProviderScope. + /// Gets the name of the VariableProviderScope. /// public string Name => _scopeName; @@ -125,7 +125,7 @@ public bool SetValue(string key, JSONValue newValue) /// The value to add. /// The current scope. /// If a value with the given key already exists, it will be overwritten. - public DataProviderScope AddValue(string key, JSONValue value) + public VariableProviderScope AddValue(string key, JSONValue value) { _values[key] = value; return this; @@ -137,7 +137,7 @@ public DataProviderScope AddValue(string key, JSONValue value) /// The values to add to the scope. /// The current scope. /// If a value with the given key already exists, it will be overwritten. - public DataProviderScope AddValues(Dictionary values) + public VariableProviderScope AddValues(Dictionary values) { foreach (var keyValue in values) { @@ -158,18 +158,18 @@ public DataProviderScope AddValues(Dictionary values) /// -/// Provides access to data stored in memory, using a stack of DataProviderScopes to +/// Provides access to data stored in memory, using a stack of VariableProviderScopes to /// store and access values. /// -public class DataProvider +public class VariableProvider { - private readonly DataProviderScope _rootScope = new DataProviderScope("__root"); - private readonly List _scopes = new(); - private readonly Dictionary> _scopesMap = new(); - private DataProviderScope _currentScope; + private readonly VariableProviderScope _rootScope = new VariableProviderScope("__root"); + private readonly List _scopes = new(); + private readonly Dictionary> _scopesMap = new(); + private VariableProviderScope _currentScope; - /// Initializes a new instance of the DataProvider class. - public DataProvider() + /// Initializes a new instance of the VariableProvider class. + public VariableProvider() { _currentScope = _rootScope; _scopes.Add(_rootScope); @@ -202,9 +202,9 @@ public JSONValue SetValue(string key, JSONValue newValue) /// /// The key of the value to add. /// The value to add. - /// The current DataProvider. + /// The current VariableProvider. /// If a value with the given key already exists, it will be overwritten. - public DataProvider AddRootValue(string key, JSONValue value) + public VariableProvider AddRootValue(string key, JSONValue value) { _rootScope.AddValue(key, value); return this; @@ -214,9 +214,9 @@ public DataProvider AddRootValue(string key, JSONValue value) /// Adds a dictionary of values to the root scope. /// /// The values to add to the root scope. - /// The current DataProvider. + /// The current VariableProvider. /// If a value with the given key already exists, it will be overwritten. - public DataProvider AddRootValues(Dictionary values) + public VariableProvider AddRootValues(Dictionary values) { _rootScope.AddValues(values); return this; @@ -224,7 +224,7 @@ public DataProvider AddRootValues(Dictionary values) /// Adds a value to the current scope. /// If a value with the given key already exists, it will be overwritten. - public DataProvider AddValue(string key, JSONValue value) + public VariableProvider AddValue(string key, JSONValue value) { _currentScope.AddValue(key, value); return this; @@ -234,9 +234,9 @@ public DataProvider AddValue(string key, JSONValue value) /// Adds a dictionary of values to the current scope. /// /// The values to add to the current scope. - /// The current DataProvider. + /// The current VariableProvider. /// If a value with the given key already exists, it will be overwritten. - public DataProvider AddValues(Dictionary values) + public VariableProvider AddValues(Dictionary values) { _currentScope.AddValues(values); return this; @@ -247,10 +247,10 @@ public DataProvider AddValues(Dictionary values) /// /// The name of the variable to add. /// The value to assign to the variable. - /// The current DataProvider. + /// The current VariableProvider. /// If the currentScope is the rootScope, the key/value will be added to the currentScope. /// If a value with the given key already exists, it will be overwritten. - public DataProvider AddParentValue(string key, JSONValue value) + public VariableProvider AddParentValue(string key, JSONValue value) { if (_scopes.Count == 1) { @@ -269,8 +269,8 @@ public DataProvider AddParentValue(string key, JSONValue value) /// Adds a scope to the top of the scope stack. /// /// The scope to add. - /// The current DataProvider. - public DataProvider PushScope(DataProviderScope scope) + /// The current VariableProvider. + public VariableProvider PushScope(VariableProviderScope scope) { _scopes.Add(scope); _currentScope = scope; @@ -280,8 +280,8 @@ public DataProvider PushScope(DataProviderScope scope) /// /// Removes the last scope added to the scopes stack. /// - /// The current DataProvider. - public DataProvider PopScope() + /// The current VariableProvider. + public VariableProvider PopScope() { // we don't want to pop the root scope, so make sure there's // more than one scope registered. @@ -295,16 +295,16 @@ public DataProvider PopScope() } /// - /// Removes the specified DataProviderScope from the stack of scopes. + /// Removes the specified VariableProviderScope from the stack of scopes. /// /// The scope to remove. - /// The current DataProvider. - public DataProvider RemoveScope(DataProviderScope scope) + /// The current VariableProvider. + public VariableProvider RemoveScope(VariableProviderScope scope) { // we expect the scope to be at the top of the stack, so check there first. if (scope == _rootScope) { - throw new InvalidOperationException("Cannot remove the root scope from the DataProvider."); + throw new InvalidOperationException("Cannot remove the root scope from the VariableProvider."); } if (_scopes[^1] == scope) @@ -315,7 +315,7 @@ public DataProvider RemoveScope(DataProviderScope scope) if (!_scopes.Remove(scope)) { - throw new InvalidOperationException("The specified scope does not belong to the current DataProvider"); + throw new InvalidOperationException("The specified scope does not belong to the current VariableProvider"); } return this; @@ -328,10 +328,10 @@ public DataProvider RemoveScope(DataProviderScope scope) /// The scope to add to the /// /// - public DataProviderScopeAccess WithScope(string scopeName, Dictionary? values = null) + public VariableProviderScopeAccess WithScope(string scopeName, Dictionary? values = null) { - var scope = new DataProviderScope(scopeName, values); - return new DataProviderScopeAccess(this, scope); + var scope = new VariableProviderScope(scopeName, values); + return new VariableProviderScopeAccess(this, scope); } /// diff --git a/Queuebal.Json.Data/Tokenizer.cs b/Queuebal.Json.Data/Tokenizer.cs index 88ea45b..adddce4 100644 --- a/Queuebal.Json.Data/Tokenizer.cs +++ b/Queuebal.Json.Data/Tokenizer.cs @@ -44,14 +44,14 @@ public static class Tokenizer /// and returns the concatenated string as a JSONValue. /// /// The input string to tokenize and get the replacement value(s) for. - /// The DataProvider to use to find the replacement values. + /// The VariableProvider to use to find the replacement values. /// A JSONValue representing the result of the evaluation. /// Thrown when a placeholder token is found, but its value - /// was not found in the DataProvider. + /// was not found in the VariableProvider. /// - public static JSONValue Evaluate(string inputValue, DataProvider dataProvider) + public static JSONValue Evaluate(string inputValue, VariableProvider variableProvider) { - var tokens = GetTokens(inputValue, dataProvider); + var tokens = GetTokens(inputValue, variableProvider); if (!tokens.Any()) { return inputValue; @@ -92,10 +92,10 @@ public static JSONValue Evaluate(string inputValue, DataProvider dataProvider) /// Gets the tokens from the input value. /// /// - /// + /// /// /// - public static IEnumerable GetTokens(string inputValue, DataProvider dataProvider) + public static IEnumerable GetTokens(string inputValue, VariableProvider variableProvider) { bool inPlaceholder = false; var currentTokenText = new StringBuilder(); @@ -164,7 +164,7 @@ public static IEnumerable GetTokens(string inputValue, DataProvider dataP // Skip the opening '${' chars, we didn't add the closing '}' to currentTokenText var tokenText = currentTokenText.ToString().Substring(2, currentTokenText.Length - 2); - var replacementValue = dataProvider.GetValue(tokenText); + var replacementValue = variableProvider.GetValue(tokenText); if (replacementValue == null) { throw new KeyNotFoundException($"Token '{tokenText}' has no replacement value."); diff --git a/Queuebal.UnitTests.Examples/TestExampleData.cs b/Queuebal.UnitTests.Examples/TestExampleData.cs index 148817c..f59cb92 100644 --- a/Queuebal.UnitTests.Examples/TestExampleData.cs +++ b/Queuebal.UnitTests.Examples/TestExampleData.cs @@ -26,7 +26,7 @@ public void test_expression_output_matches_expected(object expectedResult, objec // inputData[0] is a string containing the name of the test case. // inputData[1] is a JSONValue containing the data to transform. // inputData[2] is a deserialized expression to apply to the data to transform. - // inputData[3] is an optional DataProvider that can be used for variable substitution in the expression. + // inputData[3] is an optional VariableProvider that can be used for variable substitution in the expression. // expectedResult is a JSONValue containing the expected result of the transformation. if (inputData.Length < 3) { @@ -48,17 +48,17 @@ public void test_expression_output_matches_expected(object expectedResult, objec return; } - // DataProvider is an optional input we can use for variable substitution if the expression requires it. - var dataProvider = new DataProvider(); - if (inputData.Length > 3 && inputData[3] is DataProvider) + // VariableProvider is an optional input we can use for variable substitution if the expression requires it. + var variableProvider = new VariableProvider(); + if (inputData.Length > 3 && inputData[3] is VariableProvider) { - dataProvider = (DataProvider)inputData[3]; + variableProvider = (VariableProvider)inputData[3]; } var expected = (JSONValue)expectedResult; // Act - var expressionResult = expression.Evaluate(new ExpressionContext(dataProvider), sourceData); + var expressionResult = expression.Evaluate(new ExpressionContext(variableProvider), sourceData); // Assert Assert.AreEqual(expected, expressionResult); @@ -94,7 +94,7 @@ private static IEnumerable GetTestData() // result[1][0] is a string containing the name of the test case. // result[1][1] is a JSONValue containing the data to transform. // result[1][2] is a deserialized expression to apply to the data to transform. - // result[1][3] is an optional DataProvider that can be used for variable substitution in the expression. + // result[1][3] is an optional VariableProvider that can be used for variable substitution in the expression. // yield a first test case that should always pass, i.e. test the test method itself yield return new object[] @@ -105,7 +105,7 @@ private static IEnumerable GetTestData() "Sample Test Case", new JSONValue("Original Data"), new ValueExpression { Value = new JSONValue("Transformed Data ${var_name}") }, - new DataProvider().AddValue("var_name", "with Variable"), + new VariableProvider().AddValue("var_name", "with Variable"), } }; @@ -114,8 +114,8 @@ private static IEnumerable GetTestData() var inputValue = new JSONValue("test"); var mutation = new StringSplitMutation { Separators = new List { "." } }; var condition = new EqualsCondition { ComparerValue = new ValueExpression { Value = "test" } }; - mutation.Evaluate(new ExpressionContext(new DataProvider()), inputValue); - condition.Evaluate(new ExpressionContext(new DataProvider()), inputValue); + mutation.Evaluate(new ExpressionContext(new VariableProvider()), inputValue); + condition.Evaluate(new ExpressionContext(new VariableProvider()), inputValue); // build the type registry used to deserialize the expressions var expressionTypeRegistry = TypeRegistryService.BuildFromCurrentAppDomain("ExpressionType"); @@ -150,12 +150,12 @@ private static IEnumerable GetTestData() continue; // Skip files that do not have a corresponding expression file } - var dataProviderFile = Path.Combine("Examples", $"{testName}.data_provider.json"); + var variableProviderFile = Path.Combine("Examples", $"{testName}.data_provider.json"); var inputData = BuildJsonValue(file); var outputData = BuildJsonValue(outputFile); var expression = BuildExpression(expressionFile, typeResolver); - var dataProvider = BuildDataProvider(dataProviderFile); + var variableProvider = BuildVariableProvider(variableProviderFile); yield return new object[] { @@ -165,7 +165,7 @@ private static IEnumerable GetTestData() testName, inputData, expression, - dataProvider, + variableProvider, } }; } @@ -212,64 +212,64 @@ private static IExpression BuildExpression(string filePath, CompositeTypeResolve } /// - /// Builds a DataProvider with a single scope from the JSON data in the specified file. + /// Builds a VariableProvider with a single scope from the JSON data in the specified file. /// - /// The path of the file containing the DataProvider data to deserialize. - /// A new DataProvider containing the values from the serialized JSON data. - private static DataProvider BuildDataProvider(string filePath) + /// The path of the file containing the VariableProvider data to deserialize. + /// A new VariableProvider containing the values from the serialized JSON data. + private static VariableProvider BuildVariableProvider(string filePath) { - // Read the data provider file and deserialize it into a DataProvider + // Read the data provider file and deserialize it into a VariableProvider if (!File.Exists(filePath)) { - return new DataProvider(); // Return an empty DataProvider if the file does not exist + return new VariableProvider(); // Return an empty VariableProvider if the file does not exist } var fileContent = File.ReadAllText(filePath); if (string.IsNullOrWhiteSpace(fileContent)) { - return new DataProvider(); // Return an empty DataProvider if the file is empty + return new VariableProvider(); // Return an empty VariableProvider if the file is empty } var jsonData = JsonSerializer.Deserialize>(fileContent); if (jsonData is null) { - return new DataProvider(); // Return an empty DataProvider if the JSON data is null + return new VariableProvider(); // Return an empty VariableProvider if the JSON data is null } - var dataProvider = new DataProvider(); + var variableProvider = new VariableProvider(); foreach (var kv in jsonData) { switch (kv.Value) { case string strValue: - dataProvider.AddValue(kv.Key, new JSONValue(strValue)); + variableProvider.AddValue(kv.Key, new JSONValue(strValue)); break; case int intValue: - dataProvider.AddValue(kv.Key, new JSONValue(intValue)); + variableProvider.AddValue(kv.Key, new JSONValue(intValue)); break; case bool boolValue: - dataProvider.AddValue(kv.Key, new JSONValue(boolValue)); + variableProvider.AddValue(kv.Key, new JSONValue(boolValue)); break; case double doubleValue: - dataProvider.AddValue(kv.Key, new JSONValue(doubleValue)); + variableProvider.AddValue(kv.Key, new JSONValue(doubleValue)); break; case List listValue: - dataProvider.AddValue(kv.Key, (JSONValue)listValue); + variableProvider.AddValue(kv.Key, (JSONValue)listValue); break; case Dictionary dictValue: - dataProvider.AddValue(kv.Key, (JSONValue)dictValue); + variableProvider.AddValue(kv.Key, (JSONValue)dictValue); break; case JsonElement jsonElement: // If the value is a JsonElement, convert it to JSONValue - dataProvider.AddValue(kv.Key, new JSONValue(jsonElement)); + variableProvider.AddValue(kv.Key, new JSONValue(jsonElement)); break; case null: - dataProvider.AddValue(kv.Key, new JSONValue()); + variableProvider.AddValue(kv.Key, new JSONValue()); break; default: throw new InvalidOperationException($"Unsupported value type: {kv.Value.GetType()} for key: {kv.Key}"); } } - return dataProvider; + return variableProvider; } } diff --git a/Queuebal.UnitTests.Expressions.Conditions/TestConditionSet.cs b/Queuebal.UnitTests.Expressions.Conditions/TestConditionSet.cs index 34bb743..c3ed87d 100644 --- a/Queuebal.UnitTests.Expressions.Conditions/TestConditionSet.cs +++ b/Queuebal.UnitTests.Expressions.Conditions/TestConditionSet.cs @@ -17,7 +17,7 @@ public void test_evaluate_when_operator_is_and_and_last_condition_is_false() Operator = ConditionSetOperator.And }; - bool result = conditionSet.Evaluate(new ExpressionContext(new Queuebal.Json.Data.DataProvider()), new JSONValue("test")); + bool result = conditionSet.Evaluate(new ExpressionContext(new Queuebal.Json.Data.VariableProvider()), new JSONValue("test")); Assert.IsFalse(result); } @@ -30,7 +30,7 @@ public void test_evaluate_when_operator_is_and_and_first_condition_is_false() Operator = ConditionSetOperator.And }; - bool result = conditionSet.Evaluate(new ExpressionContext(new Queuebal.Json.Data.DataProvider()), new JSONValue("test")); + bool result = conditionSet.Evaluate(new ExpressionContext(new Queuebal.Json.Data.VariableProvider()), new JSONValue("test")); Assert.IsFalse(result); } @@ -44,7 +44,7 @@ public void test_evaluate_when_operator_is_and_and_all_conditions_are_true() Operator = ConditionSetOperator.And }; - bool result = conditionSet.Evaluate(new ExpressionContext(new Queuebal.Json.Data.DataProvider()), new JSONValue("test")); + bool result = conditionSet.Evaluate(new ExpressionContext(new Queuebal.Json.Data.VariableProvider()), new JSONValue("test")); Assert.IsTrue(result); } @@ -58,7 +58,7 @@ public void test_evaluate_when_operator_is_or_and_last_condition_is_true() Operator = ConditionSetOperator.Or }; - bool result = conditionSet.Evaluate(new ExpressionContext(new Queuebal.Json.Data.DataProvider()), new JSONValue()); + bool result = conditionSet.Evaluate(new ExpressionContext(new Queuebal.Json.Data.VariableProvider()), new JSONValue()); Assert.IsTrue(result); } @@ -71,7 +71,7 @@ public void test_evaluate_when_operator_is_and_and_first_condition_is_true() Operator = ConditionSetOperator.Or }; - bool result = conditionSet.Evaluate(new ExpressionContext(new Queuebal.Json.Data.DataProvider()), new JSONValue()); + bool result = conditionSet.Evaluate(new ExpressionContext(new Queuebal.Json.Data.VariableProvider()), new JSONValue()); Assert.IsTrue(result); } @@ -85,7 +85,7 @@ public void test_evaluate_when_has_value_selector() ValueSelector = new DataSelectorExpression { Path = "testKey" } }; - var context = new ExpressionContext(new Queuebal.Json.Data.DataProvider()); + var context = new ExpressionContext(new Queuebal.Json.Data.VariableProvider()); var inputValue = new JSONValue(new Dictionary { { "testKey", new JSONValue("test") } @@ -104,7 +104,7 @@ public void test_evaluate_when_operator_is_and_and_all_conditions_are_false() Operator = ConditionSetOperator.Or }; - bool result = conditionSet.Evaluate(new ExpressionContext(new Queuebal.Json.Data.DataProvider()), new JSONValue()); + bool result = conditionSet.Evaluate(new ExpressionContext(new Queuebal.Json.Data.VariableProvider()), new JSONValue()); Assert.IsFalse(result); } @@ -117,7 +117,7 @@ public void test_evaluate_when_condition_set_is_empty() Operator = ConditionSetOperator.And }; - bool result = conditionSet.Evaluate(new ExpressionContext(new Queuebal.Json.Data.DataProvider()), new JSONValue("test")); + bool result = conditionSet.Evaluate(new ExpressionContext(new Queuebal.Json.Data.VariableProvider()), new JSONValue("test")); Assert.IsTrue(result); // Default behavior is to return true when there are no conditions } @@ -131,7 +131,7 @@ public void test_evaluate_when_condition_set_is_empty_and_negate_result_is_true( NegateResult = true, }; - bool result = conditionSet.Evaluate(new ExpressionContext(new Queuebal.Json.Data.DataProvider()), new JSONValue("test")); + bool result = conditionSet.Evaluate(new ExpressionContext(new Queuebal.Json.Data.VariableProvider()), new JSONValue("test")); Assert.IsFalse(result); } diff --git a/Queuebal.UnitTests.Expressions.Conditions/TestEqualsCondition.cs b/Queuebal.UnitTests.Expressions.Conditions/TestEqualsCondition.cs index fda7e26..a21d088 100644 --- a/Queuebal.UnitTests.Expressions.Conditions/TestEqualsCondition.cs +++ b/Queuebal.UnitTests.Expressions.Conditions/TestEqualsCondition.cs @@ -16,7 +16,7 @@ public void test_evaluate_when_values_are_equal() ComparerValue = new ValueExpression { Value = new("test") } }; - var context = new ExpressionContext(new Queuebal.Json.Data.DataProvider()); + var context = new ExpressionContext(new Queuebal.Json.Data.VariableProvider()); var inputValue = new JSONValue("test"); bool result = condition.Evaluate(context, inputValue); @@ -31,7 +31,7 @@ public void test_evaluate_when_values_are_not_equal() ComparerValue = new ValueExpression { Value = new("test") } }; - var context = new ExpressionContext(new Queuebal.Json.Data.DataProvider()); + var context = new ExpressionContext(new Queuebal.Json.Data.VariableProvider()); var inputValue = new JSONValue("testing"); bool result = condition.Evaluate(context, inputValue); @@ -48,7 +48,7 @@ public void test_evaluate_when_values_are_not_equal_and_negate_result() ComparerValue = new ValueExpression { Value = new("test") } }; - var context = new ExpressionContext(new Queuebal.Json.Data.DataProvider()); + var context = new ExpressionContext(new Queuebal.Json.Data.VariableProvider()); var inputValue = new JSONValue("testing"); bool result = condition.Evaluate(context, inputValue); diff --git a/Queuebal.UnitTests.Expressions.Conditions/TestGreaterThanCondition.cs b/Queuebal.UnitTests.Expressions.Conditions/TestGreaterThanCondition.cs index 23b5247..79995a1 100644 --- a/Queuebal.UnitTests.Expressions.Conditions/TestGreaterThanCondition.cs +++ b/Queuebal.UnitTests.Expressions.Conditions/TestGreaterThanCondition.cs @@ -8,7 +8,7 @@ namespace Queuebal.UnitTests.Expressions.Conditions; [TestClass] public class TestGreaterThanCondition { - ExpressionContext Context { get; } = new ExpressionContext(new Json.Data.DataProvider()); + ExpressionContext Context { get; } = new ExpressionContext(new Json.Data.VariableProvider()); [TestMethod] public void test_evaluate_when_input_value_is_greater_than_comparer() diff --git a/Queuebal.UnitTests.Expressions.Conditions/TestGreaterThanOrEqualCondition.cs b/Queuebal.UnitTests.Expressions.Conditions/TestGreaterThanOrEqualCondition.cs index ce7d633..7d66d4d 100644 --- a/Queuebal.UnitTests.Expressions.Conditions/TestGreaterThanOrEqualCondition.cs +++ b/Queuebal.UnitTests.Expressions.Conditions/TestGreaterThanOrEqualCondition.cs @@ -8,7 +8,7 @@ namespace Queuebal.UnitTests.Expressions.Conditions; [TestClass] public class TestGreaterThanOrEqualCondition { - ExpressionContext Context { get; } = new ExpressionContext(new Json.Data.DataProvider()); + ExpressionContext Context { get; } = new ExpressionContext(new Json.Data.VariableProvider()); [TestMethod] public void test_evaluate_when_input_value_is_greater_than_comparer() diff --git a/Queuebal.UnitTests.Expressions.Conditions/TestIsNullCondition.cs b/Queuebal.UnitTests.Expressions.Conditions/TestIsNullCondition.cs index 98c7194..4281ea8 100644 --- a/Queuebal.UnitTests.Expressions.Conditions/TestIsNullCondition.cs +++ b/Queuebal.UnitTests.Expressions.Conditions/TestIsNullCondition.cs @@ -12,7 +12,7 @@ public class TestIsNullCondition public void test_evaluate_when_value_is_null() { var condition = new IsNullCondition(); - var context = new ExpressionContext(new Queuebal.Json.Data.DataProvider()); + var context = new ExpressionContext(new Queuebal.Json.Data.VariableProvider()); var inputValue = new JSONValue(); bool result = condition.Evaluate(context, inputValue); @@ -23,7 +23,7 @@ public void test_evaluate_when_value_is_null() public void test_evaluate_when_value_is_not_null() { var condition = new IsNullCondition(); - var context = new ExpressionContext(new Queuebal.Json.Data.DataProvider()); + var context = new ExpressionContext(new Queuebal.Json.Data.VariableProvider()); var inputValue = new JSONValue("test"); bool result = condition.Evaluate(context, inputValue); @@ -45,7 +45,7 @@ public void test_evaluate_with_input_selector() { { "testKey", new JSONValue("testValue") } }); - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); bool result = condition.Evaluate(context, inputValue); Assert.IsFalse(result); diff --git a/Queuebal.UnitTests.Expressions.Conditions/TestIsNullOrEmptyCondition.cs b/Queuebal.UnitTests.Expressions.Conditions/TestIsNullOrEmptyCondition.cs index c77bb42..b862a4f 100644 --- a/Queuebal.UnitTests.Expressions.Conditions/TestIsNullOrEmptyCondition.cs +++ b/Queuebal.UnitTests.Expressions.Conditions/TestIsNullOrEmptyCondition.cs @@ -8,7 +8,7 @@ namespace Queuebal.UnitTests.Expressions.Conditions; [TestClass] public class TestIsNullOrEmptyCondition { - private ExpressionContext Context { get; } = new ExpressionContext(new Json.Data.DataProvider()); + private ExpressionContext Context { get; } = new ExpressionContext(new Json.Data.VariableProvider()); [TestMethod] public void test_evaluate_when_value_is_null() diff --git a/Queuebal.UnitTests.Expressions.Conditions/TestLengthIsGreaterThanCondition.cs b/Queuebal.UnitTests.Expressions.Conditions/TestLengthIsGreaterThanCondition.cs index b82b47f..bdf60ce 100644 --- a/Queuebal.UnitTests.Expressions.Conditions/TestLengthIsGreaterThanCondition.cs +++ b/Queuebal.UnitTests.Expressions.Conditions/TestLengthIsGreaterThanCondition.cs @@ -8,7 +8,7 @@ namespace Queuebal.UnitTests.Expressions.Conditions; [TestClass] public class TestLengthIsGreaterThanCondition { - ExpressionContext Context { get; } = new ExpressionContext(new Json.Data.DataProvider()); + ExpressionContext Context { get; } = new ExpressionContext(new Json.Data.VariableProvider()); [TestMethod] public void test_evaluate_when_input_is_null_returns_false() diff --git a/Queuebal.UnitTests.Expressions.Conditions/TestLengthIsGreaterThanOrEqualCondition.cs b/Queuebal.UnitTests.Expressions.Conditions/TestLengthIsGreaterThanOrEqualCondition.cs index 0a3aafe..93a57a1 100644 --- a/Queuebal.UnitTests.Expressions.Conditions/TestLengthIsGreaterThanOrEqualCondition.cs +++ b/Queuebal.UnitTests.Expressions.Conditions/TestLengthIsGreaterThanOrEqualCondition.cs @@ -8,7 +8,7 @@ namespace Queuebal.UnitTests.Expressions.Conditions; [TestClass] public class TestLengthIsGreaterThanOrEqualCondition { - ExpressionContext Context { get; } = new ExpressionContext(new Json.Data.DataProvider()); + ExpressionContext Context { get; } = new ExpressionContext(new Json.Data.VariableProvider()); [TestMethod] public void test_evaluate_when_input_is_null_returns_false() diff --git a/Queuebal.UnitTests.Expressions.Conditions/TestLengthIsLessThanCondition.cs b/Queuebal.UnitTests.Expressions.Conditions/TestLengthIsLessThanCondition.cs index 269c595..b130c06 100644 --- a/Queuebal.UnitTests.Expressions.Conditions/TestLengthIsLessThanCondition.cs +++ b/Queuebal.UnitTests.Expressions.Conditions/TestLengthIsLessThanCondition.cs @@ -8,7 +8,7 @@ namespace Queuebal.UnitTests.Expressions.Conditions; [TestClass] public class TestLengthIsLessThanCondition { - ExpressionContext Context { get; } = new ExpressionContext(new Json.Data.DataProvider()); + ExpressionContext Context { get; } = new ExpressionContext(new Json.Data.VariableProvider()); [TestMethod] public void test_evaluate_when_input_is_null_returns_false() diff --git a/Queuebal.UnitTests.Expressions.Conditions/TestLengthIsLessThanOrEqualCondition.cs b/Queuebal.UnitTests.Expressions.Conditions/TestLengthIsLessThanOrEqualCondition.cs index 3dd6435..da94668 100644 --- a/Queuebal.UnitTests.Expressions.Conditions/TestLengthIsLessThanOrEqualCondition.cs +++ b/Queuebal.UnitTests.Expressions.Conditions/TestLengthIsLessThanOrEqualCondition.cs @@ -8,7 +8,7 @@ namespace Queuebal.UnitTests.Expressions.Conditions; [TestClass] public class TestLengthIsLessThanOrEqualCondition { - ExpressionContext Context { get; } = new ExpressionContext(new Json.Data.DataProvider()); + ExpressionContext Context { get; } = new ExpressionContext(new Json.Data.VariableProvider()); [TestMethod] public void test_evaluate_when_input_is_null_returns_false() diff --git a/Queuebal.UnitTests.Expressions.Conditions/TestLessThanCondition.cs b/Queuebal.UnitTests.Expressions.Conditions/TestLessThanCondition.cs index 2175270..408cecf 100644 --- a/Queuebal.UnitTests.Expressions.Conditions/TestLessThanCondition.cs +++ b/Queuebal.UnitTests.Expressions.Conditions/TestLessThanCondition.cs @@ -8,7 +8,7 @@ namespace Queuebal.UnitTests.Expressions.Conditions; [TestClass] public class TestLessThanCondition { - ExpressionContext Context { get; } = new ExpressionContext(new Json.Data.DataProvider()); + ExpressionContext Context { get; } = new ExpressionContext(new Json.Data.VariableProvider()); [TestMethod] public void test_evaluate_when_input_value_is_greater_than_comparer() diff --git a/Queuebal.UnitTests.Expressions.Conditions/TestLessThanOrEqualCondition.cs b/Queuebal.UnitTests.Expressions.Conditions/TestLessThanOrEqualCondition.cs index e117ddd..bde19d1 100644 --- a/Queuebal.UnitTests.Expressions.Conditions/TestLessThanOrEqualCondition.cs +++ b/Queuebal.UnitTests.Expressions.Conditions/TestLessThanOrEqualCondition.cs @@ -8,7 +8,7 @@ namespace Queuebal.UnitTests.Expressions.Conditions; [TestClass] public class TestLessThanOrEqualCondition { - ExpressionContext Context { get; } = new ExpressionContext(new Json.Data.DataProvider()); + ExpressionContext Context { get; } = new ExpressionContext(new Json.Data.VariableProvider()); [TestMethod] public void test_evaluate_when_input_value_is_greater_than_comparer() diff --git a/Queuebal.UnitTests.Expressions.Mutations/TestAddDaysMutation.cs b/Queuebal.UnitTests.Expressions.Mutations/TestAddDaysMutation.cs index 7691700..c554bc2 100644 --- a/Queuebal.UnitTests.Expressions.Mutations/TestAddDaysMutation.cs +++ b/Queuebal.UnitTests.Expressions.Mutations/TestAddDaysMutation.cs @@ -21,7 +21,7 @@ public void test_evaluate_when_days_is_int() Days = new ValueExpression { Value = new JSONValue(5) } }; - var context = new ExpressionContext(new Queuebal.Json.Data.DataProvider()); + var context = new ExpressionContext(new Queuebal.Json.Data.VariableProvider()); var inputValue = new JSONValue("2023-10-01T12:00:00Z"); var result = mutation.Evaluate(context, inputValue); @@ -38,7 +38,7 @@ public void test_evaluate_when_input_is_not_a_datetime() Days = new ValueExpression { Value = new JSONValue(5) } }; - var context = new ExpressionContext(new Queuebal.Json.Data.DataProvider()); + var context = new ExpressionContext(new Queuebal.Json.Data.VariableProvider()); var inputValue = new JSONValue("not a datetime"); Assert.ThrowsException(() => mutation.Evaluate(context, inputValue)); @@ -52,7 +52,7 @@ public void test_evaluate_when_hours_is_not_a_number() Days = new ValueExpression { Value = new JSONValue("not a number") } }; - var context = new ExpressionContext(new Queuebal.Json.Data.DataProvider()); + var context = new ExpressionContext(new Queuebal.Json.Data.VariableProvider()); var inputValue = new JSONValue(DateTime.Parse("2023-10-01T17:00:00Z").ToUniversalTime()); Assert.ThrowsException(() => mutation.Evaluate(context, inputValue)); diff --git a/Queuebal.UnitTests.Expressions.Mutations/TestAddHoursMutation.cs b/Queuebal.UnitTests.Expressions.Mutations/TestAddHoursMutation.cs index 8d96daf..ec324d3 100644 --- a/Queuebal.UnitTests.Expressions.Mutations/TestAddHoursMutation.cs +++ b/Queuebal.UnitTests.Expressions.Mutations/TestAddHoursMutation.cs @@ -21,7 +21,7 @@ public void test_evaluate_when_hours_is_int() Hours = new ValueExpression { Value = new JSONValue(5) } }; - var context = new ExpressionContext(new Queuebal.Json.Data.DataProvider()); + var context = new ExpressionContext(new Queuebal.Json.Data.VariableProvider()); var inputValue = new JSONValue("2023-10-01T12:00:00Z"); var result = mutation.Evaluate(context, inputValue); @@ -39,7 +39,7 @@ public void test_evaluate_when_input_is_not_a_datetime() Hours = new ValueExpression { Value = new JSONValue(5) } }; - var context = new ExpressionContext(new Queuebal.Json.Data.DataProvider()); + var context = new ExpressionContext(new Queuebal.Json.Data.VariableProvider()); var inputValue = new JSONValue("not a datetime"); Assert.ThrowsException(() => mutation.Evaluate(context, inputValue)); @@ -53,7 +53,7 @@ public void test_evaluate_when_hours_is_not_a_number() Hours = new ValueExpression { Value = new JSONValue("not a number") } }; - var context = new ExpressionContext(new Queuebal.Json.Data.DataProvider()); + var context = new ExpressionContext(new Queuebal.Json.Data.VariableProvider()); var inputValue = new JSONValue(DateTime.Parse("2023-10-01T17:00:00Z").ToUniversalTime()); Assert.ThrowsException(() => mutation.Evaluate(context, inputValue)); diff --git a/Queuebal.UnitTests.Expressions.Mutations/TestAddMinutesMutation.cs b/Queuebal.UnitTests.Expressions.Mutations/TestAddMinutesMutation.cs index 2e53e43..903c92b 100644 --- a/Queuebal.UnitTests.Expressions.Mutations/TestAddMinutesMutation.cs +++ b/Queuebal.UnitTests.Expressions.Mutations/TestAddMinutesMutation.cs @@ -21,7 +21,7 @@ public void test_evaluate_when_hours_is_int() Minutes = new ValueExpression { Value = new JSONValue(5) } }; - var context = new ExpressionContext(new Queuebal.Json.Data.DataProvider()); + var context = new ExpressionContext(new Queuebal.Json.Data.VariableProvider()); var inputValue = new JSONValue("2023-10-01T12:00:00Z"); var result = mutation.Evaluate(context, inputValue); @@ -39,7 +39,7 @@ public void test_evaluate_when_input_is_not_a_datetime() Minutes = new ValueExpression { Value = new JSONValue(5) } }; - var context = new ExpressionContext(new Queuebal.Json.Data.DataProvider()); + var context = new ExpressionContext(new Queuebal.Json.Data.VariableProvider()); var inputValue = new JSONValue("not a datetime"); Assert.ThrowsException(() => mutation.Evaluate(context, inputValue)); @@ -53,7 +53,7 @@ public void test_evaluate_when_hours_is_not_a_number() Minutes = new ValueExpression { Value = new JSONValue("not a number") } }; - var context = new ExpressionContext(new Queuebal.Json.Data.DataProvider()); + var context = new ExpressionContext(new Queuebal.Json.Data.VariableProvider()); var inputValue = new JSONValue(DateTime.Parse("2023-10-01T17:00:00Z").ToUniversalTime()); Assert.ThrowsException(() => mutation.Evaluate(context, inputValue)); diff --git a/Queuebal.UnitTests.Expressions.Mutations/TestAddSecondsMutation.cs b/Queuebal.UnitTests.Expressions.Mutations/TestAddSecondsMutation.cs index ffc7655..abdedf9 100644 --- a/Queuebal.UnitTests.Expressions.Mutations/TestAddSecondsMutation.cs +++ b/Queuebal.UnitTests.Expressions.Mutations/TestAddSecondsMutation.cs @@ -21,7 +21,7 @@ public void test_evaluate_when_hours_is_int() Seconds = new ValueExpression { Value = new JSONValue(5) } }; - var context = new ExpressionContext(new Queuebal.Json.Data.DataProvider()); + var context = new ExpressionContext(new Queuebal.Json.Data.VariableProvider()); var inputValue = new JSONValue("2023-10-01T12:00:00Z"); var result = mutation.Evaluate(context, inputValue); @@ -39,7 +39,7 @@ public void test_evaluate_when_input_is_not_a_datetime() Seconds = new ValueExpression { Value = new JSONValue(5) } }; - var context = new ExpressionContext(new Queuebal.Json.Data.DataProvider()); + var context = new ExpressionContext(new Queuebal.Json.Data.VariableProvider()); var inputValue = new JSONValue("not a datetime"); Assert.ThrowsException(() => mutation.Evaluate(context, inputValue)); @@ -53,7 +53,7 @@ public void test_evaluate_when_hours_is_not_a_number() Seconds = new ValueExpression { Value = new JSONValue("not a number") } }; - var context = new ExpressionContext(new Queuebal.Json.Data.DataProvider()); + var context = new ExpressionContext(new Queuebal.Json.Data.VariableProvider()); var inputValue = new JSONValue(DateTime.Parse("2023-10-01T17:00:00Z").ToUniversalTime()); Assert.ThrowsException(() => mutation.Evaluate(context, inputValue)); diff --git a/Queuebal.UnitTests.Expressions.Mutations/TestAddYearsMutation.cs b/Queuebal.UnitTests.Expressions.Mutations/TestAddYearsMutation.cs index 2c80cb6..6e02768 100644 --- a/Queuebal.UnitTests.Expressions.Mutations/TestAddYearsMutation.cs +++ b/Queuebal.UnitTests.Expressions.Mutations/TestAddYearsMutation.cs @@ -21,7 +21,7 @@ public void test_evaluate_when_hours_is_int() Years = new ValueExpression { Value = new JSONValue(5) } }; - var context = new ExpressionContext(new Queuebal.Json.Data.DataProvider()); + var context = new ExpressionContext(new Queuebal.Json.Data.VariableProvider()); var inputValue = new JSONValue("2023-10-01T12:00:00Z"); var result = mutation.Evaluate(context, inputValue); @@ -39,7 +39,7 @@ public void test_evaluate_when_input_is_not_a_datetime() Years = new ValueExpression { Value = new JSONValue(5) } }; - var context = new ExpressionContext(new Queuebal.Json.Data.DataProvider()); + var context = new ExpressionContext(new Queuebal.Json.Data.VariableProvider()); var inputValue = new JSONValue("not a datetime"); Assert.ThrowsException(() => mutation.Evaluate(context, inputValue)); @@ -53,7 +53,7 @@ public void test_evaluate_when_hours_is_not_a_number() Years = new ValueExpression { Value = new JSONValue("not a number") } }; - var context = new ExpressionContext(new Queuebal.Json.Data.DataProvider()); + var context = new ExpressionContext(new Queuebal.Json.Data.VariableProvider()); var inputValue = new JSONValue(DateTime.Parse("2023-10-01T17:00:00Z").ToUniversalTime()); Assert.ThrowsException(() => mutation.Evaluate(context, inputValue)); diff --git a/Queuebal.UnitTests.Expressions.Mutations/TestCullDictMutation.cs b/Queuebal.UnitTests.Expressions.Mutations/TestCullDictMutation.cs index 19001d4..131a48a 100644 --- a/Queuebal.UnitTests.Expressions.Mutations/TestCullDictMutation.cs +++ b/Queuebal.UnitTests.Expressions.Mutations/TestCullDictMutation.cs @@ -17,7 +17,7 @@ public void test_evaluate_when_input_is_not_dict_or_list_returns_value() { MaxDepth = new ValueExpression { Value = new JSONValue(1) } }; - var context = new ExpressionContext(new Queuebal.Json.Data.DataProvider()); + var context = new ExpressionContext(new Queuebal.Json.Data.VariableProvider()); var inputValue = new JSONValue("not a dict"); var result = mutation.Evaluate(context, inputValue); Assert.AreEqual(inputValue, result); @@ -30,7 +30,7 @@ public void test_evaluate_when_depth_is_not_number_throws_exception() { MaxDepth = new ValueExpression { Value = new JSONValue("not a number") } }; - var context = new ExpressionContext(new Queuebal.Json.Data.DataProvider()); + var context = new ExpressionContext(new Queuebal.Json.Data.VariableProvider()); var inputValue = new JSONValue(new Dictionary()); Assert.ThrowsException(() => mutation.Evaluate(context, inputValue)); } @@ -42,7 +42,7 @@ public void test_evaluate_when_input_value_is_null_returns_null() { MaxDepth = new ValueExpression { Value = new JSONValue(1) } }; - var context = new ExpressionContext(new Queuebal.Json.Data.DataProvider()); + var context = new ExpressionContext(new Queuebal.Json.Data.VariableProvider()); var inputValue = new JSONValue(); var result = mutation.Evaluate(context, inputValue); Assert.IsTrue(result.IsNull); @@ -56,7 +56,7 @@ public void test_when_input_is_list_culls_dict_values() MaxDepth = new ValueExpression { Value = new JSONValue(1) } }; - var context = new ExpressionContext(new Queuebal.Json.Data.DataProvider()); + var context = new ExpressionContext(new Queuebal.Json.Data.VariableProvider()); var inputValue = new JSONValue(new List { @@ -94,7 +94,7 @@ public void test_evaluate_when_depth_is_less_than_1_throws_exception() { MaxDepth = new ValueExpression { Value = new JSONValue(0) } }; - var context = new ExpressionContext(new Queuebal.Json.Data.DataProvider()); + var context = new ExpressionContext(new Queuebal.Json.Data.VariableProvider()); var inputValue = new JSONValue(new Dictionary()); Assert.ThrowsException(() => mutation.Evaluate(context, inputValue)); } @@ -107,7 +107,7 @@ public void test_evaluate_when_input_is_dict_and_depth_is_1() MaxDepth = new ValueExpression { Value = new JSONValue(1) } }; - var context = new ExpressionContext(new Queuebal.Json.Data.DataProvider()); + var context = new ExpressionContext(new Queuebal.Json.Data.VariableProvider()); var inputValue = new JSONValue(new Dictionary { @@ -143,7 +143,7 @@ public void test_evaluate_when_input_is_dict_and_depth_is_2() MaxDepth = new ValueExpression { Value = new JSONValue(2) } }; - var context = new ExpressionContext(new Queuebal.Json.Data.DataProvider()); + var context = new ExpressionContext(new Queuebal.Json.Data.VariableProvider()); var inputValue = new JSONValue(new Dictionary { @@ -184,7 +184,7 @@ public void test_evaluate_when_dict_is_contained_in_list() MaxDepth = new ValueExpression { Value = new JSONValue(2) } }; - var context = new ExpressionContext(new Queuebal.Json.Data.DataProvider()); + var context = new ExpressionContext(new Queuebal.Json.Data.VariableProvider()); var inputValue = new JSONValue(new Dictionary { @@ -232,7 +232,7 @@ public void test_evaluate_when_dict_in_list_of_lists() MaxDepth = new ValueExpression { Value = new JSONValue(2) } }; - var context = new ExpressionContext(new Queuebal.Json.Data.DataProvider()); + var context = new ExpressionContext(new Queuebal.Json.Data.VariableProvider()); var inputValue = new JSONValue(new Dictionary { diff --git a/Queuebal.UnitTests.Expressions.Mutations/TestRemoveNullKeysMutation.cs b/Queuebal.UnitTests.Expressions.Mutations/TestRemoveNullKeysMutation.cs index 4259396..d2eee34 100644 --- a/Queuebal.UnitTests.Expressions.Mutations/TestRemoveNullKeysMutation.cs +++ b/Queuebal.UnitTests.Expressions.Mutations/TestRemoveNullKeysMutation.cs @@ -10,7 +10,7 @@ public class TestRemoveNullKeysMutation { public TestRemoveNullKeysMutation() { - Context = new ExpressionContext(new Json.Data.DataProvider()); + Context = new ExpressionContext(new Json.Data.VariableProvider()); } public ExpressionContext Context { get; } diff --git a/Queuebal.UnitTests.Expressions.Mutations/TestSliceMutation.cs b/Queuebal.UnitTests.Expressions.Mutations/TestSliceMutation.cs index 94462e7..eba1c4d 100644 --- a/Queuebal.UnitTests.Expressions.Mutations/TestSliceMutation.cs +++ b/Queuebal.UnitTests.Expressions.Mutations/TestSliceMutation.cs @@ -14,7 +14,7 @@ public void test_evaluate_when_input_is_not_string_or_list_throws() // Arrange var inputValue = 123; var mutation = new SliceMutation { Start = 0 }; - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); // Act & Assert Assert.ThrowsExactly(() => mutation.Evaluate(context, inputValue)); @@ -30,7 +30,7 @@ public void test_evaluate_when_input_value_is_null_and_expecting_string_returns_ ExpectingString = true, }; - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); // Act var result = mutation.Evaluate(context, inputValue); @@ -50,7 +50,7 @@ public void test_evaluate_when_input_value_is_null_and_not_expecting_string_retu ExpectingString = false, }; - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); // Act var result = mutation.Evaluate(context, inputValue); @@ -70,7 +70,7 @@ public void test_evaluate_when_step_is_less_than_1_throws() Step = -1, }; - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); // Act & Assert Assert.ThrowsExactly(() => mutation.Evaluate(context, inputValue)); @@ -86,7 +86,7 @@ public void test_evaluate_when_start_is_less_than_0_throws() Start = -1, }; - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); // Act & Assert Assert.ThrowsExactly(() => mutation.Evaluate(context, inputValue)); @@ -109,7 +109,7 @@ public void test_evaluate_when_input_is_list_and_stop_is_greater_than_list_count Stop = 10, }; - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); // Act var result = mutation.Evaluate(context, inputValue); @@ -147,7 +147,7 @@ public void test_evaluate_when_input_is_list_and_step_is_greater_than_one() Step = 2, }; - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); // Act var result = mutation.Evaluate(context, inputValue); @@ -176,7 +176,7 @@ public void test_evaluate_when_input_is_string_and_stop_is_greater_than_string_l Stop = inputValue.Length + 5, }; - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); // Act var result = mutation.Evaluate(context, inputValue); @@ -199,7 +199,7 @@ public void test_evaluate_when_input_is_string_and_step_is_greater_than_one() Step = 2, }; - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); // Act var result = mutation.Evaluate(context, inputValue); diff --git a/Queuebal.UnitTests.Expressions.Mutations/TestStringJoinMutation.cs b/Queuebal.UnitTests.Expressions.Mutations/TestStringJoinMutation.cs index a445cbe..7a9ea3f 100644 --- a/Queuebal.UnitTests.Expressions.Mutations/TestStringJoinMutation.cs +++ b/Queuebal.UnitTests.Expressions.Mutations/TestStringJoinMutation.cs @@ -10,7 +10,7 @@ public class TestStringJoinMutation { public TestStringJoinMutation() { - Context = new ExpressionContext(new Json.Data.DataProvider()); + Context = new ExpressionContext(new Json.Data.VariableProvider()); } /// diff --git a/Queuebal.UnitTests.Expressions.Mutations/TestStringSplitMutation.cs b/Queuebal.UnitTests.Expressions.Mutations/TestStringSplitMutation.cs index 0b4637d..eb6d836 100644 --- a/Queuebal.UnitTests.Expressions.Mutations/TestStringSplitMutation.cs +++ b/Queuebal.UnitTests.Expressions.Mutations/TestStringSplitMutation.cs @@ -17,7 +17,7 @@ public void test_evaluate_when_input_is_not_string_throws() Separators = new List { ";" } }; - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); // Act & Assert Assert.ThrowsException(() => mutation.Evaluate(context, new JSONValue(123))); @@ -33,7 +33,7 @@ public void test_evaluate_when_remove_empty_entries_removes_empties() RemoveEmptyEntries = true, }; - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); // Act var result = mutation.Evaluate(context, new JSONValue("value1;;value2;value3")); @@ -57,7 +57,7 @@ public void test_evaluate_when_trim_entries_trims_whitespace() RemoveEmptyEntries = true, }; - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); // Act var result = mutation.Evaluate(context, new JSONValue(" value1 ; value2 ; ; value3 ")); diff --git a/Queuebal.UnitTests.Expressions.Mutations/TestStringTrimMutation.cs b/Queuebal.UnitTests.Expressions.Mutations/TestStringTrimMutation.cs index 6efa8ad..2f3f462 100644 --- a/Queuebal.UnitTests.Expressions.Mutations/TestStringTrimMutation.cs +++ b/Queuebal.UnitTests.Expressions.Mutations/TestStringTrimMutation.cs @@ -7,7 +7,7 @@ namespace Queuebal.UnitTests.Expressions.Mutations; [TestClass] public class TestStringTrimMutation { - private ExpressionContext Context { get; } = new ExpressionContext(new Json.Data.DataProvider()); + private ExpressionContext Context { get; } = new ExpressionContext(new Json.Data.VariableProvider()); [TestMethod] public void test_evaluate_when_input_value_is_not_string_throws() diff --git a/Queuebal.UnitTests.Expressions.Mutations/TestToDateTimeMutation.cs b/Queuebal.UnitTests.Expressions.Mutations/TestToDateTimeMutation.cs index 1bf7539..0ce9576 100644 --- a/Queuebal.UnitTests.Expressions.Mutations/TestToDateTimeMutation.cs +++ b/Queuebal.UnitTests.Expressions.Mutations/TestToDateTimeMutation.cs @@ -13,7 +13,7 @@ public void test_evaluate_when_input_is_string_and_ends_with_z() { var mutation = new ToDateTimeMutation(); - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); var inputValue = new JSONValue("2023-10-01T12:00:00Z"); var result = mutation.Evaluate(context, inputValue); @@ -26,7 +26,7 @@ public void test_evaluate_when_input_is_string_and_ends_with_00_offset() { var mutation = new ToDateTimeMutation(); - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); var inputValue = new JSONValue("2023-10-01T12:00:00+00:00"); var result = mutation.Evaluate(context, inputValue); @@ -39,7 +39,7 @@ public void test_evaluate_when_input_is_string_and_ends_with_non_zero_offset() { var mutation = new ToDateTimeMutation(); - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); var inputValue = new JSONValue("2023-10-01T12:00:00-07:00"); var result = mutation.Evaluate(context, inputValue); @@ -55,7 +55,7 @@ public void test_evaluate_when_input_is_string_and_ends_with_non_zero_offset_and { var mutation = new ToDateTimeMutation { ConvertToUtc = false }; - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); var inputValue = new JSONValue("2023-10-01T12:00:00-07:00"); var result = mutation.Evaluate(context, inputValue); @@ -79,7 +79,7 @@ public void test_evaluate_when_input_is_string_and_not_a_valid_date_time() { var mutation = new ToDateTimeMutation(); - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); var inputValue = new JSONValue("not a date time"); Assert.ThrowsException(() => mutation.Evaluate(context, inputValue)); @@ -90,7 +90,7 @@ public void test_evaluate_when_input_is_float() { var mutation = new ToDateTimeMutation(); - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); var inputValue = new JSONValue(1727808000.0); // This is the Unix timestamp for 2024-10-01T18:40:00Z var result = mutation.Evaluate(context, inputValue); @@ -104,7 +104,7 @@ public void test_evaluate_when_input_is_int() { var mutation = new ToDateTimeMutation(); - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); var inputValue = new JSONValue(1727808000); // This is the Unix timestamp for 2024-10-01T18:40:00Z var result = mutation.Evaluate(context, inputValue); @@ -117,7 +117,7 @@ public void test_evaluate_when_input_is_not_string_or_number_throws_exception() { var mutation = new ToDateTimeMutation(); - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); var inputValue = new JSONValue(true); // Boolean is not a valid date time input Assert.ThrowsException(() => mutation.Evaluate(context, inputValue)); diff --git a/Queuebal.UnitTests.Expressions.Mutations/TestToDictMutation.cs b/Queuebal.UnitTests.Expressions.Mutations/TestToDictMutation.cs index 3753cf0..3bd3ebc 100644 --- a/Queuebal.UnitTests.Expressions.Mutations/TestToDictMutation.cs +++ b/Queuebal.UnitTests.Expressions.Mutations/TestToDictMutation.cs @@ -16,7 +16,7 @@ public class TestToDictMutation public void test_evaluate_when_key_selector_is_null() { // Arrange - var context = new ExpressionContext(new DataProvider()); + var context = new ExpressionContext(new VariableProvider()); var mutation = new ToDictMutation { KeySelector = null, @@ -47,7 +47,7 @@ public void test_evaluate_when_key_selector_is_null() public void test_evaluate_when_input_is_null_returns_empty_dict() { // Arrange - var context = new ExpressionContext(new DataProvider()); + var context = new ExpressionContext(new VariableProvider()); var mutation = new ToDictMutation { KeySelector = null, @@ -67,7 +67,7 @@ public void test_evaluate_when_input_is_null_returns_empty_dict() public void test_evaluate_when_input_is_not_list_throws_exception() { // Arrange - var context = new ExpressionContext(new DataProvider()); + var context = new ExpressionContext(new VariableProvider()); var mutation = new ToDictMutation { KeySelector = null, @@ -84,7 +84,7 @@ public void test_evaluate_when_input_is_not_list_throws_exception() public void test_evaluate_with_key_selector_and_condition() { // Arrange - var context = new ExpressionContext(new DataProvider()); + var context = new ExpressionContext(new VariableProvider()); var mutation = new ToDictMutation { KeySelector = new DataSelectorExpression { Path = "key" }, @@ -141,7 +141,7 @@ public void test_evaluate_with_key_selector_and_condition() public void test_evaluate_when_non_string_key_selected_throws_exception() { // Arrange - var context = new ExpressionContext(new DataProvider()); + var context = new ExpressionContext(new VariableProvider()); var mutation = new ToDictMutation { KeySelector = new DataSelectorExpression { Path = "key" }, diff --git a/Queuebal.UnitTests.Expressions.Mutations/TestToLowerMutation.cs b/Queuebal.UnitTests.Expressions.Mutations/TestToLowerMutation.cs index 019434a..e552caf 100644 --- a/Queuebal.UnitTests.Expressions.Mutations/TestToLowerMutation.cs +++ b/Queuebal.UnitTests.Expressions.Mutations/TestToLowerMutation.cs @@ -13,7 +13,7 @@ public void test_evaluate_when_input_is_not_string_throws() { var mutation = new ToLowerMutation(); - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); var inputValue = new JSONValue(123); // Not a string Assert.ThrowsException(() => mutation.Evaluate(context, inputValue)); @@ -24,7 +24,7 @@ public void test_evaluate_when_input_is_string_returns_uppercase() { var mutation = new ToLowerMutation(); - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); // TODO: Get a better test string that requires invariant-culture-specific casing var inputValue = new JSONValue("TeST StRiNg"); @@ -39,7 +39,7 @@ public void test_evaluate_when_input_is_string_returns_uppercase_with_current_cu { var mutation = new ToLowerMutation { UseInvariantCulture = false }; - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); // TODO: Get a better test string that requires culture-specific casing var inputValue = new JSONValue("TeST StRiNg"); @@ -54,8 +54,8 @@ public void test_evaluate_when_output_is_variable_replaces_value() { var mutation = new ToLowerMutation(); - var context = new ExpressionContext(new Json.Data.DataProvider()); - context.DataProvider.AddValue("output", new JSONValue("New output value")); + var context = new ExpressionContext(new Json.Data.VariableProvider()); + context.VariableProvider.AddValue("output", new JSONValue("New output value")); var inputValue = new JSONValue("${OUTPUT}"); var result = mutation.Evaluate(context, inputValue); diff --git a/Queuebal.UnitTests.Expressions.Mutations/TestToUpperMutation.cs b/Queuebal.UnitTests.Expressions.Mutations/TestToUpperMutation.cs index 6f596c9..37ff85e 100644 --- a/Queuebal.UnitTests.Expressions.Mutations/TestToUpperMutation.cs +++ b/Queuebal.UnitTests.Expressions.Mutations/TestToUpperMutation.cs @@ -13,7 +13,7 @@ public void test_evaluate_when_input_is_not_string_throws() { var mutation = new ToUpperMutation(); - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); var inputValue = new JSONValue(123); // Not a string Assert.ThrowsException(() => mutation.Evaluate(context, inputValue)); @@ -24,7 +24,7 @@ public void test_evaluate_when_input_is_string_returns_uppercase() { var mutation = new ToUpperMutation(); - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); // TODO: Get a better test string that requires invariant-culture-specific casing var inputValue = new JSONValue("test string"); @@ -39,7 +39,7 @@ public void test_evaluate_when_input_is_string_returns_uppercase_with_current_cu { var mutation = new ToUpperMutation { UseInvariantCulture = false }; - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); // TODO: Get a better test string that requires culture-specific casing var inputValue = new JSONValue("test string"); @@ -54,8 +54,8 @@ public void test_evaluate_when_output_is_variable_replaces_value() { var mutation = new ToUpperMutation(); - var context = new ExpressionContext(new Json.Data.DataProvider()); - context.DataProvider.AddValue("OUTPUT", new JSONValue("New output value")); + var context = new ExpressionContext(new Json.Data.VariableProvider()); + context.VariableProvider.AddValue("OUTPUT", new JSONValue("New output value")); var inputValue = new JSONValue("${output}"); var result = mutation.Evaluate(context, inputValue); diff --git a/Queuebal.UnitTests.Expressions.Tools/TestBuilder.cs b/Queuebal.UnitTests.Expressions.Tools/TestBuilder.cs index 81e6d83..dc484fe 100644 --- a/Queuebal.UnitTests.Expressions.Tools/TestBuilder.cs +++ b/Queuebal.UnitTests.Expressions.Tools/TestBuilder.cs @@ -167,7 +167,7 @@ public void test_conditions_all_builds_all_condition() new IsNullCondition { NegateResult = true } ); - var result = condition.Evaluate(new ExpressionContext(new Json.Data.DataProvider()), 123); + var result = condition.Evaluate(new ExpressionContext(new Json.Data.VariableProvider()), 123); Assert.IsTrue(result); } @@ -180,7 +180,7 @@ public void test_conditions_any_builds_any_of_condition() new IsNullCondition() ); - var result = condition.Evaluate(new ExpressionContext(new Json.Data.DataProvider()), new JSONValue()); + var result = condition.Evaluate(new ExpressionContext(new Json.Data.VariableProvider()), new JSONValue()); Assert.IsTrue(result); } @@ -193,7 +193,7 @@ public void test_conditions_none_of_builds_none_of_condition() new IsNullCondition() ); - var result = condition.Evaluate(new ExpressionContext(new Json.Data.DataProvider()), 456); + var result = condition.Evaluate(new ExpressionContext(new Json.Data.VariableProvider()), 456); Assert.IsTrue(result); } @@ -209,7 +209,7 @@ public void test_not_eq_builds_equals_condition_with_negate_result_true() { var condition = q.Conditions.not_eq(q.val(123)); Assert.IsInstanceOfType(condition); - var result = condition.Evaluate(new ExpressionContext(new Json.Data.DataProvider()), 456); + var result = condition.Evaluate(new ExpressionContext(new Json.Data.VariableProvider()), 456); Assert.IsTrue(result); } @@ -218,7 +218,7 @@ public void test_is_null_builds_is_null_condition() { var condition = q.Conditions.is_null(); Assert.IsInstanceOfType(condition); - var result = condition.Evaluate(new ExpressionContext(new Json.Data.DataProvider()), new JSONValue()); + var result = condition.Evaluate(new ExpressionContext(new Json.Data.VariableProvider()), new JSONValue()); Assert.IsTrue(result); } @@ -227,7 +227,7 @@ public void test_not_null_builds_is_null_condition_with_negate_result_true() { var condition = q.Conditions.not_null(); Assert.IsInstanceOfType(condition); - var result = condition.Evaluate(new ExpressionContext(new Json.Data.DataProvider()), new JSONValue()); + var result = condition.Evaluate(new ExpressionContext(new Json.Data.VariableProvider()), new JSONValue()); Assert.IsFalse(result); } @@ -237,10 +237,10 @@ public void test_is_greater_than_builds_is_greater_than_condition() var condition = q.Conditions.is_greater_than(q.val(37)); Assert.IsInstanceOfType(condition); - var result1 = condition.Evaluate(new ExpressionContext(new Json.Data.DataProvider()), 37); + var result1 = condition.Evaluate(new ExpressionContext(new Json.Data.VariableProvider()), 37); Assert.IsFalse(result1); - var result2 = condition.Evaluate(new ExpressionContext(new Json.Data.DataProvider()), 38); + var result2 = condition.Evaluate(new ExpressionContext(new Json.Data.VariableProvider()), 38); Assert.IsTrue(result2); } @@ -250,10 +250,10 @@ public void test_is_greater_than_or_equal_builds_is_greater_than_or_equal_condit var condition = q.Conditions.is_greater_than_or_equal(q.val(37)); Assert.IsInstanceOfType(condition); - var result1 = condition.Evaluate(new ExpressionContext(new Json.Data.DataProvider()), 37); + var result1 = condition.Evaluate(new ExpressionContext(new Json.Data.VariableProvider()), 37); Assert.IsTrue(result1); - var result2 = condition.Evaluate(new ExpressionContext(new Json.Data.DataProvider()), 38); + var result2 = condition.Evaluate(new ExpressionContext(new Json.Data.VariableProvider()), 38); Assert.IsTrue(result2); } @@ -263,10 +263,10 @@ public void test_is_less_than_builds_is_greater_than_condition() var condition = q.Conditions.is_less_than(q.val(37)); Assert.IsInstanceOfType(condition); - var result1 = condition.Evaluate(new ExpressionContext(new Json.Data.DataProvider()), 37); + var result1 = condition.Evaluate(new ExpressionContext(new Json.Data.VariableProvider()), 37); Assert.IsFalse(result1); - var result2 = condition.Evaluate(new ExpressionContext(new Json.Data.DataProvider()), 36); + var result2 = condition.Evaluate(new ExpressionContext(new Json.Data.VariableProvider()), 36); Assert.IsTrue(result2); } @@ -276,10 +276,10 @@ public void test_is_less_than_or_equal_builds_is_greater_than_or_equal_condition var condition = q.Conditions.is_less_than_or_equal(q.val(37)); Assert.IsInstanceOfType(condition); - var result1 = condition.Evaluate(new ExpressionContext(new Json.Data.DataProvider()), 37); + var result1 = condition.Evaluate(new ExpressionContext(new Json.Data.VariableProvider()), 37); Assert.IsTrue(result1); - var result2 = condition.Evaluate(new ExpressionContext(new Json.Data.DataProvider()), 36); + var result2 = condition.Evaluate(new ExpressionContext(new Json.Data.VariableProvider()), 36); Assert.IsTrue(result2); } diff --git a/Queuebal.UnitTests.Expressions/TestCoalesceExpression.cs b/Queuebal.UnitTests.Expressions/TestCoalesceExpression.cs index 48a08c7..bac8ea3 100644 --- a/Queuebal.UnitTests.Expressions/TestCoalesceExpression.cs +++ b/Queuebal.UnitTests.Expressions/TestCoalesceExpression.cs @@ -9,7 +9,7 @@ public class TestCoalesceExpression { public TestCoalesceExpression() { - Context = new ExpressionContext(new DataProvider()); + Context = new ExpressionContext(new VariableProvider()); } /// diff --git a/Queuebal.UnitTests.Expressions/TestCountExpression.cs b/Queuebal.UnitTests.Expressions/TestCountExpression.cs index e7ef4fc..afe6c2b 100644 --- a/Queuebal.UnitTests.Expressions/TestCountExpression.cs +++ b/Queuebal.UnitTests.Expressions/TestCountExpression.cs @@ -9,7 +9,7 @@ public class TestCountExpression { public TestCountExpression() { - Context = new ExpressionContext(new DataProvider()); + Context = new ExpressionContext(new VariableProvider()); } /// diff --git a/Queuebal.UnitTests.Expressions/TestDataSelectorExpression.cs b/Queuebal.UnitTests.Expressions/TestDataSelectorExpression.cs index 7301c55..a819105 100644 --- a/Queuebal.UnitTests.Expressions/TestDataSelectorExpression.cs +++ b/Queuebal.UnitTests.Expressions/TestDataSelectorExpression.cs @@ -9,7 +9,7 @@ public class TestDataSelectorExpression { public TestDataSelectorExpression() { - Context = new ExpressionContext(new DataProvider()); + Context = new ExpressionContext(new VariableProvider()); } /// diff --git a/Queuebal.UnitTests.Expressions/TestDeclareAndAssignExpression.cs b/Queuebal.UnitTests.Expressions/TestDeclareAndAssignExpression.cs index eae87bb..e6c4fa9 100644 --- a/Queuebal.UnitTests.Expressions/TestDeclareAndAssignExpression.cs +++ b/Queuebal.UnitTests.Expressions/TestDeclareAndAssignExpression.cs @@ -12,8 +12,8 @@ public class TestDeclareAndAssignExpression public void test_evaluate_when_variable_already_exists_throws() { // Arrange - var context = new ExpressionContext(new DataProvider()); - context.DataProvider.AddValue("existingVar", new JSONValue(42)); + var context = new ExpressionContext(new VariableProvider()); + context.VariableProvider.AddValue("existingVar", new JSONValue(42)); var expression = new DeclareAndAssignExpression { @@ -29,7 +29,7 @@ public void test_evaluate_when_variable_already_exists_throws() public void test_evaluate_when_variable_does_not_exist_creates_and_assigns_value() { // Arrange - var context = new ExpressionContext(new DataProvider()); + var context = new ExpressionContext(new VariableProvider()); var expression = new DeclareAndAssignExpression { VariableName = "newVar", @@ -39,6 +39,6 @@ public void test_evaluate_when_variable_does_not_exist_creates_and_assigns_value var result = expression.Evaluate(context, new JSONValue()); // Assert Assert.AreEqual(new JSONValue(100), result); - Assert.AreEqual(new JSONValue(100), context.DataProvider.GetValue("newVar")); + Assert.AreEqual(new JSONValue(100), context.VariableProvider.GetValue("newVar")); } } \ No newline at end of file diff --git a/Queuebal.UnitTests.Expressions/TestDictExpression.cs b/Queuebal.UnitTests.Expressions/TestDictExpression.cs index 6964b12..5b2b8c5 100644 --- a/Queuebal.UnitTests.Expressions/TestDictExpression.cs +++ b/Queuebal.UnitTests.Expressions/TestDictExpression.cs @@ -20,10 +20,10 @@ public void test_evaluate_when_key_is_not_string_throws_exception() } }; - var dataProvider = new Json.Data.DataProvider(); - dataProvider.AddValue("replace", new JSONValue(123)); // Non-string value for key + var variableProvider = new Json.Data.VariableProvider(); + variableProvider.AddValue("replace", new JSONValue(123)); // Non-string value for key - var context = new ExpressionContext(dataProvider); + var context = new ExpressionContext(variableProvider); var inputValue = new JSONValue("not used"); // Act & Assert @@ -42,7 +42,7 @@ public void test_evaluate_when_valid_dict() } }; - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); var inputValue = new JSONValue("not used"); // Act diff --git a/Queuebal.UnitTests.Expressions/TestDynamicDictExpression.cs b/Queuebal.UnitTests.Expressions/TestDynamicDictExpression.cs index 974a07c..bcec6d5 100644 --- a/Queuebal.UnitTests.Expressions/TestDynamicDictExpression.cs +++ b/Queuebal.UnitTests.Expressions/TestDynamicDictExpression.cs @@ -23,7 +23,7 @@ public void test_evaluate_when_key_is_not_string_throws_exception() } }; - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); var inputValue = new List { new JSONValue("input") }; Assert.ThrowsException(() => expression.Evaluate(context, inputValue)); } @@ -43,7 +43,7 @@ public void test_evaluate_when_input_is_not_list_throws_exception() } }; - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); var inputValue = new JSONValue("input"); Assert.ThrowsException(() => expression.Evaluate(context, inputValue)); } @@ -83,7 +83,7 @@ public void test_evaluate_when_entry_condition_is_false_excludes_entry() } }; - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); var inputValue = new List { new JSONValue("input") }; var result = expression.Evaluate(context, inputValue); @@ -120,7 +120,7 @@ public void test_evaluate_when_entry_condition_is_true_includes_entry() } } }; - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); var inputValue = new List { new JSONValue("input") }; var result = expression.Evaluate(context, inputValue); Assert.IsTrue(result.IsDict); @@ -151,7 +151,7 @@ public void test_evaluate_when_no_condition_is_present_includes_all_entries() } }; - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); var inputValue = new List { new JSONValue("input") }; var result = expression.Evaluate(context, inputValue); @@ -185,7 +185,7 @@ public void test_evaluate_when_entry_unpack_adds_items_to_output() } }; - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); var inputValue = new List { new JSONValue("input") }; // Act @@ -224,7 +224,7 @@ public void test_evaluate_when_entry_unpack_and_entry_does_not_create_dict_throw } }; - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); var inputValue = new List { new JSONValue("input") }; // Act & Assert @@ -264,7 +264,7 @@ public void test_evaluate_when_entry_unpack_has_condition_excludes_filtered_item } }; - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); var inputValue = new List { new JSONValue("input") }; // Act diff --git a/Queuebal.UnitTests.Expressions/TestExpression.cs b/Queuebal.UnitTests.Expressions/TestExpression.cs index 58a2c23..00657bf 100644 --- a/Queuebal.UnitTests.Expressions/TestExpression.cs +++ b/Queuebal.UnitTests.Expressions/TestExpression.cs @@ -49,7 +49,7 @@ public void test_evaluate_invalid_expression_returns_input_value() } """; var inputValue = new JSONValue(System.Text.Json.JsonDocument.Parse(inputJson).RootElement); - var context = new ExpressionContext(new DataProvider()); + var context = new ExpressionContext(new VariableProvider()); // Act var result = expression.Evaluate(context, inputValue); diff --git a/Queuebal.UnitTests.Expressions/TestFilterExpression.cs b/Queuebal.UnitTests.Expressions/TestFilterExpression.cs index a3b66cc..756a589 100644 --- a/Queuebal.UnitTests.Expressions/TestFilterExpression.cs +++ b/Queuebal.UnitTests.Expressions/TestFilterExpression.cs @@ -27,7 +27,7 @@ public void test_evaluate_when_input_is_not_list_or_dict_throws_exception() } }; - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); var inputValue = new JSONValue("not a list"); Assert.ThrowsException(() => expression.Evaluate(context, inputValue)); @@ -52,7 +52,7 @@ public void test_evaluate_when_condition_is_true_includes_item_in_results() } }; - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); var inputValue = new List { new JSONValue("test"), new JSONValue("not included") }; var result = expression.Evaluate(context, inputValue); @@ -84,7 +84,7 @@ public void test_evaluate_when_input_value_is_dict() }; var expression = new FilterExpression { Condition = condition }; - var result = expression.Evaluate(new ExpressionContext(new Json.Data.DataProvider()), inputValue); + var result = expression.Evaluate(new ExpressionContext(new Json.Data.VariableProvider()), inputValue); Assert.IsNotNull(result); var expected = new Dictionary diff --git a/Queuebal.UnitTests.Expressions/TestIfElseExpression.cs b/Queuebal.UnitTests.Expressions/TestIfElseExpression.cs index 6882d55..72d05d1 100644 --- a/Queuebal.UnitTests.Expressions/TestIfElseExpression.cs +++ b/Queuebal.UnitTests.Expressions/TestIfElseExpression.cs @@ -43,7 +43,7 @@ public void test_evaluate_when_condition_is_true_returns_then_value() }; // Act - var result = expression.Evaluate(new ExpressionContext(new Json.Data.DataProvider()), new JSONValue()); + var result = expression.Evaluate(new ExpressionContext(new Json.Data.VariableProvider()), new JSONValue()); // Assert Assert.AreEqual("Condition C - True", result.StringValue); @@ -70,7 +70,7 @@ public void test_evaluate_when_no_conditions_match_and_else_value_is_provided_re }; // Act - var result = expression.Evaluate(new ExpressionContext(new Json.Data.DataProvider()), new JSONValue()); + var result = expression.Evaluate(new ExpressionContext(new Json.Data.VariableProvider()), new JSONValue()); // Assert Assert.AreEqual("Else Value", result.StringValue); @@ -97,7 +97,7 @@ public void test_evaluate_when_no_conditions_match_and_else_value_is_not_provide }; // Act - var result = expression.Evaluate(new ExpressionContext(new Json.Data.DataProvider()), new JSONValue()); + var result = expression.Evaluate(new ExpressionContext(new Json.Data.VariableProvider()), new JSONValue()); // Assert Assert.IsTrue(result.IsNull); diff --git a/Queuebal.UnitTests.Expressions/TestJoinExpression.cs b/Queuebal.UnitTests.Expressions/TestJoinExpression.cs index 0b5fe28..d4125b0 100644 --- a/Queuebal.UnitTests.Expressions/TestJoinExpression.cs +++ b/Queuebal.UnitTests.Expressions/TestJoinExpression.cs @@ -66,7 +66,7 @@ public void test_evaluate_when_lvalues_is_not_list() }; // Act & Assert - Assert.ThrowsExactly(() => expression.Evaluate(new ExpressionContext(new Json.Data.DataProvider()), new JSONValue())); + Assert.ThrowsExactly(() => expression.Evaluate(new ExpressionContext(new Json.Data.VariableProvider()), new JSONValue())); } [TestMethod] @@ -84,7 +84,7 @@ public void test_evaluate_when_rvalues_is_not_list() }; // Act & Assert - Assert.ThrowsExactly(() => expression.Evaluate(new ExpressionContext(new Json.Data.DataProvider()), new JSONValue())); + Assert.ThrowsExactly(() => expression.Evaluate(new ExpressionContext(new Json.Data.VariableProvider()), new JSONValue())); } [TestMethod] @@ -102,7 +102,7 @@ public void test_evaluate_when_lrecord_is_not_dict() }; // Act & Assert - Assert.ThrowsExactly(() => expression.Evaluate(new ExpressionContext(new Json.Data.DataProvider()), new JSONValue())); + Assert.ThrowsExactly(() => expression.Evaluate(new ExpressionContext(new Json.Data.VariableProvider()), new JSONValue())); } [TestMethod] @@ -120,7 +120,7 @@ public void test_evaluate_when_rrecord_is_not_dict() }; // Act & Assert - Assert.ThrowsExactly(() => expression.Evaluate(new ExpressionContext(new Json.Data.DataProvider()), new JSONValue())); + Assert.ThrowsExactly(() => expression.Evaluate(new ExpressionContext(new Json.Data.VariableProvider()), new JSONValue())); } [TestMethod] @@ -138,7 +138,7 @@ public void test_evaluate_when_lkey_is_list_or_dict() }; // Act & Assert - Assert.ThrowsExactly(() => expression.Evaluate(new ExpressionContext(new Json.Data.DataProvider()), new JSONValue())); + Assert.ThrowsExactly(() => expression.Evaluate(new ExpressionContext(new Json.Data.VariableProvider()), new JSONValue())); } [TestMethod] @@ -156,7 +156,7 @@ public void test_evaluate_when_rkey_is_list_or_dict() }; // Act & Assert - Assert.ThrowsExactly(() => expression.Evaluate(new ExpressionContext(new Json.Data.DataProvider()), new JSONValue())); + Assert.ThrowsExactly(() => expression.Evaluate(new ExpressionContext(new Json.Data.VariableProvider()), new JSONValue())); } [TestMethod] @@ -181,7 +181,7 @@ public void test_evaluate_when_joining_two_lists_returns_joined_list() { new JoinField { FieldName = "email", Alias = "emailAddress" } } - }.Evaluate(new ExpressionContext(new Json.Data.DataProvider()), new JSONValue("not used")); + }.Evaluate(new ExpressionContext(new Json.Data.VariableProvider()), new JSONValue("not used")); Assert.IsNotNull(result); var expected = new List @@ -225,7 +225,7 @@ public void test_evaluate_when_field_list_is_star() { new JoinField { FieldName = "*" } } - }.Evaluate(new ExpressionContext(new Json.Data.DataProvider()), new JSONValue("not used")); + }.Evaluate(new ExpressionContext(new Json.Data.VariableProvider()), new JSONValue("not used")); Assert.IsNotNull(result); var expected = new List @@ -272,7 +272,7 @@ public void test_evaluate_when_field_not_found_uses_null() new JoinField { FieldName = "userIdentifier" }, new JoinField { FieldName = "email", Alias = "emailAddress" } } - }.Evaluate(new ExpressionContext(new Json.Data.DataProvider()), new JSONValue("not used")); + }.Evaluate(new ExpressionContext(new Json.Data.VariableProvider()), new JSONValue("not used")); Assert.IsNotNull(result); var expected = new List diff --git a/Queuebal.UnitTests.Expressions/TestListExpression.cs b/Queuebal.UnitTests.Expressions/TestListExpression.cs index 9ec346c..3fd46e1 100644 --- a/Queuebal.UnitTests.Expressions/TestListExpression.cs +++ b/Queuebal.UnitTests.Expressions/TestListExpression.cs @@ -17,7 +17,7 @@ public void test_evaluate_when_list_is_empty_returns_empty_list() }; // Act - var result = expression.Evaluate(new ExpressionContext(new Json.Data.DataProvider()), new JSONValue("not used")); + var result = expression.Evaluate(new ExpressionContext(new Json.Data.VariableProvider()), new JSONValue("not used")); // Assert Assert.IsTrue(result.IsList); @@ -38,7 +38,7 @@ public void test_evaluate_when_list_contains_values_returns_list() }; // Act - var result = expression.Evaluate(new ExpressionContext(new Json.Data.DataProvider()), new JSONValue("not used")); + var result = expression.Evaluate(new ExpressionContext(new Json.Data.VariableProvider()), new JSONValue("not used")); // Assert Assert.IsTrue(result.IsList); diff --git a/Queuebal.UnitTests.Expressions/TestMapExpression.cs b/Queuebal.UnitTests.Expressions/TestMapExpression.cs index 6981c06..8aa6b06 100644 --- a/Queuebal.UnitTests.Expressions/TestMapExpression.cs +++ b/Queuebal.UnitTests.Expressions/TestMapExpression.cs @@ -15,7 +15,7 @@ public void test_evaluate_when_input_is_not_list_throws_exception() Map = new ValueExpression { Value = new JSONValue("test") } }; - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); var inputValue = new JSONValue("not a list"); Assert.ThrowsException(() => expression.Evaluate(context, inputValue)); @@ -29,7 +29,7 @@ public void test_evaluate_when_input_is_list_returns_mapped_values() Map = new ValueExpression { Value = new JSONValue("mapped") } }; - var context = new ExpressionContext(new Json.Data.DataProvider()); + var context = new ExpressionContext(new Json.Data.VariableProvider()); var inputValue = new List { new JSONValue("item1"), new JSONValue("item2") }; var result = expression.Evaluate(context, inputValue); diff --git a/Queuebal.UnitTests.Expressions/TestMaxExpression.cs b/Queuebal.UnitTests.Expressions/TestMaxExpression.cs index cf8b18a..30eb1e9 100644 --- a/Queuebal.UnitTests.Expressions/TestMaxExpression.cs +++ b/Queuebal.UnitTests.Expressions/TestMaxExpression.cs @@ -8,7 +8,7 @@ public class TestMaxExpression { public TestMaxExpression() { - Context = new ExpressionContext(new Json.Data.DataProvider()); + Context = new ExpressionContext(new Json.Data.VariableProvider()); } /// diff --git a/Queuebal.UnitTests.Expressions/TestMergeExpression.cs b/Queuebal.UnitTests.Expressions/TestMergeExpression.cs index d0b3179..99c713a 100644 --- a/Queuebal.UnitTests.Expressions/TestMergeExpression.cs +++ b/Queuebal.UnitTests.Expressions/TestMergeExpression.cs @@ -9,7 +9,7 @@ public class TestMergeExpression { public TestMergeExpression() { - Context = new ExpressionContext(new Json.Data.DataProvider()); + Context = new ExpressionContext(new Json.Data.VariableProvider()); SourceValue = new JSONValue("not used"); } diff --git a/Queuebal.UnitTests.Expressions/TestMinExpression.cs b/Queuebal.UnitTests.Expressions/TestMinExpression.cs index ba559a4..796d713 100644 --- a/Queuebal.UnitTests.Expressions/TestMinExpression.cs +++ b/Queuebal.UnitTests.Expressions/TestMinExpression.cs @@ -8,7 +8,7 @@ public class TestMinExpression { public TestMinExpression() { - Context = new ExpressionContext(new Json.Data.DataProvider()); + Context = new ExpressionContext(new Json.Data.VariableProvider()); } /// diff --git a/Queuebal.UnitTests.Expressions/TestProjectionExpression.cs b/Queuebal.UnitTests.Expressions/TestProjectionExpression.cs index 20a62e3..299362f 100644 --- a/Queuebal.UnitTests.Expressions/TestProjectionExpression.cs +++ b/Queuebal.UnitTests.Expressions/TestProjectionExpression.cs @@ -17,7 +17,7 @@ public void test_evaluate_when_include_data_from_parent_object() var filter = BuildFilterCondition(); expression.ItemFilter = filter; - var context = new ExpressionContext(new DataProvider()); + var context = new ExpressionContext(new VariableProvider()); var result = expression.Evaluate(context, inputValue); Assert.IsTrue(result.IsList); @@ -34,7 +34,7 @@ public void test_evaluate_when_input_value_is_not_list_converts_to_list() var expression = BuildNonListProjectionExpression(); var inputValue = BuildInputValue(); - var context = new ExpressionContext(new DataProvider()); + var context = new ExpressionContext(new VariableProvider()); var result = expression.Evaluate(context, inputValue); Assert.IsTrue(result.IsList); @@ -53,7 +53,7 @@ public void test_evaluate_when_items_is_null_returns_null() var expression = BuildMissingProjectionExpression(); var inputValue = BuildInputValue(); - var context = new ExpressionContext(new DataProvider()); + var context = new ExpressionContext(new VariableProvider()); var result = expression.Evaluate(context, inputValue); Assert.IsTrue(result.IsNull); diff --git a/Queuebal.UnitTests.Json.Data/TestDataProvider.cs b/Queuebal.UnitTests.Json.Data/TestDataProvider.cs index b9e5097..c09116e 100644 --- a/Queuebal.UnitTests.Json.Data/TestDataProvider.cs +++ b/Queuebal.UnitTests.Json.Data/TestDataProvider.cs @@ -5,14 +5,14 @@ namespace Queuebal.UnitTests.Json.Data; [TestClass] -public class TestDataProvider +public class TestVariableProvider { [TestMethod] public void test_when_add_root_value_value_is_in_root_scope() { - var dataProvider = new DataProvider(); - dataProvider.AddRootValue("test_key", new JSONValue("Test Value")); - var value = dataProvider.GetValue("test_key"); + var variableProvider = new VariableProvider(); + variableProvider.AddRootValue("test_key", new JSONValue("Test Value")); + var value = variableProvider.GetValue("test_key"); Assert.IsNotNull(value); Assert.AreEqual(value.Value, "Test Value"); } @@ -20,13 +20,13 @@ public void test_when_add_root_value_value_is_in_root_scope() [TestMethod] public void test_when_pop_scope_and_no_scopes_does_not_pop_root_scope() { - var dataProvider = new DataProvider(); - dataProvider.AddRootValue("test_key", new JSONValue("Test Value")); - dataProvider.PopScope(); + var variableProvider = new VariableProvider(); + variableProvider.AddRootValue("test_key", new JSONValue("Test Value")); + variableProvider.PopScope(); // get the value from the root scope, which should still exist even // though we called "PopScope" when no other scopes were registered. - var value = dataProvider.GetValue("test_key"); + var value = variableProvider.GetValue("test_key"); Assert.IsNotNull(value); Assert.AreEqual(value.Value, "Test Value"); } @@ -34,8 +34,8 @@ public void test_when_pop_scope_and_no_scopes_does_not_pop_root_scope() [TestMethod] public void test_when_value_in_multiple_scopes_gets_top_value() { - var dataProvider = new DataProvider(); - dataProvider.AddRootValue("test_key", new JSONValue("Test Value - Root")); + var variableProvider = new VariableProvider(); + variableProvider.AddRootValue("test_key", new JSONValue("Test Value - Root")); var scope1Values = new Dictionary() { @@ -47,25 +47,25 @@ public void test_when_value_in_multiple_scopes_gets_top_value() { "test_key", new JSONValue("Test Value - scope2") } }; - using (var scopeAccess1 = dataProvider.WithScope("scope1", scope1Values)) + using (var scopeAccess1 = variableProvider.WithScope("scope1", scope1Values)) { - using (var scopeAccess2 = dataProvider.WithScope("scope2", scope2Values)) + using (var scopeAccess2 = variableProvider.WithScope("scope2", scope2Values)) { - Assert.AreEqual(dataProvider.GetValue("test_key")?.Value, "Test Value - scope2"); + Assert.AreEqual(variableProvider.GetValue("test_key")?.Value, "Test Value - scope2"); } // since scope 2 was popped, we should get the scope 1 value - Assert.AreEqual(dataProvider.GetValue("test_key")?.Value, "Test Value - scope1"); + Assert.AreEqual(variableProvider.GetValue("test_key")?.Value, "Test Value - scope1"); } - Assert.AreEqual(dataProvider.GetValue("test_key")?.Value, "Test Value - Root"); + Assert.AreEqual(variableProvider.GetValue("test_key")?.Value, "Test Value - Root"); } [TestMethod] public void test_when_searching_by_scope_name_finds_correct_value() { - var dataProvider = new DataProvider(); - dataProvider.AddRootValue("test_key", new JSONValue("Test Value - Root")); + var variableProvider = new VariableProvider(); + variableProvider.AddRootValue("test_key", new JSONValue("Test Value - Root")); var scope1Values = new Dictionary() { @@ -77,17 +77,17 @@ public void test_when_searching_by_scope_name_finds_correct_value() { "test_key", new JSONValue("Test Value - scope2") } }; - dataProvider.PushScope(new DataProviderScope("scope1", scope1Values)); - dataProvider.PushScope(new DataProviderScope("scope2", scope2Values)); + variableProvider.PushScope(new VariableProviderScope("scope1", scope1Values)); + variableProvider.PushScope(new VariableProviderScope("scope2", scope2Values)); - Assert.AreEqual(dataProvider.GetValue("test_key", "scope1")?.Value, "Test Value - scope1"); - Assert.AreEqual(dataProvider.GetValue("test_key", "scope2")?.Value, "Test Value - scope2"); + Assert.AreEqual(variableProvider.GetValue("test_key", "scope1")?.Value, "Test Value - scope1"); + Assert.AreEqual(variableProvider.GetValue("test_key", "scope2")?.Value, "Test Value - scope2"); } [TestMethod] public void test_when_scope_added_to_stack_without_using_accessor_pops_correct_scope() { - var dataProvider = new DataProvider(); + var variableProvider = new VariableProvider(); var scope1Values = new Dictionary() { @@ -99,33 +99,33 @@ public void test_when_scope_added_to_stack_without_using_accessor_pops_correct_s { "test_key", new JSONValue("Test Value - scope2") } }; - using (var scopeAccess1 = dataProvider.WithScope("scope1", scope1Values)) + using (var scopeAccess1 = variableProvider.WithScope("scope1", scope1Values)) { - dataProvider.PushScope(new DataProviderScope("scope2", scope2Values)); + variableProvider.PushScope(new VariableProviderScope("scope2", scope2Values)); } // we popped scope1, but scope2 should still exist, even though it was added // after scope1. - Assert.AreEqual(dataProvider.GetValue("test_key")?.Value, "Test Value - scope2"); + Assert.AreEqual(variableProvider.GetValue("test_key")?.Value, "Test Value - scope2"); } [TestMethod] public void test_when_add_to_parent_adds_to_correct_scope() { - var dataProvider = new DataProvider(); + var variableProvider = new VariableProvider(); var scope1Values = new Dictionary() { { "test_key", new JSONValue("Test Value - scope1") } }; - using (var scopeAccess1 = dataProvider.WithScope("scope1", scope1Values)) + using (var scopeAccess1 = variableProvider.WithScope("scope1", scope1Values)) { - dataProvider.AddParentValue("test_key", "Test Value - rootScope"); - var currentScopeValue = dataProvider.GetValue("test_key"); + variableProvider.AddParentValue("test_key", "Test Value - rootScope"); + var currentScopeValue = variableProvider.GetValue("test_key"); Assert.AreEqual("Test Value - scope1", currentScopeValue); - var rootScopeValue = dataProvider.GetValue("test_key", "__root"); + var rootScopeValue = variableProvider.GetValue("test_key", "__root"); Assert.AreEqual("Test Value - rootScope", rootScopeValue); } } @@ -133,34 +133,34 @@ public void test_when_add_to_parent_adds_to_correct_scope() [TestMethod] public void test_when_add_to_parent_and_there_is_no_parent_adds_to_root_scope() { - var dataProvider = new DataProvider(); - dataProvider.AddParentValue("test_key", "test_value"); + var variableProvider = new VariableProvider(); + variableProvider.AddParentValue("test_key", "test_value"); - var value = dataProvider.GetValue("test_key", scopeName: "__root"); + var value = variableProvider.GetValue("test_key", scopeName: "__root"); Assert.AreEqual("test_value", value); } [TestMethod] public void test_add_values_from_dict_adds_values_to_current_scope() { - var dataProvider = new DataProvider(); + var variableProvider = new VariableProvider(); var values = new Dictionary { { "key1", new JSONValue("value1") }, { "key2", new JSONValue("value2") } }; - dataProvider.AddValues(values); + variableProvider.AddValues(values); - Assert.AreEqual("value1", dataProvider.GetValue("key1")?.Value); - Assert.AreEqual("value2", dataProvider.GetValue("key2")?.Value); + Assert.AreEqual("value1", variableProvider.GetValue("key1")?.Value); + Assert.AreEqual("value2", variableProvider.GetValue("key2")?.Value); } [TestMethod] public void test_get_value_from_root_scope_returns_correct_value() { - var dataProvider = new DataProvider(); - dataProvider.AddRootValue("test_key", new JSONValue("Test Value - Root")); + var variableProvider = new VariableProvider(); + variableProvider.AddRootValue("test_key", new JSONValue("Test Value - Root")); // add a duplicate key in a new scope to make sure we pull // from the root scope @@ -169,10 +169,10 @@ public void test_get_value_from_root_scope_returns_correct_value() { "test_key", new JSONValue("Test Value - scope1") } }; - using (dataProvider.WithScope("scope1", scope1Values)) + using (variableProvider.WithScope("scope1", scope1Values)) { // Get value from root scope while in a child scope - var value = dataProvider.GetRootValue("test_key"); + var value = variableProvider.GetRootValue("test_key"); Assert.IsNotNull(value); Assert.AreEqual("Test Value - Root", value.Value); } @@ -181,28 +181,28 @@ public void test_get_value_from_root_scope_returns_correct_value() [TestMethod] public void test_get_value_when_key_not_found_returns_null() { - var dataProvider = new DataProvider(); - var value = dataProvider.GetValue("non_existent_key"); + var variableProvider = new VariableProvider(); + var value = variableProvider.GetValue("non_existent_key"); Assert.IsNull(value); } [TestMethod] public void test_remove_scope_when_scope_from_different_data_provider_throws() { - var dataProvider1 = new DataProvider(); - var dataProvider2 = new DataProvider(); + var variableProvider1 = new VariableProvider(); + var variableProvider2 = new VariableProvider(); var scopeValues = new Dictionary { { "test_key", new JSONValue("Test Value") } }; - using (var scopeAccessor = dataProvider1.WithScope("scope1", scopeValues)) + using (var scopeAccessor = variableProvider1.WithScope("scope1", scopeValues)) { // Attempt to remove a scope from a different data provider Assert.ThrowsException(() => { - dataProvider2.RemoveScope(scopeAccessor.Scope); + variableProvider2.RemoveScope(scopeAccessor.Scope); }); } } @@ -210,7 +210,7 @@ public void test_remove_scope_when_scope_from_different_data_provider_throws() [TestMethod] public void test_pop_scope_when_multiple_scopes_exist_removes_top_scope() { - var dataProvider = new DataProvider(); + var variableProvider = new VariableProvider(); var scope1Values = new Dictionary() { @@ -222,32 +222,32 @@ public void test_pop_scope_when_multiple_scopes_exist_removes_top_scope() { "test_key", new JSONValue("Test Value - scope2") } }; - dataProvider.AddRootValue("test_key", new JSONValue("Test Value - Root")); - dataProvider.WithScope("scope1", scope1Values); - dataProvider.WithScope("scope2", scope2Values); + variableProvider.AddRootValue("test_key", new JSONValue("Test Value - Root")); + variableProvider.WithScope("scope1", scope1Values); + variableProvider.WithScope("scope2", scope2Values); // At this point, we are in scope2 - Assert.AreEqual(dataProvider.GetValue("test_key")?.Value, "Test Value - scope2"); - dataProvider.PopScope(); + Assert.AreEqual(variableProvider.GetValue("test_key")?.Value, "Test Value - scope2"); + variableProvider.PopScope(); // After popping scope2, we should be back in scope1 - Assert.AreEqual(dataProvider.GetValue("test_key")?.Value, "Test Value - scope1"); - dataProvider.PopScope(); + Assert.AreEqual(variableProvider.GetValue("test_key")?.Value, "Test Value - scope1"); + variableProvider.PopScope(); // After popping scope1, we should be back in the root scope - Assert.AreEqual(dataProvider.GetValue("test_key")?.Value, "Test Value - Root"); - dataProvider.PopScope(); // We should not be able to pop the root scope, so this should not change anything. + Assert.AreEqual(variableProvider.GetValue("test_key")?.Value, "Test Value - Root"); + variableProvider.PopScope(); // We should not be able to pop the root scope, so this should not change anything. - Assert.AreEqual(dataProvider.GetValue("test_key")?.Value, "Test Value - Root"); + Assert.AreEqual(variableProvider.GetValue("test_key")?.Value, "Test Value - Root"); } [TestMethod] public void test_add_value_adds_value_to_current_scope() { - var dataProvider = new DataProvider(); - dataProvider.AddValue("test_key", new JSONValue("Test Value")); + var variableProvider = new VariableProvider(); + variableProvider.AddValue("test_key", new JSONValue("Test Value")); - var value = dataProvider.GetValue("test_key"); + var value = variableProvider.GetValue("test_key"); Assert.IsNotNull(value); Assert.AreEqual("Test Value", value.Value); } @@ -255,13 +255,13 @@ public void test_add_value_adds_value_to_current_scope() [TestMethod] public void test_add_root_values_adds_values_to_root_scope() { - var dataProvider = new DataProvider(); + var variableProvider = new VariableProvider(); var scope2Values = new Dictionary { { "key3", new JSONValue("value3") } }; - using (dataProvider.WithScope("scope2", scope2Values)) + using (variableProvider.WithScope("scope2", scope2Values)) { var values = new Dictionary { @@ -270,35 +270,35 @@ public void test_add_root_values_adds_values_to_root_scope() }; // Add values to root scope while in a child scope - dataProvider.AddRootValues(values); + variableProvider.AddRootValues(values); - Assert.AreEqual("value1", dataProvider.GetValue("key1", "__root")?.Value); - Assert.AreEqual("value2", dataProvider.GetValue("key2", "__root")?.Value); + Assert.AreEqual("value1", variableProvider.GetValue("key1", "__root")?.Value); + Assert.AreEqual("value2", variableProvider.GetValue("key2", "__root")?.Value); } } [TestMethod] public void test_remove_root_scope_throws_invalid_operation_exception() { - var dataProvider = new DataProvider(); + var variableProvider = new VariableProvider(); - var rootScopeField = typeof(DataProvider).GetField("_rootScope", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); - var rootScope = (DataProviderScope?)rootScopeField?.GetValue(dataProvider); + var rootScopeField = typeof(VariableProvider).GetField("_rootScope", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); + var rootScope = (VariableProviderScope?)rootScopeField?.GetValue(variableProvider); - var scopeAccessor = new DataProviderScopeAccess(dataProvider, rootScope!); + var scopeAccessor = new VariableProviderScopeAccess(variableProvider, rootScope!); Assert.ThrowsExactly(() => scopeAccessor.Dispose()); } [TestMethod] public void test_set_value_when_key_exists_updates_value() { - var dataProvider = new DataProvider(); - dataProvider.AddRootValue("test_key", new JSONValue("Initial Value")); + var variableProvider = new VariableProvider(); + variableProvider.AddRootValue("test_key", new JSONValue("Initial Value")); // Set a new value for the existing key - dataProvider.SetValue("test_key", new JSONValue("Updated Value")); + variableProvider.SetValue("test_key", new JSONValue("Updated Value")); - var value = dataProvider.GetValue("test_key"); + var value = variableProvider.GetValue("test_key"); Assert.IsNotNull(value); Assert.AreEqual("Updated Value", value.Value); } @@ -306,13 +306,13 @@ public void test_set_value_when_key_exists_updates_value() [TestMethod] public void test_set_value_when_key_does_not_exist_throws_exception() { - var dataProvider = new DataProvider(); + var variableProvider = new VariableProvider(); // Act & Assert - Assert.ThrowsException(() => dataProvider.SetValue("non_existent_key", new JSONValue("Some Value"))); + Assert.ThrowsException(() => variableProvider.SetValue("non_existent_key", new JSONValue("Some Value"))); // Ensure that the key was not added - var value = dataProvider.GetValue("non_existent_key"); + var value = variableProvider.GetValue("non_existent_key"); Assert.IsNull(value); } } diff --git a/Queuebal.UnitTests.Json.Data/TestTokenizer.cs b/Queuebal.UnitTests.Json.Data/TestTokenizer.cs index 4917631..23a9d06 100644 --- a/Queuebal.UnitTests.Json.Data/TestTokenizer.cs +++ b/Queuebal.UnitTests.Json.Data/TestTokenizer.cs @@ -11,25 +11,25 @@ public class TestTokenizer public void test_get_tokens_when_unmatched_opening_bracket_throws_exception() { var text = "this is a test ${ with an extra ${ opening bracket"; - var dataProvider = new DataProvider(); - Assert.ThrowsException(() => Tokenizer.GetTokens(text, dataProvider).ToList()); + var variableProvider = new VariableProvider(); + Assert.ThrowsException(() => Tokenizer.GetTokens(text, variableProvider).ToList()); } [TestMethod] public void test_get_tokens_when_unmatched_closing_bracket_throws_exception() { var text = "this is a ${test} with} an extra closing bracket"; - var dataProvider = new DataProvider(); - dataProvider.AddValue("test", new JSONValue("value")); - Assert.ThrowsException(() => Tokenizer.GetTokens(text, dataProvider).ToList()); + var variableProvider = new VariableProvider(); + variableProvider.AddValue("test", new JSONValue("value")); + Assert.ThrowsException(() => Tokenizer.GetTokens(text, variableProvider).ToList()); } [TestMethod] public void test_get_tokens_when_opening_bracket_is_escaped_is_not_replaced() { var text = "this is a test \\${ with an escaped opening bracket"; - var dataProvider = new DataProvider(); - var tokens = Tokenizer.GetTokens(text, dataProvider).ToList(); + var variableProvider = new VariableProvider(); + var tokens = Tokenizer.GetTokens(text, variableProvider).ToList(); Assert.AreEqual(1, tokens.Count); Assert.AreEqual("this is a test ${ with an escaped opening bracket", tokens[0].Text); @@ -40,18 +40,18 @@ public void test_get_tokens_when_opening_bracket_is_escaped_is_not_replaced() public void test_get_tokens_when_text_contains_unclosed_placeholder_throws_exception() { var text = "this is a test ${placeholder with no closing bracket"; - var dataProvider = new DataProvider(); - Assert.ThrowsException(() => Tokenizer.GetTokens(text, dataProvider).ToList()); + var variableProvider = new VariableProvider(); + Assert.ThrowsException(() => Tokenizer.GetTokens(text, variableProvider).ToList()); } [TestMethod] public void test_get_tokens_when_text_contains_escaped_extra_closing_paren_is_ignored() { var text = "this is a test ${placeholder} with}} an escaped closing bracket"; - var dataProvider = new DataProvider(); - dataProvider.AddValue("placeholder", new JSONValue("value")); + var variableProvider = new VariableProvider(); + variableProvider.AddValue("placeholder", new JSONValue("value")); - var tokens = Tokenizer.GetTokens(text, dataProvider).ToList(); + var tokens = Tokenizer.GetTokens(text, variableProvider).ToList(); Assert.AreEqual(3, tokens.Count); Assert.AreEqual("this is a test ", tokens[0].Text); @@ -69,10 +69,10 @@ public void test_get_tokens_when_text_contains_escaped_extra_closing_paren_is_ig public void test_get_tokens_when_closing_bracket_in_placeholder_is_escaped() { var text = "this is a test ${placeholder}} with} an escaped closing bracket"; - var dataProvider = new DataProvider(); - dataProvider.AddValue("placeholder} with", new JSONValue("value")); + var variableProvider = new VariableProvider(); + variableProvider.AddValue("placeholder} with", new JSONValue("value")); - var tokens = Tokenizer.GetTokens(text, dataProvider).ToList(); + var tokens = Tokenizer.GetTokens(text, variableProvider).ToList(); Assert.AreEqual(3, tokens.Count); Assert.AreEqual("this is a test ", tokens[0].Text); @@ -90,35 +90,35 @@ public void test_get_tokens_when_closing_bracket_in_placeholder_is_escaped() public void test_get_tokens_when_closing_bracket_found_after_closed_placeholder_token() { var text = "this is a ${test}} with an extra closing bracket"; - var dataProvider = new DataProvider(); - dataProvider.AddValue("test", new JSONValue("value")); + var variableProvider = new VariableProvider(); + variableProvider.AddValue("test", new JSONValue("value")); - Assert.ThrowsExactly(() => Tokenizer.GetTokens(text, dataProvider).ToList()); + Assert.ThrowsExactly(() => Tokenizer.GetTokens(text, variableProvider).ToList()); } [TestMethod] public void test_get_tokens_when_replacement_value_is_not_found() { var text = "this is a test ${placeholder} with no replacement value"; - var dataProvider = new DataProvider(); + var variableProvider = new VariableProvider(); - Assert.ThrowsException(() => Tokenizer.GetTokens(text, dataProvider).ToList()); + Assert.ThrowsException(() => Tokenizer.GetTokens(text, variableProvider).ToList()); } [TestMethod] public void test_get_tokens_when_text_contains_tokens_within_brackets() { var text = "this is a test ${placeholder1} with ${placeholder2} tokens"; - var dataProvider = new DataProvider(); - var dataProviderValues = new Dictionary + var variableProvider = new VariableProvider(); + var variableProviderValues = new Dictionary { { "placeholder1", new JSONValue("value1") }, { "placeholder2", new JSONValue("value2") } }; - using (dataProvider.WithScope("testScope", dataProviderValues)) + using (variableProvider.WithScope("testScope", variableProviderValues)) { - var tokens = Tokenizer.GetTokens(text, dataProvider).ToList(); + var tokens = Tokenizer.GetTokens(text, variableProvider).ToList(); Assert.AreEqual(5, tokens.Count); @@ -144,51 +144,51 @@ public void test_get_tokens_when_text_contains_tokens_within_brackets() [TestMethod] public void test_evaluate_when_input_value_is_empty_returns_input() { - var dataProvider = new DataProvider(); - var result = Tokenizer.Evaluate("", dataProvider); + var variableProvider = new VariableProvider(); + var result = Tokenizer.Evaluate("", variableProvider); Assert.AreEqual("", result); } [TestMethod] public void test_evaluate_when_input_is_single_variable_returns_variable_value() { - var dataProvider = new DataProvider(); - dataProvider.AddValue("test", new JSONValue(3.14f)); + var variableProvider = new VariableProvider(); + variableProvider.AddValue("test", new JSONValue(3.14f)); - var result = Tokenizer.Evaluate("${test}", dataProvider); + var result = Tokenizer.Evaluate("${test}", variableProvider); Assert.AreEqual(3.14f, result.FloatValue); } [TestMethod] public void test_evaluate_when_input_does_not_contain_placeholder_returns_input_as_string() { - var dataProvider = new DataProvider(); + var variableProvider = new VariableProvider(); var inputValue = "this is a test string"; - var result = Tokenizer.Evaluate(inputValue, dataProvider); + var result = Tokenizer.Evaluate(inputValue, variableProvider); Assert.AreEqual(inputValue, result.StringValue); } [TestMethod] public void test_evaluate_when_input_contains_multiple_tokens_returns_concatenated_string() { - var dataProvider = new DataProvider(); - dataProvider.AddValue("test1", new JSONValue("Hello")); - dataProvider.AddValue("test2", new JSONValue(123)); - dataProvider.AddValue("test3", new JSONValue("World")); + var variableProvider = new VariableProvider(); + variableProvider.AddValue("test1", new JSONValue("Hello")); + variableProvider.AddValue("test2", new JSONValue(123)); + variableProvider.AddValue("test3", new JSONValue("World")); var inputValue = "${test1} ${test2} ${test3}!"; - var result = Tokenizer.Evaluate(inputValue, dataProvider); + var result = Tokenizer.Evaluate(inputValue, variableProvider); Assert.AreEqual("Hello 123 World!", result.StringValue); } [TestMethod] public void test_evaluate_when_stored_replacement_value_is_null() { - var dataProvider = new DataProvider(); - dataProvider.AddValue("test", new JSONValue()); + var variableProvider = new VariableProvider(); + variableProvider.AddValue("test", new JSONValue()); var inputValue = "${test}"; - var result = Tokenizer.Evaluate(inputValue, dataProvider); + var result = Tokenizer.Evaluate(inputValue, variableProvider); Assert.IsTrue(result.IsNull); } } diff --git a/Queuebal.UnitTests.Serialization/TestExpressionSerialization.cs b/Queuebal.UnitTests.Serialization/TestExpressionSerialization.cs index b2770be..37cbb0c 100644 --- a/Queuebal.UnitTests.Serialization/TestExpressionSerialization.cs +++ b/Queuebal.UnitTests.Serialization/TestExpressionSerialization.cs @@ -52,7 +52,7 @@ public void test_serialize_expression_when_expression_is_condition_expression() Assert.IsNotNull(deserialized); Assert.IsInstanceOfType(deserialized); - var result = deserialized.Evaluate(new ExpressionContext(new Json.Data.DataProvider()), new JSONValue("test")); + var result = deserialized.Evaluate(new ExpressionContext(new Json.Data.VariableProvider()), new JSONValue("test")); Assert.IsTrue(result.BooleanValue); // true because NegateResult is true and inputValue is not null } }