public bool ItExecutesStatements(string statement, string rawStatement, int scope) { var load = new ReflectionStatementDefinition(GetMethod(statement), typeof(TestStatements)); var linked = load.Link(rawStatement); Assert.IsNotNull(linked); return(linked.Execute(new InvokationContext() { Scope = scope, Context = new ContextBundle(), })); }
public static InvokationResult Invoke <T>(Type controller, string methodName, T scope, string statement, ContextBundle context = null, Func <object, bool> proceed = null) { if (proceed == null) { proceed = o => false; } context = context ?? new ContextBundle(); var method = GetMethod(controller, methodName); var statementHandler = new ReflectionStatementDefinition(method, controller); var invokationResult = new InvokationResult() { Context = context, Statement = statement, MatchingCriteria = statementHandler.GetMatchingCriteria(), Attachments = new ContextBundle() }; invokationResult.Match = statementHandler.Matches(new MatchingContext() { Statement = statement, ScopeType = typeof(T) }); if (!invokationResult.Matched) { return(invokationResult); } var link = statementHandler.Link(statement); if (link == null) { throw new Exception("If matched, should have linked, but didn't"); } invokationResult.Result = link.Execute(new InvokationContext() { Context = invokationResult.Context, Attachments = invokationResult.Attachments, Scope = scope, Proceed = proceed }); return(invokationResult); }
[TestCase("R4", "I haz 10 cheeseburgers", "1", 1, ExpectedException = typeof(CannotLinkStatementException), TestName = "It errors when cannot make parameter")] //too many public bool ItExecutesAggregates(string statement, string rawStatement, string strScope, int expectedCalls) { var scope = strScope.Split(',').Select(int.Parse); var load = new ReflectionStatementDefinition(GetAggregateMethod(statement), typeof(TestAggregates)); var link = load.Link(rawStatement); Assert.IsNotNull(link); var calls = 0; var result = link.Execute(new InvokationContext() { Scope = scope, Proceed = o => { calls++; return(((int)o) % 2 == 0); } }); Assert.AreEqual(expectedCalls, calls); return(result); }
public void ItDoesNotReUseControllers() { var load = new ReflectionStatementDefinition(GetMethod("R8"), typeof(TestStatements)); var linked = load.Link("R8"); var att1 = new ContextBundle(); var att2 = new ContextBundle(); linked.Execute(new InvokationContext() { Scope = 9, Attachments = att1 }); linked.Execute(new InvokationContext() { Scope = 9, Attachments = att2 }); var ctr1 = att1.Get <TestStatements>("controller"); var ctr2 = att2.Get <TestStatements>("controller"); Assert.AreNotSame(ctr1, ctr2); }