Example #1
0
        public void TestInterprete_Fun_SqlEq()
        {
            var log = new BdoLog();

            string value        = null;
            string fluentScript = DbFluent.Eq(
                DbFluent.Field("RegionalDirectorateId"), DbFluent.IfNull(value, DbFluent.Field("RegionalDirectorateId")));
            string expectedScript = "$sqlEq($sqlField('RegionalDirectorateId'), $sqlIfNull($sqlNull(), $sqlField('RegionalDirectorateId')))";

            string xml = "";

            if (log.HasErrorsOrExceptions())
            {
                xml = ". Result was '" + log.ToXml();
            }
            Assert.That(expectedScript.Equals(fluentScript, StringComparison.OrdinalIgnoreCase), "Bad fluent interpretation. Result was '" + xml);


            var scriptVariableSet = new ScriptVariableSet();

            scriptVariableSet.SetValue(VarSetDb.__DbBuilder,
                                       DbQueryFactory.CreateQueryBuilder <DbQueryBuilder_PostgreSql>(GlobalVariables.AppHost));
            string result = GlobalVariables.AppHost.Scope.Interpreter.Evaluate(fluentScript, DataExpressionKind.Script, scriptVariableSet, log: log)?.ToString();

            string expectedResult = @"""RegionalDirectorateId""=COALESCE(NULL, ""RegionalDirectorateId"")";

            if (log.HasErrorsOrExceptions())
            {
                xml = ". Result was '" + log.ToXml();
            }
            Assert.That(result.Trim().Equals(expectedResult.Trim(), StringComparison.OrdinalIgnoreCase), "Bad script interpretation" + xml);
        }
        public static ScriptVariableSet BuildScriptVariableSet(List <Line> lines)
        {
            var scriptVariableSet = new ScriptVariableSet(
                BuildTimes(lines),
                BuildCurrencies(lines),
                BuildIndicators(lines),
                BuildValues(lines)
                );


            // Return
            return(scriptVariableSet);
        }
Example #3
0
        public static ScriptVariableSet GetFake_List()
        {
            var scriptVariableSetResponse = new ScriptVariableSet();

            var now        = DateTime.Now;
            var times      = new [] { now };
            var currencies = new [] { "bitcoin", "ethereum", "master" };
            var indicators = new [] { "price", "hype", "performance" };

            var level31 = new Dictionary <string, decimal>
            {
                { "price", 3200m },
                { "hype", 0.125m }
            };
            var level32 = new Dictionary <string, decimal>
            {
                { "price", 570m },
                { "hype", 6.5m }
            };
            var level33 = new Dictionary <string, decimal>
            {
                { "performance", 70m }
            };
            var level2 = new Dictionary <string, Dictionary <string, decimal> >
            {
                { "bitcoin", level31 },
                { "ethereum", level32 },
                { "master", level33 }
            };
            var level1 = new Dictionary <DateTime, Dictionary <string, Dictionary <string, decimal> > >
            {
                { now, level2 }
            };

            scriptVariableSetResponse.Times      = times;
            scriptVariableSetResponse.Currencies = currencies;
            scriptVariableSetResponse.Indicators = indicators;
            scriptVariableSetResponse.Values     = level1;

            // Return
            return(scriptVariableSetResponse);
        }
Example #4
0
        public void TestInterprete_Fun_SqlEq_Null()
        {
            var log = new BdoLog();

            // Case: value, null

            string value         = null;
            string fluentScript1 = DbFluent.Eq(
                null, DbFluent.IfNull(value, DbFluent.Field("RegionalDirectorateId", DbFluent.Table("Table1", "Schema1"))));

            var scriptVariableSet = new ScriptVariableSet();

            scriptVariableSet.SetValue(VarSetDb.__DbBuilder,
                                       DbQueryFactory.CreateQueryBuilder <DbQueryBuilder_PostgreSql>(GlobalVariables.AppHost));
            string result = GlobalVariables.AppHost.Scope.Interpreter.Evaluate(fluentScript1, DataExpressionKind.Script, scriptVariableSet, log: log)?.ToString();

            string expectedResult = @"COALESCE(NULL, ""Schema1"".""Table1"".""RegionalDirectorateId"") is null";

            string xml = "";

            if (log.HasErrorsOrExceptions())
            {
                xml = ". Result was '" + log.ToXml();
            }
            Assert.That(result.Trim().Equals(expectedResult.Trim(), StringComparison.OrdinalIgnoreCase), "Bad script interpretation" + xml);

            // Case: null, value

            string fluentScript2 = DbFluent.Eq(
                DbFluent.IfNull(value, DbFluent.Field("RegionalDirectorateId", DbFluent.Table("Table1", "Schema1"))), null);

            result = GlobalVariables.AppHost.Scope.Interpreter.Evaluate(fluentScript2, DataExpressionKind.Script, scriptVariableSet, log: log)?.ToString();

            expectedResult = @"COALESCE(NULL, ""Schema1"".""Table1"".""RegionalDirectorateId"") is null";

            xml = "";
            if (log.HasErrorsOrExceptions())
            {
                xml = ". Result was '" + log.ToXml();
            }
            Assert.That(result.Trim().Equals(expectedResult.Trim(), StringComparison.OrdinalIgnoreCase), "Bad script interpretation" + xml);
        }
        public static Dictionary <string, decimal?> BuildHypes(ScriptVariableSet scriptVariableSet)
        {
            // Arrange
            var hypes      = new Dictionary <string, decimal?>();
            var time       = scriptVariableSet.Times[0];
            var currencies = scriptVariableSet.Values[time]["price-change-24hrs"];
            var values     = currencies.Select(x => x.Value).ToArray();

            // Build
            BuildHypes(values);
            var i = 0;

            foreach (var currency in currencies)
            {
                hypes.Add(currency.Key, values[i]);
                i++;
            }

            // Return
            return(hypes);
        }
Example #6
0
        public void TestInterprete_Fun_SqlULPad()
        {
            var log = new BdoLog();

            string fluentScript = DbFluent.LeftPadding(DbFluent.Field("RegionalDirectorateId"), 10, DbFluent.Text("A"));

            var scriptVariableSet = new ScriptVariableSet();

            scriptVariableSet.SetValue(VarSetDb.__DbBuilder,
                                       DbQueryFactory.CreateQueryBuilder <DbQueryBuilder_PostgreSql>(GlobalVariables.AppHost));
            string result = GlobalVariables.AppHost.Scope.Interpreter.Evaluate(fluentScript, DataExpressionKind.Script, scriptVariableSet, log: log)?.ToString();

            string expectedResult = @"lpad(""RegionalDirectorateId"", 10, 'A')";

            string xml = "";

            if (log.HasErrorsOrExceptions())
            {
                xml = ". Result was '" + log.ToXml();
            }
            Assert.That(result.Trim().Equals(expectedResult.Trim(), StringComparison.OrdinalIgnoreCase), "Bad script interpretation" + xml);
        }
Example #7
0
        public void TestInterprete_Fun_SqlIf()
        {
            string value   = null;
            string script1 = DbFluent.If(DbFluent.IsNull(value), DbFluent.Field("RegionalDirectorateId"), DbFluent.Field("RegionalDirectorateId2"));

            string expectedResult = @"case when (null is null) then ""RegionalDirectorateId"" else ""RegionalDirectorateId2"" end";

            var log = new BdoLog();

            var scriptVariableSet = new ScriptVariableSet();

            scriptVariableSet.SetValue(VarSetDb.__DbBuilder,
                                       DbQueryFactory.CreateQueryBuilder <DbQueryBuilder_PostgreSql>(GlobalVariables.AppHost));
            string result = GlobalVariables.AppHost.Scope.Interpreter.Evaluate(script1, DataExpressionKind.Script, scriptVariableSet, log: log)?.ToString();

            string xml = "";

            if (log.HasErrorsOrExceptions())
            {
                xml = ". Result was '" + log.ToXml();
            }
            Assert.That(result.Trim().Equals(expectedResult.Trim(), StringComparison.OrdinalIgnoreCase), "Bad script interpretation" + xml);
        }
Example #8
0
        public void TestInterprete_Fun_SqlEncode()
        {
            string script         = DbFluent.EncodeBase64(DbFluent.Text("ABCDE"));
            string expectedResult = @"encode('ABCDE', 'base64')";

            var log = new BdoLog();

            var scriptVariableSet = new ScriptVariableSet();

            scriptVariableSet.SetValue(VarSetDb.__DbBuilder,
                                       DbQueryFactory.CreateQueryBuilder <DbQueryBuilder_PostgreSql>(GlobalVariables.AppHost));
            string result = GlobalVariables.AppHost.Scope.Interpreter.Evaluate(script, DataExpressionKind.Script, scriptVariableSet, log: log)?.ToString();

            string xml = "";

            if (log.HasErrorsOrExceptions())
            {
                xml = ". Result was '" + log.ToXml();
            }
            Assert.That(result.Trim().Equals(expectedResult.Trim(), StringComparison.OrdinalIgnoreCase), "Bad script interpretation" + xml);

            script         = DbFluent.DecodeBase64(DbFluent.Field("ABCDE"));
            expectedResult = @"decode(""ABCDE"", 'base64')";
            log            = new BdoLog();

            scriptVariableSet = new ScriptVariableSet();
            scriptVariableSet.SetValue(VarSetDb.__DbBuilder,
                                       DbQueryFactory.CreateQueryBuilder <DbQueryBuilder_PostgreSql>(GlobalVariables.AppHost));
            result = GlobalVariables.AppHost.Scope.Interpreter.Evaluate(script, DataExpressionKind.Script, scriptVariableSet, log: log)?.ToString();

            xml = "";
            if (log.HasErrorsOrExceptions())
            {
                xml = ". Result was '" + log.ToXml();
            }
            Assert.That(result.Trim().Equals(expectedResult.Trim(), StringComparison.OrdinalIgnoreCase), "Bad script interpretation" + xml);
        }
Example #9
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="configuration"></param>
 /// <param name="key"></param>
 /// <param name="scope"></param>
 /// <param name="scriptVariableSet">The script variable set to consider.</param>
 /// <param name="log"></param>
 /// <returns></returns>
 public static T GetBdoValue <T>(this IConfiguration configuration, string key, IBdoScope scope = null, ScriptVariableSet scriptVariableSet = null, IBdoLog log = null)
     where T : class
 {
     return(configuration?.GetBdoValue <T>(key, default, scope, scriptVariableSet, log));