public void TestImplicitSetup() { var model = RuntimeTypeModel.Create(); model.AutoCompile = false; var obj1 = new ShipResource { Value = new Ship { Foo = 123 } }; var obj2 = new SomeResource { Value = new SomeType { Bar = "abc" } }; Test(model, obj1, obj2, "Runtime"); model.Compile("SO9408133_TestImplicitSetup", "SO9408133_TestImplicitSetup.dll"); PEVerify.AssertValid("SO9408133_TestImplicitSetup.dll"); model.CompileInPlace(); Test(model, obj1, obj2, "CompileInPlace"); Test(model.Compile(), obj1, obj2, "Compile"); }
public void TestExplicitSetup() { var model = RuntimeTypeModel.Create(); model.AutoCompile = false; model.Add(typeof(ResourceNode <Ship>), false).AddSubType(1, typeof(ShipResource)); model.Add(typeof(ResourceNode <SomeType>), false).AddSubType(1, typeof(SomeResource)); var obj1 = new ShipResource { Value = new Ship { Foo = 123 } }; var obj2 = new SomeResource { Value = new SomeType { Bar = "abc" } }; Test(model, obj1, obj2, "Runtime"); model.Compile("SO9408133_TestExplicitSetup", "SO9408133_TestExplicitSetup.dll"); PEVerify.AssertValid("SO9408133_TestExplicitSetup.dll"); model.CompileInPlace(); Test(model, obj1, obj2, "CompileInPlace"); Test(model.Compile(), obj1, obj2, "Compile"); }
private void Test(TypeModel model, ShipResource obj1, SomeResource obj2, string caption) { try { var clone1 = (ShipResource)model.DeepClone(obj1); var clone2 = (SomeResource)model.DeepClone(obj2); Assert.Equal(obj1.Value.Foo, clone1.Value.Foo); //, caption + ":Foo"); Assert.Equal(obj2.Value.Bar, clone2.Value.Bar); //, caption + ":Bar"); } catch (Exception ex) { throw new Exception(caption + ":" + ex.Message, ex); } }