/// <summary>Test stub for ProcessResultOperator(ResultOperatorBase, QueryModel, IGeneratedCode)</summary> internal GeneratedCode ProcessResultOperator( ROTakeSkipOperators target, ResultOperatorBase resultOperator, QueryModel queryModel, GeneratedCode codeEnv ) { if (codeEnv.ResultValue != null) { throw new ArgumentException("this should not be null for this test"); } if (codeEnv.CodeBody.DeclaredVariables == null) { throw new ArgumentException("Need this declare variables to be defined"); } /// /// We always expect to be inside a loop - and depend on it for doing our declares, so add something... /// var inlineBlock = new StatementInlineBlock(); codeEnv.Add(inlineBlock); /// /// Get the environment setup and run it /// CodeContext c = new CodeContext(); c.SetLoopVariable(Expression.Variable(typeof(int), "d"), null); target.ProcessResultOperator(resultOperator, queryModel, codeEnv, c, MEFUtilities.MEFContainer); codeEnv.DumpCodeToConsole(); /// /// First, there should be a counter now declared and ready to go in the current variable block - which will /// be the outer one for this test. If this is the outter most, then this is going to be burried. /// var declBlock = inlineBlock.Parent.Parent as IBookingStatementBlock; Assert.IsNotNull(declBlock, "Expecting a declaration block above!"); Assert.AreEqual(1, inlineBlock.Statements.Count(), "Expected an if block/increment!"); Assert.IsInstanceOfType(inlineBlock.Statements.First(), typeof(StatementIfOnCount), "if statement not found!"); var s = inlineBlock.Statements.First() as StatementIfOnCount; bool isTopLevel = codeEnv.DumpCode().Where(l => l.Contains("static int")).Any(); if (!isTopLevel) { Assert.AreEqual(1, declBlock.DeclaredVariables.Count(), "Expected only 1 variable to be declared"); Assert.IsInstanceOfType(declBlock.DeclaredVariables.First(), typeof(DeclarableParameter), "Expected it to be a counter"); } else { Assert.AreEqual(1, (s.Parent as IBookingStatementBlock).DeclaredVariables.Count()); } string count = ""; if (resultOperator is SkipResultOperator) { count = (resultOperator as SkipResultOperator).Count.ToString(); } else if (resultOperator is TakeResultOperator) { count = (resultOperator as TakeResultOperator).Count.ToString(); } Assert.AreEqual(count, s.Limit.RawValue, "bad count made it through"); /// /// Finally, the current loop variable should be identical, and there should be no result set. /// Assert.IsNull(codeEnv.ResultValue, "result value"); Assert.IsInstanceOfType(c.LoopVariable, typeof(ParameterExpression), "loop variable type"); var lv = c.LoopVariable as ParameterExpression; Assert.AreEqual("d", lv.Name, "loop variable name"); // // Dump everything and return. To force it out, add a dummy statement // (because if statements, etc., are smart enough to not print anything if they // are empty). // codeEnv.Add(new StatementSimpleStatement("fork = left")); codeEnv.DumpCodeToConsole(); return(codeEnv); }
/// <summary>Test stub for ProcessResultOperator(ResultOperatorBase, QueryModel, IGeneratedCode)</summary> internal GeneratedCode ProcessResultOperator( ROTakeSkipOperators target, ResultOperatorBase resultOperator, QueryModel queryModel, GeneratedCode codeEnv ) { if (codeEnv.ResultValue != null) throw new ArgumentException("this should not be null for this test"); if (codeEnv.CodeBody.DeclaredVariables == null) throw new ArgumentException("Need this declare variables to be defined"); /// /// We always expect to be inside a loop - and depend on it for doing our declares, so add something... /// var inlineBlock = new StatementInlineBlock(); codeEnv.Add(inlineBlock); /// /// Get the environment setup and run it /// CodeContext c = new CodeContext(); c.SetLoopVariable(Expression.Variable(typeof(int), "d"), null); target.ProcessResultOperator(resultOperator, queryModel, codeEnv, c, MEFUtilities.MEFContainer); codeEnv.DumpCodeToConsole(); /// /// First, there should be a counter now declared and ready to go in the current variable block - which will /// be the outer one for this test. If this is the outter most, then this is going to be burried. /// var declBlock = inlineBlock.Parent.Parent as IBookingStatementBlock; Assert.IsNotNull(declBlock, "Expecting a declaration block above!"); Assert.AreEqual(1, inlineBlock.Statements.Count(), "Expected an if block/increment!"); Assert.IsInstanceOfType(inlineBlock.Statements.First(), typeof(StatementIfOnCount), "if statement not found!"); var s = inlineBlock.Statements.First() as StatementIfOnCount; bool isTopLevel = codeEnv.DumpCode().Where(l => l.Contains("static int")).Any(); if (!isTopLevel) { Assert.AreEqual(1, declBlock.DeclaredVariables.Count(), "Expected only 1 variable to be declared"); Assert.IsInstanceOfType(declBlock.DeclaredVariables.First(), typeof(DeclarableParameter), "Expected it to be a counter"); } else { Assert.AreEqual(1, (s.Parent as IBookingStatementBlock).DeclaredVariables.Count()); } string count = ""; if (resultOperator is SkipResultOperator) { count = (resultOperator as SkipResultOperator).Count.ToString(); } else if (resultOperator is TakeResultOperator) { count = (resultOperator as TakeResultOperator).Count.ToString(); } Assert.AreEqual(count, s.Limit.RawValue, "bad count made it through"); /// /// Finally, the current loop variable should be identical, and there should be no result set. /// Assert.IsNull(codeEnv.ResultValue, "result value"); Assert.IsInstanceOfType(c.LoopVariable, typeof(ParameterExpression), "loop variable type"); var lv = c.LoopVariable as ParameterExpression; Assert.AreEqual("d", lv.Name, "loop variable name"); // // Dump everything and return. To force it out, add a dummy statement // (because if statements, etc., are smart enough to not print anything if they // are empty). // codeEnv.Add(new StatementSimpleStatement("fork = left")); codeEnv.DumpCodeToConsole(); return codeEnv; }