Пример #1
0
        public void CallScope_Size_EmptyArgsListDoesNotCauseSequenceCastException()
        {
            CallScope callScope = new CallScope(new MockScope());

            callScope.Args = Value.Empty;
            Assert.Equal(0, callScope.Size);
        }
Пример #2
0
        public void Session_FnLotTag_ReturnsDateFromFirstArgAmouunt()
        {
            Session session = new Session();

            Amount    amount1 = new Amount(0); // No tag
            CallScope scope1  = new CallScope(new EmptyScope());

            //scope1.PushBack(Value.Get(false));  // first argument
            scope1.PushBack(Value.Get(amount1));
            Assert.AreEqual(Value.Empty, session.FnLotTag(scope1));

            Commodity  commodity  = new Commodity(CommodityPool.Current, new CommodityBase("base"));
            string     tag        = "my-tag";
            Annotation annotation = new Annotation()
            {
                Tag = tag
            };
            AnnotatedCommodity annotatedCommodity = new AnnotatedCommodity(commodity, annotation);
            Amount             amount2            = new Amount(BigInt.FromInt(10), annotatedCommodity); // With date
            CallScope          scope2             = new CallScope(new EmptyScope());

            //scope2.PushBack(Value.Get(false));  // first argument
            scope2.PushBack(Value.Get(amount2));
            Assert.AreEqual(tag, session.FnLotTag(scope2).AsString);
        }
Пример #3
0
        public void Session_FnLotDate_ReturnsDateFromFirstArgAmount()
        {
            Session session = new Session();

            Amount    amount1 = new Amount(0); // No date
            CallScope scope1  = new CallScope(new EmptyScope());

            //scope1.PushBack(Value.Get(false));  // first argument
            scope1.PushBack(Value.Get(amount1));
            Assert.AreEqual(Value.Empty, session.FnLotDate(scope1));

            Commodity  commodity  = new Commodity(CommodityPool.Current, new CommodityBase("base"));
            Date       date       = (Date)DateTime.Now.Date;
            Annotation annotation = new Annotation()
            {
                Date = date
            };
            AnnotatedCommodity annotatedCommodity = new AnnotatedCommodity(commodity, annotation);
            Amount             amount2            = new Amount(BigInt.FromInt(10), annotatedCommodity); // With date
            CallScope          scope2             = new CallScope(new EmptyScope());

            //scope2.PushBack(Value.Get(false));  // first argument
            scope2.PushBack(Value.Get(amount2));
            Assert.AreEqual(date, session.FnLotDate(scope2).AsDate);
        }
Пример #4
0
        private static Value GetAccount(CallScope args)  // this gets the name
        {
            Account account = args.Context <Account>();

            if (args.Has <string>(0))
            {
                Account acct = account.Parent;
                while (acct != null)
                {
                    acct = acct.Parent;
                }
                if (args[0].Type == ValueTypeEnum.String)
                {
                    return(Value.ScopeValue(acct.FindAccount(args.Get <string>(0), false)));
                }
                else if (args[0].Type == ValueTypeEnum.Mask)
                {
                    return(Value.ScopeValue(acct.FindAccountRe(args.Get <Mask>(0).ToString())));
                }
                else
                {
                    return(Value.Empty);
                }
            }
            else if (args.TypeContext == ValueTypeEnum.Scope)
            {
                return(Value.ScopeValue(account));
            }
            else
            {
                return(Value.StringValue(account.FullName));
            }
        }
Пример #5
0
        // query_command
        public static Value QueryCommand(CallScope args)
        {
            Report        report = args.FindScope <Report>();
            StringBuilder sb     = new StringBuilder();

            sb.AppendLine("--- Input arguments ---");
            sb.AppendLine(args.Value().Dump());
            sb.AppendLine();

            Query query = new Query(args.Value(), report.WhatToKeep(), report.CollapseHandler.Handled);

            if (query.HasQuery(QueryKindEnum.QUERY_LIMIT))
            {
                CallScope subArgs = new CallScope(args);
                subArgs.PushBack(Value.StringValue(query.GetQuery(QueryKindEnum.QUERY_LIMIT)));

                report.OutputStream.Write(sb.ToString());
                ParseCommand(subArgs);
            }

            if (query.HasQuery(QueryKindEnum.QUERY_SHOW))
            {
                sb.AppendLine();
                sb.AppendLine("====== Display predicate ======");
                sb.AppendLine();

                CallScope dispSubArgs = new CallScope(args);
                dispSubArgs.PushBack(Value.StringValue(query.GetQuery(QueryKindEnum.QUERY_SHOW)));

                report.OutputStream.Write(sb.ToString());
                ParseCommand(dispSubArgs);
            }

            return(Value.Empty);
        }
Пример #6
0
        // format_command
        public static Value FormatCommand(CallScope args)
        {
            string arg = CallScope.JoinArgs(args);

            if (String.IsNullOrEmpty(arg))
            {
                throw new LogicError(LogicError.ErrorMessageUsageFormatText);
            }

            Report        report = args.FindScope <Report>();
            StringBuilder sb     = new StringBuilder();

            Post post = GetSampleXact(report);

            sb.AppendLine("--- Input format string ---");
            sb.AppendLine(arg);
            sb.AppendLine();

            sb.AppendLine("--- Format elements ---");
            Format fmt = new Format(arg);

            sb.AppendLine(fmt.Dump());

            sb.AppendLine("--- Formatted string ---");
            BindScope boundScope = new BindScope(args, post);

            sb.AppendFormat("\"{0}\"", fmt.Calc(boundScope));
            sb.AppendLine();

            report.OutputStream.Write(sb.ToString());
            return(Value.Empty);
        }
Пример #7
0
        public void Option_ProcessEnvironment_IgnoresEmptyValues()
        {
            OptFunctScopes.Clear();

            MockScope mockScope = new MockScope();

            mockScope.LookupResult            = new ExprOp(OpKindEnum.FUNCTION);
            mockScope.LookupResult.AsFunction = OptFunct;

            IDictionary <string, string> envp = new Dictionary <string, string>();

            envp.Add("opt-1-1", "val1");
            envp.Add("opt-1-2", "val2");
            envp.Add("opt-2-1", "");
            envp.Add("opt-2-2", "val4");
            envp.Add("opt-3-1", "val5");
            envp.Add("opt-3-2", "val6");

            Option.ProcessEnvironment(envp, "opt-2", mockScope);

            Assert.AreEqual(1, OptFunctScopes.Count);
            CallScope callScope = OptFunctScopes.First() as CallScope;

            Assert.AreEqual(2, callScope.Size);
            Assert.AreEqual("$-2", callScope[0].ToString());
            Assert.AreEqual("val4", callScope[1].ToString());
        }
Пример #8
0
        private Value CalcCall(Scope scope, ExprOp locus, int depth)
        {
            ExprOp func = Left;
            string name = func.IsIdent ? func.AsIdent : "<value expr>";

            func = FindDefinition(func, scope, locus, depth);

            CallScope callArgs = new CallScope(scope, locus, depth + 1);

            if (HasRight)
            {
                callArgs.Args = SplitConsExpr(Right);
            }

            try
            {
                if (func.IsFunction)
                {
                    return(func.AsFunction(callArgs));
                }
                else
                {
                    if (func.Kind != OpKindEnum.O_LAMBDA)
                    {
                        throw new InvalidOperationException("Not a lambda");
                    }

                    return(CallLambda(func, scope, callArgs, locus, depth));
                }
            }
            catch (Exception ex)
            {
                throw new Exception(String.Format("While calling function '{0} {1}':", name, callArgs.Args), ex);
            }
        }
Пример #9
0
        public void Option_Handler_ChecksThatTheNumerOfArgumentsNotLessThan1WhenWantsArgIsNo()
        {
            Option    option1 = new Option("myname");
            CallScope scope   = new CallScope(new EmptyScope());

            Assert.AreEqual(0, scope.Size);
            option1.Handler(scope);
        }
Пример #10
0
        public void Option_Handler_ChecksThatTheNumerOfArgumentsNotLessThan1WhenWantsArgIsNo()
        {
            Option    option1 = new Option("myname");
            CallScope scope   = new CallScope(new EmptyScope());

            Assert.Equal(0, scope.Size);
            Assert.Throws <InvalidOperationException>(() => option1.Handler(scope));
        }
Пример #11
0
        public void Option_Handler_ChecksThatTheNumerOfArgumentsNotLessThan2WhenWantsArgIsYes()
        {
            Option    option1 = new Option("myname_");
            CallScope scope   = new CallScope(new EmptyScope());

            scope.PushFront(Value.Get(true));
            Assert.AreEqual(1, scope.Size);
            option1.Handler(scope);
        }
Пример #12
0
        public void CallScope_Resolve_DoesNotCalculateNonAnyValues()
        {
            CallScope callScope = new CallScope(new MockScope());
            callScope.PushFront(Value.Get(33));

            Value result = callScope.Resolve(0);

            Assert.Equal(33, result.AsLong);
        }
Пример #13
0
        public void CallScope_Context_LooksForParentContextByType()
        {
            MockScope parent    = new MockScope();
            CallScope callScope = new CallScope(parent);

            MockScope result = callScope.Context <MockScope>();

            Assert.Equal(parent, result);
        }
Пример #14
0
        public void Option_Handler_CallsOnWithOneArgumentIfWantsArgIsNo()
        {
            Option    option1 = new Option("myname");
            CallScope scope1  = new CallScope(new EmptyScope());

            scope1.PushFront(Value.Get("whence"));
            option1.Handler(scope1);
            Assert.IsTrue(option1.Handled);
        }
Пример #15
0
        public void Option_Handler_CallsReturnsTrueValue()
        {
            Option    option1 = new Option("myname");
            CallScope scope1  = new CallScope(new EmptyScope());

            scope1.PushFront(Value.Get("whence"));
            Value val = option1.Handler(scope1);

            Assert.IsTrue(val.AsBoolean);
        }
Пример #16
0
        public void CallScope_Resolve_CallsAnyValuesAsExpr()
        {
            CallScope callScope = new CallScope(new MockScope());
            ExprOp testExprOp = new ExprOp(OpKindEnum.VALUE) { AsValue = Value.Get(55) };
            callScope.PushFront(Value.Get(testExprOp));

            Value result = callScope.Resolve(0, ValueTypeEnum.Integer, true);

            Assert.Equal(55, result.AsLong);
        }
Пример #17
0
        public void Session_FnInt_ReturnsFirstArgumentAsLong()
        {
            Session session = new Session();
            Value   val     = Value.Get(234);

            CallScope scope1 = new CallScope(new EmptyScope());

            scope1.PushBack(val);
            Assert.AreEqual(234, session.FnInt(scope1).AsLong);
        }
Пример #18
0
        protected virtual void Dispose(bool disposing)
        {
            var tables = new[]
            {
                "person"
            };

            _databaseFixture.ResetDataInTestDatabase(tables);
            CallScope.Dispose();
        }
Пример #19
0
        public void CallScope_IsEmpty_IndicatesWhetherArgsAreEmpty()
        {
            CallScope callScope = new CallScope(new MockScope());

            Assert.True(callScope.IsEmpty);
            callScope.PushBack(Value.Get(11));
            Assert.False(callScope.IsEmpty);
            callScope.PopBack();
            Assert.True(callScope.IsEmpty);
        }
Пример #20
0
        public void Session_FnStr_ReturnsFirstArgumentAsString()
        {
            Session session = new Session();
            Value   val     = Value.Get("USD23");

            CallScope scope1 = new CallScope(new EmptyScope());

            scope1.PushBack(val);
            Assert.AreEqual(23, session.FnStr(scope1).AsAmount.Quantity.ToLong());  // TODO - validate this case
        }
Пример #21
0
        public void CallScope_Value_ThisIsEqualToResolve()
        {
            CallScope callScope = new CallScope(new MockScope());

            ExprOp testExprOp = new ExprOp(OpKindEnum.VALUE) { AsValue = Value.Get(55) };
            callScope.PushFront(Value.Get(testExprOp));

            Value result = callScope[0];

            Assert.Equal(55, result.AsLong);
        }
Пример #22
0
        public void Option_Handler_ChecksThatTheNumerOfArgumentsNotMoreThan2WhenWantsArgIsYes()
        {
            Option    option1 = new Option("myname_");
            CallScope scope   = new CallScope(new EmptyScope());

            scope.PushFront(Value.Get(true));
            scope.PushFront(Value.Get(true));
            scope.PushFront(Value.Get(true));
            Assert.Equal(3, scope.Size);
            Assert.Throws <InvalidOperationException>(() => option1.Handler(scope));
        }
Пример #23
0
        protected virtual void Dispose(bool disposing)
        {
            var tables = new[]
            {
                "zipuser",
                "account"
            };

            _databaseFixture.ResetDataInTestDatabase(tables);
            CallScope.Dispose();
        }
Пример #24
0
        public void Option_Handler_CallsOnWithTwoArgumentsIfWantsArgIsYes()
        {
            Option    option1 = new Option("myname_");
            CallScope scope1  = new CallScope(new EmptyScope());

            scope1.PushFront(Value.Get("whence"));
            scope1.PushBack(Value.Get("str"));
            option1.Handler(scope1);
            Assert.AreEqual("str", option1.Value);
            Assert.IsTrue(option1.Handled);
        }
Пример #25
0
        public void CallScope_Value_MakesSureThatAllArgumentsAreResolved()
        {
            CallScope callScope = new CallScope(new MockScope());

            ExprOp testExprOp = new ExprOp(OpKindEnum.VALUE) { AsValue = Value.Get(55) };
            callScope.PushFront(Value.Get(testExprOp));

            Value result = callScope.Value();

            Assert.Equal(55, callScope.Args.AsSequence[0].AsLong);
        }
Пример #26
0
        public void CallScope_Resolve_UpdatesArgumentWithExpressionResult_ArgsIsSingleValue()
        {
            MockScope parent    = new MockScope();
            CallScope callScope = new CallScope(parent);

            callScope.Args = Value.Get(new Expr("\"ABC\"").Op);
            Value val1 = callScope.Resolve(0, ValueTypeEnum.String, true);

            Assert.Equal("ABC", val1.AsString);
            Assert.Equal(val1, callScope.Args);
            Assert.Equal(val1.AsString, callScope.Args.AsSequence[0].AsString);
        }
Пример #27
0
        public void CallScope_Get_ConvertsByDefault()
        {
            MockScope parent    = new MockScope();
            CallScope callScope = new CallScope(parent);

            callScope.Args = Value.Get(new List <Value>());
            callScope.Args.AsSequence.Add(Value.Get(new Amount(22)));

            int result = callScope.Get <int>(0); // convert is not specified; "true" by default

            Assert.Equal(22, result);            // Amount is automatically converted to int
        }
Пример #28
0
        public void Option_Call_CallsHandlerIfArgsNotEmpty()
        {
            Option    option1 = new Option("myname_");
            CallScope scope1  = new CallScope(new EmptyScope());

            scope1.PushFront(Value.Get("str"));
            Value val = option1.Call(scope1);

            Assert.IsTrue(val.AsBoolean);
            Assert.IsTrue(option1.Handled);
            Assert.AreEqual("str", option1.Value);
        }
Пример #29
0
        public void Option_Call_ReturnsValueIfWantsArgsAndArgsAreEmpty()
        {
            Option option1 = new Option("myname_")
            {
                Value = "val"
            };
            CallScope scope1 = new CallScope(new EmptyScope());
            Value     val    = option1.Call(scope1);

            Assert.AreEqual("val", val.AsString);
            Assert.IsFalse(option1.Handled);
        }
Пример #30
0
        public void CallScope_Get_SupportsDateTime()
        {
            MockScope parent    = new MockScope();
            CallScope callScope = new CallScope(parent);

            callScope.Args = Value.Get(new List <Value>());
            callScope.Args.AsSequence.Add(Value.Get(new DateTime(2015, 10, 22)));

            DateTime result = callScope.Get <DateTime>(0);

            Assert.Equal(new DateTime(2015, 10, 22), result);
        }
Пример #31
0
        public void DialSipTest()
        {
            var c = new DelegateInArgument<CallContext>();

            var a = new CallScope()
            {
                Body = new ActivityAction<CallContext>()
                {
                    Argument = c,
                    Handler = new Dial()
                    {
                        Activities =
                        {
                            new DialSip()
                            {
                                Uris =
                                {
                                    new DialSipUri()
                                    {
                                        Uri = "*****@*****.**",
                                        UserName = "******",
                                    },
                                    new DialSipUri()
                                    {
                                        Uri = "*****@*****.**",
                                        UserName = "******",
                                    },
                                },
                            },
                        },
                    },
                },
            };

            var ctx = CreateContext(a);
            ctx.Invoke();

            Assert.AreEqual("<Response><Dial>+15555555555</Dial></Response>", ctx.Response.ToString(SaveOptions.DisableFormatting));
        }
Пример #32
0
        /// <summary>
        /// Initializes a new instance.
        /// </summary>
        /// <param name="activity"></param>
        public TwilioTestContext(Activity activity)
        {
            // wrap in CallScope
            var arg1 = new DelegateInArgument<CallContext>();
            var scope = new CallScope()
            {
                Body = new ActivityAction<CallContext>()
                {
                    Argument = arg1,
                    Handler = activity,
                },
            };

            // workflow needs a sync context to run on
            sync = new SynchronizedSynchronizationContext();

            // new invoker which uses ourself as the context
            app = new WorkflowApplication(scope);
            app.Extensions.Add<ITwilioContext>(() => this);
            app.Completed = a => state = a.CompletionState;

            response = new XElement("Response");
            element = response;
        }