public PythonFixtureBuilder(PythonEngine engine) { if (engine == null) throw new ArgumentNullException("engine"); _engine = engine; _findTestMethods = _engine.CreateMethod<Func<List, OldClass, string>>(@"return getTestCaseNames(testCaseClass, prefix)", Params("testCaseClass", "prefix")); _isNUnitFixture = _engine.CreateMethod<Func<bool, OldClass>>( string.Format("return (obj != {0}) and (issubclass(obj, {0}))", FixtureBaseClass), Params("obj")); _createInstance = _engine.CreateMethod<Func<OldInstance, OldClass>>("return toCreate()", Params("toCreate")); }
public void StatementsToStronglyTypedDelegate() { PythonEngine engine = new PythonEngine(); List<string> parameters = new List<string>(new string[] {"age"}); Converter<int, string> converter = engine.CreateMethod<Converter<int, string>>("return str(age+1)", parameters); Assert.AreEqual("11", converter(10)); }
public PythonFixtureBuilder(PythonEngine engine) { if (engine == null) { throw new ArgumentNullException("engine"); } _engine = engine; _findTestMethods = _engine.CreateMethod <Func <List, OldClass, string> >(@"return getTestCaseNames(testCaseClass, prefix)", Params("testCaseClass", "prefix")); _isNUnitFixture = _engine.CreateMethod <Func <bool, OldClass> >( string.Format("return (obj != {0}) and (issubclass(obj, {0}))", FixtureBaseClass), Params("obj")); _createInstance = _engine.CreateMethod <Func <OldInstance, OldClass> >("return toCreate()", Params("toCreate")); }
public void StatementsToStronglyTypedDelegate() { PythonEngine engine = new PythonEngine(); List <string> parameters = new List <string>(new string[] { "age" }); Converter <int, string> converter = engine.CreateMethod <Converter <int, string> >("return str(age+1)", parameters); Assert.AreEqual("11", converter(10)); }
public static TDelegate SetupDelegate <TDelegate>(string code, IList <string> args) { try { return(interpreter.CreateMethod <TDelegate>(code, args)); } catch (Exception) { log.WarnFormat("Failed to compile delegate code:\n{0}", code); throw; } }
private Proc MakeProc(OldInstance instance, string methodName) { var nakedProc = _engine.CreateMethod <Proc <object> >(string.Format("instance.{0}()", methodName), Params("instance")); Proc testCase = () => nakedProc(instance); return(testCase); }
public void LooseDelegateAndDynamicInvoke() { PythonEngine engine = new PythonEngine(); List <string> parameters = new List <string>(new string[] { "name", "age" }); Delegate func = engine.CreateMethod <Delegate>("return ‘my name is’ + name + ‘ and my age is ‘ + str(age)", parameters); string result = (string)func.DynamicInvoke("alex", 26); Assert.AreEqual("my name is alex and my age is 25", result); }
public void StronglyTypedDelegate() { Dictionary <string, object> context = new Dictionary <string, object>(); context.Add("user", "alex"); context.Add("age", 26); PythonEngine engine = new PythonEngine(); FormatUserDetailsDelegate func = engine.CreateMethod <FormatUserDetailsDelegate>("return user + ' is ' + str(age) + ' years old'", new List <string>(context.Keys)); object result = func.DynamicInvoke(new List <object>(context.Values).ToArray()); Assert.AreEqual("alex is 26 years old", result); }
public void LooseDelegateAndDynamicInvoke() { PythonEngine engine = new PythonEngine(); List<string> parameters = new List<string>(new string[] {"name", "age"}); Delegate func = engine.CreateMethod<Delegate>("return ‘my name is’ + name + ‘ and my age is ‘ + str(age)", parameters); string result = (string) func.DynamicInvoke("alex", 26); Assert.AreEqual("my name is alex and my age is 25", result); }
public void StronglyTypedDelegate() { Dictionary<string, object> context = new Dictionary<string, object>(); context.Add("user", "alex"); context.Add("age", 26); PythonEngine engine = new PythonEngine(); FormatUserDetailsDelegate func = engine.CreateMethod<FormatUserDetailsDelegate>("return user + ' is ' + str(age) + ' years old'", new List<string>(context.Keys)); object result = func.DynamicInvoke(new List<object>(context.Values).ToArray()); Assert.AreEqual("alex is 26 years old", result); }