/// <summary>Test stub for CanHandle(Type)</summary>
        //[PexMethod]
        public bool CanHandle(TypeHandlerReplacementCall target, Type t)
        {
            bool result = target.CanHandle(t);

            return(result);
            // TODO: add assertions to method TypeHandlerReplacementCallTest.CanHandle(TypeHandlerReplacementCall, Type)
        }
        public void TestStringParsing()
        {
            StringBuilder bld = new StringBuilder();

            bld.AppendLine("#<classtype Name> func(arg1 FullName type, arg2 FullName type) => c++func(cppargtype, cppargtype)");
            bld.AppendLine("ParseTest sin(System.Double) => sin(double)");
            bld.AppendLine("ParseTest f1(System.Int32, System.Int32) => f1(int, int)");
            bld.AppendLine("ParseTest f2(System.Double,System.Double) => f2(double,double)");

            var target = new TypeHandlerReplacementCall();

            target.Parse(new StringReader(bld.ToString()));

            var e1 = Expression.Call(null, typeof(ParseTest).GetMethod("sin"), new Expression[] { Expression.Constant((double)10.3) });
            var e2 = Expression.Call(null, typeof(ParseTest).GetMethod("f1"), new Expression[] { Expression.Constant((int)10), Expression.Constant((int)20) });
            var e3 = Expression.Call(null, typeof(ParseTest).GetMethod("f2"), new Expression[] { Expression.Constant((double)10.3), Expression.Constant((double)20.3) });

            var gc      = new GeneratedCode();
            var context = new CodeContext();

            var result = CodeMethodCall(target, e1, gc);

            Assert.AreEqual("sin((double)10.3)", result.RawValue, "sin incorrect");

            result = CodeMethodCall(target, e2, gc);
            Assert.AreEqual("f1((int)10,(int)20)", result.RawValue, "f1 incorrect");

            result = CodeMethodCall(target, e3, gc);
            Assert.AreEqual("f2((double)10.3,(double)20.3)", result.RawValue, "f2 incorrect");
        }
        public void TestCanHandleSimpleTestWithLoadedType()
        {
            TypeHandlerReplacementCall.AddMethod("SimpleTest", "noArg", "noArg");
            var r = CanHandle(new TypeHandlerReplacementCall(), typeof(SimpleTest));

            Assert.IsTrue(r, "everything should have been loaded");
        }
        public void TestRightClassBadMethod()
        {
            TypeHandlerReplacementCall.AddMethod("SimpleTest", "noArgDude", "noArg");

            var e       = Expression.Call(null, typeof(SimpleTest).GetMethod("noArg"));
            var gc      = new GeneratedCode();
            var context = new CodeContext();
            var r       = CodeMethodCall(new TypeHandlerReplacementCall(), e, gc);
        }
 public IValue CodeMethodCall(
     TypeHandlerReplacementCall target,
     MethodCallExpression expr,
     IGeneratedQueryCode gc
 )
 {
     var result01 = target.CodeMethodCall(expr, gc, MEFUtilities.MEFContainer);
     return result01;
 }
        public void TestSameMethodsDifferentArgTypes()
        {
            TypeHandlerReplacementCall.AddMethod("SimpleTest", "oneArg", "oneArg", new Tuple <string, string>[] { new Tuple <string, string>(typeof(float).FullName, "float") });

            var e       = Expression.Call(null, typeof(SimpleTest).GetMethod("oneArg"), new Expression[] { Expression.Constant((int)10) });
            var gc      = new GeneratedCode();
            var context = new CodeContext();
            var r       = CodeMethodCall(new TypeHandlerReplacementCall(), e, gc);
        }
        public void TestRigthClassMethodBadArgsDefined()
        {
            TypeHandlerReplacementCall.AddMethod("SimpleTest", "noArg", "noArg", new Tuple <string, string>[] { new Tuple <string, string>(typeof(int).FullName, "int") });

            var e       = Expression.Call(null, typeof(SimpleTest).GetMethod("noArg"));
            var gc      = new GeneratedCode();
            var context = new CodeContext();
            var r       = CodeMethodCall(new TypeHandlerReplacementCall(), e, gc);
        }
        public void TestRigthClassMethodBadArgs()
        {
            TypeHandlerReplacementCall.AddMethod("SimpleTest", "oneArg", "oneArg");

            var e       = Expression.Call(null, typeof(SimpleTest).GetMethod("oneArg"), new Expression[] { Expression.Constant((int)1) });
            var gc      = new GeneratedCode();
            var context = new CodeContext();
            var r       = CodeMethodCall(new TypeHandlerReplacementCall(), e, gc);
        }
        public IValue CodeMethodCall(
            TypeHandlerReplacementCall target,
            MethodCallExpression expr,
            IGeneratedQueryCode gc
            )
        {
            var result01 = target.CodeMethodCall(expr, gc, MEFUtilities.MEFContainer);

            return(result01);
        }
 /// <summary>Test stub for ProcessMethodCall(MethodCallExpression, IValue&amp;, IGeneratedCode, ICodeContext)</summary>
 ///[PexMethod]
 public Expression ProcessMethodCall(
     TypeHandlerReplacementCall target,
     MethodCallExpression expr,
     IGeneratedQueryCode gc,
     ICodeContext context
 )
 {
     Expression result01 = target.ProcessMethodCall(expr, gc, context, MEFUtilities.MEFContainer);
     return result01;
     // TODO: add assertions to method TypeHandlerReplacementCallTest.ProcessMethodCall(TypeHandlerReplacementCall, MethodCallExpression, IValue&, IGeneratedCode, ICodeContext)
 }
        public void TestCallWithArgs()
        {
            TypeHandlerReplacementCall.AddMethod("SimpleTest", "oneArg", "oneArg", new Tuple <string, string>[] { new Tuple <string, string>(typeof(int).FullName, "int") });

            var e       = Expression.Call(null, typeof(SimpleTest).GetMethod("oneArg"), new Expression[] { Expression.Constant((int)10) });
            var gc      = new GeneratedCode();
            var context = new CodeContext();
            var r       = CodeMethodCall(new TypeHandlerReplacementCall(), e, gc);

            Assert.AreEqual("oneArg((int)10)", r.RawValue, "uncorrected coded method argument");
        }
        public void TestIncludes()
        {
            TypeHandlerReplacementCall.AddMethod("SimpleTest", "noArg", "noArg", null, new string[] { "cmath" });

            var e       = Expression.Call(null, typeof(SimpleTest).GetMethod("noArg"));
            var gc      = new GeneratedCode();
            var context = new CodeContext();
            var result  = CodeMethodCall(new TypeHandlerReplacementCall(), e, gc);

            Assert.AreEqual(1, gc.IncludeFiles.Count(), "# include files");
            Assert.AreEqual("cmath", gc.IncludeFiles.First(), "include filename");
        }
        /// <summary>Test stub for ProcessMethodCall(MethodCallExpression, IValue&amp;, IGeneratedCode, ICodeContext)</summary>
        ///[PexMethod]
        public Expression ProcessMethodCall(
            TypeHandlerReplacementCall target,
            MethodCallExpression expr,
            IGeneratedQueryCode gc,
            ICodeContext context
            )
        {
            Expression result01 = target.ProcessMethodCall(expr, gc, context, MEFUtilities.MEFContainer);

            return(result01);
            // TODO: add assertions to method TypeHandlerReplacementCallTest.ProcessMethodCall(TypeHandlerReplacementCall, MethodCallExpression, IValue&, IGeneratedCode, ICodeContext)
        }
        public void TestNoArg()
        {
            TypeHandlerReplacementCall.AddMethod("SimpleTest", "noArg", "noArg");

            var e       = Expression.Call(null, typeof(SimpleTest).GetMethod("noArg"));
            var gc      = new GeneratedCode();
            var context = new CodeContext();
            var result  = CodeMethodCall(new TypeHandlerReplacementCall(), e, gc);

            Assert.AreEqual(typeof(double), result.Type, "the type that came back isn't right");
            Assert.AreEqual("noArg()", result.RawValue, "raw translation incorrect");
        }
        public void TestAutoLoad()
        {
            var tanmethod = from m in typeof(Math).GetMethods()
                            where m.Name == "Tan"
                            where m.ReturnParameter.ParameterType == typeof(double)
                            select m;

            var e0 = Expression.Call(null, tanmethod.FirstOrDefault(), new Expression[] { Expression.Constant((double)10.3) });

            var gc      = new GeneratedCode();
            var context = new CodeContext();
            var target  = new TypeHandlerReplacementCall();

            CodeMethodCall(target, e0, gc);
        }
        public void TestFunctionMerge()
        {
            StringBuilder bld = new StringBuilder();

            bld.AppendLine("ParseTest sin(System.Double) => freak(double)");
            var target = new TypeHandlerReplacementCall();

            target.Parse(new StringReader(bld.ToString()));

            bld = new StringBuilder();
            bld.AppendLine("ParseTest sin(System.Double) => sin(double)");
            target.Parse(new StringReader(bld.ToString()));

            var e1 = Expression.Call(null, typeof(ParseTest).GetMethod("sin"), new Expression[] { Expression.Constant((double)10.3) });

            var gc      = new GeneratedCode();
            var context = new CodeContext();

            var result = CodeMethodCall(target, e1, gc);

            Assert.AreEqual("freak((double)10.3)", result.RawValue, "sin incorrect");
        }
        public void TestParseInclude()
        {
            StringBuilder bld = new StringBuilder();

            bld.AppendLine("include: cmath1 cmath3");
            bld.AppendLine("ParseTest sin(System.Double) => freak(double)");
            bld.AppendLine("include: cmath2");
            bld.AppendLine("ParseTest cos(System.Double) => cos(double)");
            bld.AppendLine("include: ");
            bld.AppendLine("ParseTest tan(System.Double) => tan(double)");
            var target = new TypeHandlerReplacementCall();

            target.Parse(new StringReader(bld.ToString()));

            var gc      = new GeneratedCode();
            var context = new CodeContext();

            var e0     = Expression.Call(null, typeof(ParseTest).GetMethod("tan"), new Expression[] { Expression.Constant((double)10.3) });
            var result = CodeMethodCall(target, e0, gc);

            Assert.AreEqual(0, gc.IncludeFiles.Count(), "# include files after none should have been added");

            var e1 = Expression.Call(null, typeof(ParseTest).GetMethod("cos"), new Expression[] { Expression.Constant((double)10.3) });

            result = CodeMethodCall(target, e1, gc);
            Assert.AreEqual(1, gc.IncludeFiles.Count(), "# include files");
            Assert.AreEqual("cmath2", gc.IncludeFiles.First(), "include filename");

            var e2 = Expression.Call(null, typeof(ParseTest).GetMethod("sin"), new Expression[] { Expression.Constant((double)10.3) });

            result = CodeMethodCall(target, e2, gc);
            Assert.AreEqual(3, gc.IncludeFiles.Count(), "# include files");
            Assert.IsTrue(gc.IncludeFiles.Contains("cmath1"), "cmath1 missing");
            Assert.IsTrue(gc.IncludeFiles.Contains("cmath2"), "cmath1 missing");
            Assert.IsTrue(gc.IncludeFiles.Contains("cmath3"), "cmath1 missing");
        }
 public void TestProcessConstantReference()
 {
     var p = new TypeHandlerReplacementCall();
     p.ProcessConstantReference(null, null, null);
 }
 /// <summary>Test stub for CanHandle(Type)</summary>
 //[PexMethod]
 public bool CanHandle(TypeHandlerReplacementCall target, Type t)
 {
     bool result = target.CanHandle(t);
     return result;
     // TODO: add assertions to method TypeHandlerReplacementCallTest.CanHandle(TypeHandlerReplacementCall, Type)
 }
        public void TestAutoLoad()
        {
            var tanmethod = from m in typeof(Math).GetMethods()
                            where m.Name == "Tan"
                            where m.ReturnParameter.ParameterType == typeof(double)
                            select m;

            var e0 = Expression.Call(null, tanmethod.FirstOrDefault(), new Expression[] { Expression.Constant((double)10.3) });

            var gc = new GeneratedCode();
            var context = new CodeContext();
            var target = new TypeHandlerReplacementCall();

            CodeMethodCall(target, e0, gc);
        }
        public void TestParseInclude()
        {
            StringBuilder bld = new StringBuilder();
            bld.AppendLine("include: cmath1 cmath3");
            bld.AppendLine("ParseTest sin(System.Double) => freak(double)");
            bld.AppendLine("include: cmath2");
            bld.AppendLine("ParseTest cos(System.Double) => cos(double)");
            bld.AppendLine("include: ");
            bld.AppendLine("ParseTest tan(System.Double) => tan(double)");
            var target = new TypeHandlerReplacementCall();
            target.Parse(new StringReader(bld.ToString()));

            var gc = new GeneratedCode();
            var context = new CodeContext();

            var e0 = Expression.Call(null, typeof(ParseTest).GetMethod("tan"), new Expression[] { Expression.Constant((double)10.3) });
            var result = CodeMethodCall(target, e0, gc);
            Assert.AreEqual(0, gc.IncludeFiles.Count(), "# include files after none should have been added");

            var e1 = Expression.Call(null, typeof(ParseTest).GetMethod("cos"), new Expression[] { Expression.Constant((double)10.3) });
            result = CodeMethodCall(target, e1, gc);
            Assert.AreEqual(1, gc.IncludeFiles.Count(), "# include files");
            Assert.AreEqual("cmath2", gc.IncludeFiles.First(), "include filename");

            var e2 = Expression.Call(null, typeof(ParseTest).GetMethod("sin"), new Expression[] { Expression.Constant((double)10.3) });
            result = CodeMethodCall(target, e2, gc);
            Assert.AreEqual(3, gc.IncludeFiles.Count(), "# include files");
            Assert.IsTrue(gc.IncludeFiles.Contains("cmath1"), "cmath1 missing");
            Assert.IsTrue(gc.IncludeFiles.Contains("cmath2"), "cmath1 missing");
            Assert.IsTrue(gc.IncludeFiles.Contains("cmath3"), "cmath1 missing");
        }
        public void TestFunctionMerge()
        {
            StringBuilder bld = new StringBuilder();
            bld.AppendLine("ParseTest sin(System.Double) => freak(double)");
            var target = new TypeHandlerReplacementCall();
            target.Parse(new StringReader(bld.ToString()));

            bld = new StringBuilder();
            bld.AppendLine("ParseTest sin(System.Double) => sin(double)");
            target.Parse(new StringReader(bld.ToString()));

            var e1 = Expression.Call(null, typeof(ParseTest).GetMethod("sin"), new Expression[] { Expression.Constant((double)10.3) });

            var gc = new GeneratedCode();
            var context = new CodeContext();

            var result = CodeMethodCall(target, e1, gc);
            Assert.AreEqual("freak((double)10.3)", result.RawValue, "sin incorrect");
        }
        public void TestStringParsing()
        {
            StringBuilder bld = new StringBuilder();
            bld.AppendLine("#<classtype Name> func(arg1 FullName type, arg2 FullName type) => c++func(cppargtype, cppargtype)");
            bld.AppendLine("ParseTest sin(System.Double) => sin(double)");
            bld.AppendLine("ParseTest f1(System.Int32, System.Int32) => f1(int, int)");
            bld.AppendLine("ParseTest f2(System.Double,System.Double) => f2(double,double)");

            var target = new TypeHandlerReplacementCall();
            target.Parse(new StringReader(bld.ToString()));

            var e1 = Expression.Call(null, typeof(ParseTest).GetMethod("sin"), new Expression[] { Expression.Constant((double)10.3) });
            var e2 = Expression.Call(null, typeof(ParseTest).GetMethod("f1"), new Expression[] { Expression.Constant((int)10), Expression.Constant((int)20) });
            var e3 = Expression.Call(null, typeof(ParseTest).GetMethod("f2"), new Expression[] { Expression.Constant((double)10.3), Expression.Constant((double)20.3) });

            var gc = new GeneratedCode();
            var context = new CodeContext();

            var result = CodeMethodCall(target, e1, gc);
            Assert.AreEqual("sin((double)10.3)", result.RawValue, "sin incorrect");

            result = CodeMethodCall(target, e2, gc);
            Assert.AreEqual("f1((int)10,(int)20)", result.RawValue, "f1 incorrect");

            result = CodeMethodCall(target, e3, gc);
            Assert.AreEqual("f2((double)10.3,(double)20.3)", result.RawValue, "f2 incorrect");
        }
        public void TestProcessConstantReference()
        {
            var p = new TypeHandlerReplacementCall();

            p.ProcessConstantReference(null, null, null);
        }