private static void AssertTransformation <TResult>( Expression <Func <IQueryable <MyClass1>, TResult> > input, Expression <Func <IQueryable <MyClass1>, TResult> > output) { var myClass1KeyParameter = Expression.Parameter(typeof(MyClass1), "m1"); var myClass1KeyDescriptor = new PrimaryKeyDescriptor( typeof(MyClass1), Expression.Lambda( Expression.MakeMemberAccess( myClass1KeyParameter, typeof(MyClass1).GetRuntimeProperty(nameof(MyClass1.Id))), myClass1KeyParameter)); var myClass2KeyParameter = Expression.Parameter(typeof(MyClass2), "m2"); var myClass2KeyDescriptor = new PrimaryKeyDescriptor( typeof(MyClass2), Expression.Lambda( Expression.MakeMemberAccess( myClass2KeyParameter, typeof(MyClass2).GetRuntimeProperty(nameof(MyClass2.Id))), myClass2KeyParameter)); var myClass1NavigationDescriptor = new NavigationDescriptor( typeof(MyClass1), typeof(MyClass1).GetRuntimeProperty(nameof(MyClass1.Nav1)), Expression.Lambda( Expression.MakeMemberAccess( myClass1KeyParameter, typeof(MyClass1).GetRuntimeProperty(nameof(MyClass1.Nav1Id))), myClass1KeyParameter), myClass2KeyDescriptor.KeySelector, false, Expression.Default(typeof(IQueryable <MyClass2>))); var visitor = new KeyEqualityRewritingExpressionVisitor( new DescriptorSet( primaryKeyDescriptors: new[] { myClass1KeyDescriptor, myClass2KeyDescriptor, }, navigationDescriptors: new[] { myClass1NavigationDescriptor, })); var result = visitor.Visit(input.Body); var inputHash = ExpressionEqualityComparer.Instance.GetHashCode(result); var outputHash = ExpressionEqualityComparer.Instance.GetHashCode(output.Body); Assert.AreEqual(inputHash, outputHash, "Output expression trees do not match"); }
private static void AssertTransformation <TResult>( Expression <Func <IQueryable <MyClass1>, TResult> > input, Expression <Func <IQueryable <MyClass1>, TResult> > output) { var myClass1KeyParameter = Expression.Parameter(typeof(MyClass1), "m1"); var myClass1KeyDescriptor = new PrimaryKeyDescriptor { TargetType = typeof(MyClass1), KeySelector = Expression.Lambda( Expression.MakeMemberAccess( myClass1KeyParameter, typeof(MyClass1).GetRuntimeProperty(nameof(MyClass1.Id))), myClass1KeyParameter) }; var myClass2KeyParameter = Expression.Parameter(typeof(MyClass2), "m2"); var myClass2KeyDescriptor = new PrimaryKeyDescriptor { TargetType = typeof(MyClass2), KeySelector = Expression.Lambda( Expression.MakeMemberAccess( myClass2KeyParameter, typeof(MyClass2).GetRuntimeProperty(nameof(MyClass2.Id))), myClass2KeyParameter) }; var myClass1NavigationDescriptor = new NavigationDescriptor { Type = typeof(MyClass1), Member = typeof(MyClass1).GetRuntimeProperty(nameof(MyClass1.Nav1)), OuterKeySelector = Expression.Lambda( Expression.MakeMemberAccess( myClass1KeyParameter, typeof(MyClass1).GetRuntimeProperty(nameof(MyClass1.Nav1Id))), myClass1KeyParameter), InnerKeySelector = myClass2KeyDescriptor.KeySelector, }; var visitor = new KeyEqualityRewritingExpressionVisitor( primaryKeyDescriptors: new[] { myClass1KeyDescriptor, myClass2KeyDescriptor, }, navigationDescriptors: new[] { myClass1NavigationDescriptor, }); var result = visitor.Visit(input.Body); var hasher = new HashingExpressionVisitor(); hasher.Visit(result); var inputHash = hasher.HashCode; hasher.Reset(); hasher.Visit(output.Body); var outputHash = hasher.HashCode; Assert.AreEqual(inputHash, outputHash, "Output expression trees do not match"); }