public void TestIntegration() { try { var some = from c in new TestClientDataContext().Companies where c.Employees.Count == 2 select c; var tf = new TransformationFramework(); tf.Integration.AllowDuplicateRules = false; tf.Integration.RegisterCSharp(o => o is IBean, o => "bean"); tf.Integration.RegisterCSharp(o => o is IBean, o => "bean2"); tf.CSharpToJS(some.Expression); } catch (Exception ex) { var ex0 = ex; Assert.AreEqual(typeof(CSharpToJSException), ex0.GetType()); Assert.IsNotNull(ex0.InnerException); var ex0_kvps = ((RelinqException)ex0).PrettyProperties; Assert.AreEqual("Integration", ex0_kvps["Type"]); Assert.AreEqual("value(Relinq.Infrastructure.Client.Beans.Bean`1[Relinq.Playground.Domain.Company]).Where(c => (c.Employees.Count = 2))", ex0_kvps["Input"]); var ex1 = ex0.InnerException; Assert.AreEqual(typeof(LinqVisitorException), ex1.GetType()); Assert.IsNotNull(ex1.InnerException); var ex1_kvps = ((RelinqException)ex1).PrettyProperties; Assert.AreEqual("value(Relinq.Infrastructure.Client.Beans.Bean`1[Relinq.Playground.Domain.Company]).Where(c => (c.Employees.Count = 2))", ex1_kvps["Root"]); Assert.AreEqual("value(Relinq.Infrastructure.Client.Beans.Bean`1[Relinq.Playground.Domain.Company])", ex1_kvps["Expression"]); Assert.AreEqual("Constant", ex1_kvps["ExpressionType"]); var ex2 = ex1.InnerException; Assert.AreEqual(typeof(CSharpToJSIntegrationException), ex2.GetType()); Assert.IsNull(ex2.InnerException); var ex2_kvps = ((RelinqException)ex2).PrettyProperties; Assert.AreEqual("Relinq.Infrastructure.Client.Beans.Bean`1[Relinq.Playground.Domain.Company]", ex2_kvps["CSharpObject"]); Assert.AreEqual("Relinq.Playground.Domain.Company", ex2_kvps["CSharpObject[0]"]); Assert.AreEqual("Relinq.Playground.Domain.Company", ex2_kvps["CSharpObject[1]"]); Assert.AreEqual("Relinq.Playground.Domain.Company", ex2_kvps["CSharpObject[2]"]); Assert.AreEqual("MultipleSuitableRules", ex2_kvps["Type"]); Assert.AreEqual("Relinq.Script.Integration.IntegrationContext", ex2_kvps["Context"]); return; } Assert.Fail("Expected exception wasn't thrown"); }
public static String Relinq(String serialized) { var asm = Assembly.Load("Relinq.Playground"); var ctxType = asm.GetType("Relinq.Playground.DataContexts.TestServerDataContext"); var ctx = Activator.CreateInstance(ctxType); var transformationFramework = new TransformationFramework(); transformationFramework.Integration.RegisterJS("ctx", ctx); var queryAtServer = transformationFramework.JSToCSharp(serialized); var resultAtServer = queryAtServer.Evaluate(); var serializedResultAtServer = JsonSerializer.Serialize(resultAtServer, queryAtServer.Type); return serializedResultAtServer; }
public void SimpleTest10() { var tf = new TransformationFramework(); tf.Integration.RegisterJS("items", new List<ItemFactory>{new ItemFactory(), new ItemFactory()}); var js = "items.Select(function(c){return {I:c.Item()}})"; var result = tf.JSToCSharp(js).Evaluate(); var ints = new List<int>(); foreach(var anon in (IEnumerable)result) ints.Add((int)anon.GetType().GetProperty("I").GetValue(anon, null)); Assert.IsTrue(ints.SequenceEqual(Enumerable.Range(1, 2))); }
public void SimpleTest8() { var tf = new TransformationFramework(); tf.Integration.RegisterJS("iec", new List<Company>()); var js = "iec.Where(function(c){return c.Name=='a'}).Select(function(c){return c.Name})"; var et = tf.JSToCSharp(js); Expression<Func<IEnumerable<Company>, IEnumerable<String>>> linq = iec => from c in iec where c.Name == "a" select c.Name; var relinq = et.Evaluate(); var native = linq.Compile()(new List<Company>()); }
public void TestStaticMember_Method() { try { IConvertible cnv = 2; var some = from c in new TestClientDataContext().Companies where cnv.GetTypeCode() == Type.GetTypeCode(c.GetType()) select c; var tf = new TransformationFramework(); tf.CSharpToJS(some.Expression); } catch (Exception ex) { var ex0 = ex; Assert.AreEqual(typeof(CSharpToJSException), ex0.GetType()); Assert.IsNotNull(ex0.InnerException); var ex0_kvps = ((RelinqException)ex0).PrettyProperties; Assert.AreEqual("StaticMember", ex0_kvps["Type"]); Assert.AreEqual("value(Relinq.Infrastructure.Client.Beans.Bean`1[Relinq.Playground.Domain.Company]).Where(c => (Convert(value(Relinq.Playground.RelinqScriptBuilderExceptionsTests+<>c__DisplayClassa).cnv.GetTypeCode()) = Convert(GetTypeCode(c.GetType()))))", ex0_kvps["Input"]); Assert.AreEqual("False", ex0_kvps["IsUnexpected"]); var ex1 = ex0.InnerException; Assert.AreEqual(typeof(ScriptBuilderException), ex1.GetType()); Assert.IsNull(ex1.InnerException); var ex1_kvps = ((RelinqException)ex1).PrettyProperties; Assert.AreEqual("StaticMember", ex1_kvps["Type"]); Assert.AreEqual("False", ex1_kvps["IsUnexpected"]); Assert.AreEqual("value(Relinq.Infrastructure.Client.Beans.Bean`1[Relinq.Playground.Domain.Company]).Where(c => (9 = Convert(GetTypeCode(c.GetType()))))", ex1_kvps["Root"]); Assert.AreEqual("GetTypeCode(c.GetType())", ex1_kvps["Expression"]); Assert.AreEqual("Call", ex1_kvps["ExpressionType"]); return; } Assert.Fail("Expected exception wasn't thrown"); }