public async Task TestBoolExpressionsActuators() { var config = new MustacheConfigSchema() { Params = new List <Param> { new Param { Name = "MySql", DefaultValue = "true" }, new Param { Name = "MySqlEFCore", DefaultValue = "false" }, new Param { Name = "C", DefaultValue = "false" }, }, }; var dv = new Dictionary <string, string> { { "MySql", "true" }, { "MySqlEFCore", "false" }, }; var calcParam = new CalculatedParam { Name = "MySqlOrMySqlEFCore", Expression = "MySql || MySqlEFCore", ExpressionType = ExpressionTypeEnum.Bool, }; var expression = new BooleanExpression(_logger, calcParam, config); var result = await expression.EvaluateExpressionAsync(dv); Assert.Equal(true.ToString(), result); }
public async Task TestAnyExpression() { var config = new MustacheConfigSchema() { Params = new List <Param> { new Param { Name = "MySql", DefaultValue = "true" }, new Param { Name = "MySqlEFCore", DefaultValue = "false" }, new Param { Name = "C", DefaultValue = "false" }, }, }; var dv = new Dictionary <string, string> { { "MySql", "true" }, }; var calcParam = new CalculatedParam { Name = "AnyEFCore", Expression = "MySql,Postgres,Redis,MongoDB,OAuthConnector", ExpressionType = ExpressionTypeEnum.Any, }; var expression = new AnyExpression(_logger, calcParam, config); var result = await expression.EvaluateExpressionAsync(dv); Assert.Equal("True", result); }
public async Task TestStringExpression() { var config = new MustacheConfigSchema() { Params = new List <Param> { new Param { Name = "MySql", DefaultValue = "true" }, new Param { Name = "MySqlEFCore", DefaultValue = "false" }, new Param { Name = "C", DefaultValue = "false" }, }, }; var dv = new Dictionary <string, string> { { "TargetFrameworkVersion", "netcoreapp2.2" }, }; var calcParam = new CalculatedParam { Name = "AspNetCoreVersion", Expression = "dataView => dataView[\"TargetFrameworkVersion\"]==\"netcoreapp2.2\"? \"2.2.0\": null", ExpressionType = ExpressionTypeEnum.Bool, }; var expression = new StringExpression(_logger, calcParam, config); var result = await expression.EvaluateExpressionAsync(dv); Assert.Equal("2.2.0", result); }
public async Task TestCaseExpression() { var config = new MustacheConfigSchema() { Params = new List <Param> { new Param { Name = "MySql", DefaultValue = "true" }, new Param { Name = "MySqlEFCore", DefaultValue = "false" }, new Param { Name = "C", DefaultValue = "false" }, }, }; var dv = new Dictionary <string, string> { { "TargetFrameworkVersion", "netcoreapp2.2" }, }; var calcParam = new CalculatedParam { Name = "AspNetCoreVersion", Expression = "TargetFrameworkVersion,netcoreapp2.2=2.2.0,netcoreapp2.1=2.1.1,default=False", ExpressionType = ExpressionTypeEnum.Case, }; var expression = new CaseExpression(_logger, calcParam, config); var result = await expression.EvaluateExpressionAsync(dv); Assert.Equal("2.2.0", result); }
public void TestLambdaExpression() { var cdv = new MustacheConfig(); var dv = new Dictionary <string, object> { { "TargetFrameworkVersion", "netcoreapp2.2" }, }; var calcExp = new CalculatedParam { Name = "AspNetCoreVersion", Expression = "dataView => dataView[\"TargetFrameworkVersion\"]==\"netcoreapp2.2\"? \"2.2.0\": null", ExpressionType = ExpressionTypeEnum.Lambda, }; cdv.EvaluateLambdaExpression <string>(calcExp.Name, calcExp.Expression, dv); Assert.Contains(dv, (item) => item.Key == calcExp.Name && (string)item.Value == "2.2.0"); }
public void TestExpressionsActuators() { var cdv = new MustacheConfig(); var dv = new Dictionary <string, object> { { "MySql", true }, { "MySqlEFCore", false }, }; var calcExp = new CalculatedParam { Name = "MySqlOrMySqlEFCore", Expression = "MySql || MySqlEFCore", ExpressionType = ExpressionTypeEnum.Lookup, }; var lambda = cdv.BuildLookupLambda(calcExp, dv); cdv.EvaluateLambdaExpression <bool>(calcExp.Name, lambda, dv); Assert.Contains(dv, (item) => item.Key == calcExp.Name && item.Value is bool itemValue && itemValue); }
public async Task Test_MorethanOneExpression_false() { var config = new MustacheConfigSchema(); var dv = new Dictionary <string, string> { { "IsMoreThanOne", "false" }, { "ConfigServer", "false" }, { "SQLServer", "true" }, { "Redis", "false" }, }; var calcParam = new CalculatedParam { Name = "IsMoreThanOne", Expression = "ConfigServer,SQLServer,Redis", ExpressionType = ExpressionTypeEnum.MoreThanOne, }; var expression = new MoreThanOneExpression(_logger, calcParam, config); var result = await expression.EvaluateExpressionAsync(dv); Assert.Equal("False", result); }
public async Task TestBoolExpressions() { var config = new MustacheConfigSchema() { Params = new List <Param> { new Param { Name = "A", DefaultValue = "true" }, new Param { Name = "B", DefaultValue = "false" }, new Param { Name = "C", DefaultValue = "false" }, }, }; var dv = new Dictionary <string, string> { { "A", "true" }, { "B", "false" }, { "C", "false" }, }; var calcParam = new CalculatedParam { Name = "testExp", Expression = "A || B && !C ", ExpressionType = ExpressionTypeEnum.Bool, }; var expression = new BooleanExpression(_logger, calcParam, config); var result = await expression.EvaluateExpressionAsync(dv); Assert.Equal("True", result); }
public MoreThanOneExpression(ILogger logger, CalculatedParam param, MustacheConfigSchema schema) { _param = param; _logger = logger; _evaluationExpression = BuildEvaluationExpression(schema); }
public StringExpression(ILogger logger, CalculatedParam param, MustacheConfigSchema config) { _param = param; _logger = logger; _evaluationExpression = BuildEvaluationExpression(config); }