public void StructuralTypeSubstitutionExpressionVisitor_RecordToAnonymous_ThrowsInvalidOperation() { var type1 = RuntimeCompiler.CreateRecordType(new Dictionary <string, Type> { { "Foo", typeof(int) } }, valueEquality: true); var type2 = RuntimeCompiler.CreateAnonymousType(new Dictionary <string, Type> { { "Foo", typeof(int) } }); var expr = Expression.Constant(Activator.CreateInstance(type1)); var visitor = new StructuralTypeSubstitutionExpressionVisitor(new Dictionary <Type, Type> { { type1, type2 } }); Assert.ThrowsException <InvalidOperationException>(() => visitor.Visit(expr)); }
public void StructuralTypeSubstitutionExpressionVisitor_NullValue_Success() { var type1 = RuntimeCompiler.CreateAnonymousType(new Dictionary <string, Type> { { "Foo", typeof(int) } }); var type2 = RuntimeCompiler.CreateAnonymousType(new Dictionary <string, Type> { { "Foo", typeof(int) } }); var expr = Expression.Constant(null, type1); var visitor = new StructuralTypeSubstitutionExpressionVisitor(new Dictionary <Type, Type> { { type1, type2 } }); var result = visitor.Visit(expr); Assert.AreEqual(type2, result.Type); }
public void StructuralTypeSubstitutionExpressionVisitor_Record_Success() { var type1 = RuntimeCompiler.CreateRecordType(new Dictionary <string, Type> { { "Foo", typeof(int) } }, valueEquality: true); var type2 = RuntimeCompiler.CreateRecordType(new Dictionary <string, Type> { { "Foo", typeof(int) } }, valueEquality: true); var expr = Expression.Constant(Activator.CreateInstance(type1)); var visitor = new StructuralTypeSubstitutionExpressionVisitor(new Dictionary <Type, Type> { { type1, type2 } }); var result = visitor.Visit(expr); Assert.AreEqual(type2, result.Type); }