public void CanCompileEnumsAsPassthru() { var model = BuildModel(true); model.Compile("AllTheEnumsPassThru", "AllTheEnumsPassThru.dll"); PEVerify.Verify("AllTheEnumsPassThru.dll"); }
public void CanCompile() { var model = CreateModel(); model.Compile("PEVerifyPackedArrays", "PEVerifyPackedArrays.dll"); PEVerify.Verify("PEVerifyPackedArrays.dll"); }
public void CanCompileEnumsAsMapped() { var model = BuildModel(false); model.Compile("AllTheEnumsMapped", "AllTheEnumsMapped.dll"); PEVerify.Verify("AllTheEnumsMapped.dll"); }
public void TestTypeWithNullablePropsComplex() { var model = TypeModel.Create(); var obj = new TypeWithNullsComplex() { First = new Foo(123) }; var clone1 = model.DeepClone(obj); model.CompileInPlace(); var clone2 = model.DeepClone(obj); TypeModel compiled = model.Compile("TestTypeWithNullablePropsComplex", "TestTypeWithNullablePropsComplex.dll"); PEVerify.Verify("TestTypeWithNullablePropsComplex.dll"); var clone3 = compiled.DeepClone(obj); Assert.AreEqual(123, clone1.First.Value.Value); Assert.AreEqual(null, clone1.Second); Assert.AreEqual(123, clone2.First.Value.Value); Assert.AreEqual(null, clone2.Second); Assert.AreEqual(123, clone3.First.Value.Value); Assert.AreEqual(null, clone3.Second); }
public void VerifyPointDirect() { var model = BuildModel(); model.Compile("PointDirect", "PointDirect.dll"); PEVerify.Verify("PointDirect.dll", 1); // expect failure due to field access }
public void TestTypeWithNullableProps() { var model = TypeModel.Create(); TypeWithNulls obj = new TypeWithNulls { First = 123, Second = 456.789M }; var clone1 = (TypeWithNulls)model.DeepClone(obj); model.CompileInPlace(); var clone2 = (TypeWithNulls)model.DeepClone(obj); TypeModel compiled = model.Compile("TestTypeWithNullableProps", "TestTypeWithNullableProps.dll"); PEVerify.Verify("TestTypeWithNullableProps.dll"); var clone3 = (TypeWithNulls)compiled.DeepClone(obj); Assert.AreEqual(123, clone1.First); Assert.AreEqual(456.789, clone1.Second); Assert.AreEqual(123, clone2.First); Assert.AreEqual(456.789, clone2.Second); Assert.AreEqual(123, clone3.First); Assert.AreEqual(456.789, clone3.Second); }
public void TypeWithIDictionaryTest() { var orig = new TypeWithIDictionary { Data = new Dictionary <string, decimal> { { "abc", 123.45M } } }; var model = TypeModel.Create(); var clone = (TypeWithIDictionary)model.DeepClone(orig); Assert.Equal(1, clone.Data.Count); Assert.Equal(123.45M, clone.Data["abc"]); //, "Runtime"); model.Compile("TypeWithIDictionary", "TypeWithIDictionary.dll"); PEVerify.Verify("TypeWithIDictionary.dll"); model.CompileInPlace(); clone = (TypeWithIDictionary)model.DeepClone(orig); Assert.Equal(1, clone.Data.Count); Assert.Equal(123.45M, clone.Data["abc"]); //, "Runtime"); clone = (TypeWithIDictionary)model.Compile().DeepClone(orig); Assert.Equal(1, clone.Data.Count); Assert.Equal(123.45M, clone.Data["abc"]); //, "Runtime"); }
public static void TestModel(RuntimeTypeModel model, object value, string hex) { byte[] raw; using (MemoryStream ms = new MemoryStream()) { model.Serialize(ms, value); raw = ms.ToArray(); } Assert.Equal(hex, GetHex(raw)); model.CompileInPlace(); using (MemoryStream ms = new MemoryStream()) { model.Serialize(ms, value); raw = ms.ToArray(); } Assert.Equal(hex, GetHex(raw)); TypeModel compiled = model.Compile("compiled", "compiled.dll"); PEVerify.Verify("compiled.dll"); using (MemoryStream ms = new MemoryStream()) { compiled.Serialize(ms, value); raw = ms.ToArray(); } Assert.Equal(hex, GetHex(raw)); }
public void TestRoundTripRandomCompile() { var model = BuildModel().Compile("TestRoundTripRandomCompile", "TestRoundTripRandomCompile.dll"); PEVerify.Verify("TestRoundTripRandomCompile.dll"); TestGuids(model, 1000); }
public void VerifyPointWithSurrogate() { var model = BuildModelWithSurrogate(); model.Compile("PointWithSurrogate", "PointWithSurrogate.dll"); PEVerify.Verify("PointWithSurrogate.dll"); }
public void RemappingCanCompile() { var model = CreateRemappingModel(); model.Compile("CreateRemappingModel", "CreateRemappingModel.dll"); PEVerify.Verify("CreateRemappingModel.dll"); }
public void TestEnumTopLevel_CompileFull() { var model = CreateEnumModel(); var compiled = model.Compile("TestEnumTopLevel_CompileFull", "TestEnumTopLevel_CompileFull.dll"); PEVerify.Verify("TestEnumTopLevel_CompileFull.dll", deleteOnSuccess: false); TestEnumModel(compiled); }
public void CanCompileModel() { var model = BuildModel(); model.CompileInPlace(); model.Compile("Callbacks", "Callbacks.dll"); PEVerify.Verify("Callbacks.dll"); }
public void Execute() { WriteHeading(".NET version"); #if !COREFX Console.WriteLine(Environment.Version); #endif RuntimeTypeModel orderModel = TypeModel.Create(); orderModel.Add(typeof(OrderHeader), true); orderModel.Add(typeof(OrderDetail), true); PurgeWithGusto("OrderSerializer.dll"); orderModel.Compile("OrderSerializer", "OrderSerializer.dll"); PEVerify.Verify("OrderSerializer.dll"); RuntimeTypeModel model = BuildMeta(); Customer cust1 = new Customer(); CustomerStruct cust2 = new CustomerStruct { Id = cust1.Id = 123, Name = cust1.Name = "Fred" }; #if !FX11 cust1.HasValue = cust2.HasValue = true; cust1.HowMuch = cust2.HowMuch = 0.123; #endif WriteCustomer(model, "Runtime - class", cust1); WriteCustomer(model, "Runtime - struct", cust2); #if FEAT_COMPILER && !FX11 model.CompileInPlace(); WriteCustomer(model, "InPlace- class", cust1); WriteCustomer(model, "InPlace - struct", cust2); #endif #if FEAT_COMPILER #if !COREFX PurgeWithGusto("CustomerModel.dll"); TypeModel compiled = model.Compile("CustomerModel", "CustomerModel.dll"); PEVerify.Verify("CustomerModel.dll"); WriteCustomer(compiled, "Compiled - class", cust2); WriteCustomer(compiled, "Compiled - struct", cust2); #endif /* * CustomerModel serializer = new CustomerModel(); * using (MemoryStream ms = new MemoryStream()) * { * Customer cust = new Customer(); * cust.Id = 123; * cust.Name = "Fred"; * serializer.Serialize(ms, cust); * ms.Position = 0; * Customer clone = (Customer)serializer.Deserialize(ms, null, typeof(Customer)); * Console.WriteLine(clone.Id); * Console.WriteLine(clone.Name); * } */ #endif }
public void CanCompileModel() { var model = BuildModel(); model.CompileInPlace(); var gid = Guid.NewGuid().ToString("n"); model.Compile("Callbacks", "Callbacks-" + gid + ".dll"); PEVerify.Verify("Callbacks-" + gid + ".dll"); }
public void CanCompileModel(bool useCtor) { var model = BuildModel(useCtor); model.CompileInPlace(); var path = useCtor ? "Callbacks_Ctor.dll" : "Callbacks_NoCtor.dll"; model.Compile("Callbacks", path); PEVerify.Verify(path); }
public void TestHazImplicitMap_CompileDll() { var model = RuntimeTypeModel.Create(); model.AutoCompile = false; model.Add(typeof(HazImplicitMap), true); var compiled = model.Compile("TestHazImplicitMap_CompileDll", "TestHazImplicitMap_CompileDll.dll"); PEVerify.Verify("TestHazImplicitMap_CompileDll.dll"); TestHazImplicitMap(compiled); }
public void VerifyPointDirect() { try { var model = BuildModel(); model.Compile("PointDirect", "PointDirect.dll"); PEVerify.Verify("PointDirect.dll", 1); // expect failure due to field access } catch (InvalidOperationException ex) { Assert.Equal("Non-public member cannot be used with full dll compilation: ProtoBuf.unittest.Attribs.PointStructTests+Point.x", ex.Message); } }
private static void Compile <T>([CallerMemberName] string name = null, bool deleteOnSuccess = true) { var model = TypeModel.Create(); model.Add(typeof(T), true); var path = Path.ChangeExtension(name, "dll"); if (File.Exists(path)) { File.Delete(path); } model.Compile(name, path); PEVerify.Verify(path, 0, deleteOnSuccess); }
public void PEVerifyArraysAndLists() { var model = RuntimeTypeModel.Create(); model.Add(typeof(NastyType), true) //.Add(1, "Blobs") //.Add(2, "Blob") .Add(3, "BasicArray") //.Add(4, "BasicList") ; model.CompileInPlace(); model.Compile("PEVerifyArraysAndLists", "PEVerifyArraysAndLists.dll"); PEVerify.Verify("PEVerifyArraysAndLists.dll"); }
public void EmitModelWithEverything() { var model = RuntimeTypeModel.Create(); MetaType meta = model.Add(typeof(TypeWithLists), false); meta.Add(1, "ListString"); meta.Add(2, "ListInt32"); meta.Add(3, "IListStringTyped"); meta.Add(4, "IListInt32Typed"); model.CompileInPlace(); model.Compile("EmitModelWithEverything", "EmitModelWithEverything.dll"); PEVerify.Verify("EmitModelWithEverything.dll"); }
public void EmitModelWithEverything() { var model = TypeModel.Create(); MetaType meta = model.Add(typeof(TypeWithLists), false); meta.Add(1, "ListString"); meta.Add(2, "ListInt32"); meta.Add(3, "IListStringTyped"); meta.Add(4, "IListInt32Typed"); meta.Add(5, "ArrayListString", typeof(string), null); meta.Add(6, "ArrayListInt32", typeof(int), null); meta.Add(7, "IListStringUntyped", typeof(string), null); meta.Add(8, "IListInt32Untyped", typeof(int), null); model.CompileInPlace(); model.Compile("EmitModelWithEverything", "EmitModelWithEverything.dll"); PEVerify.Verify("EmitModelWithEverything.dll"); }
public void PEVerifyArraysAndLists() { var model = RuntimeTypeModel.Create(); model.Add(typeof(NastyType), true) .Add(1, nameof(NastyType.Blobs)) .Add(2, nameof(NastyType.Blob)) .Add(3, nameof(NastyType.BasicArray)) .Add(4, nameof(NastyType.BasicList)) .Add(5, nameof(NastyType.BlobsField)) .Add(6, nameof(NastyType.BlobField)) .Add(7, nameof(NastyType.BasicArrayField)) .Add(8, nameof(NastyType.BasicListField)) ; model.CompileInPlace(); model.Compile("PEVerifyArraysAndLists", "PEVerifyArraysAndLists.dll"); PEVerify.Verify("PEVerifyArraysAndLists.dll"); }
public void TypeWithPairTest() { var orig = new TypeWithPair { Pair = new KeyValuePair<string, decimal>("abc", 123.45M) }; var model = TypeModel.Create(); var clone = (TypeWithPair)model.DeepClone(orig); Assert.AreEqual("abc", clone.Pair.Key, "Runtime"); Assert.AreEqual(123.45M, clone.Pair.Value, "Runtime"); model.Compile("TypeWithPairTest", "TypeWithPairTest.dll"); PEVerify.Verify("TypeWithPairTest.dll"); model.CompileInPlace(); clone = (TypeWithPair)model.DeepClone(orig); Assert.AreEqual("abc", clone.Pair.Key, "CompileInPlace"); Assert.AreEqual(123.45M, clone.Pair.Value, "CompileInPlace"); clone = (TypeWithPair)model.Compile().DeepClone(orig); Assert.AreEqual("abc", clone.Pair.Key, "Compile"); Assert.AreEqual(123.45M, clone.Pair.Value, "Compile"); }
public void ShouldWorkWithAutoLoadDisabledCompile() { var orig = new TypeWithDictionary { Data = new Dictionary <string, decimal> { { "abc", 123.45M } } }; var model = TypeModel.Create(); model.AutoAddMissingTypes = false; model.Add(typeof(TypeWithDictionary), true); var compiled = model.Compile("MapSerializer", "ShouldWorkWithAutoLoadDisabledCompile.dll"); PEVerify.Verify("ShouldWorkWithAutoLoadDisabledCompile.dll"); var clone = (TypeWithDictionary)model.Compile().DeepClone(orig); Assert.Single(clone.Data); Assert.Equal(123.45M, clone.Data["abc"]); }
public void TestCanDeserialierAllFromEmptyStream_Generic() { var model = CreateModel(); Assert.IsType <OuterRef>(model.Deserialize <OuterRef>(Stream.Null)); Assert.IsType <OuterVal>(model.Deserialize <OuterVal>(Stream.Null)); Assert.IsType <InnerRef>(model.Deserialize <InnerRef>(Stream.Null)); Assert.IsType <InnerVal>(model.Deserialize <InnerVal>(Stream.Null)); model.CompileInPlace(); Assert.IsType <OuterRef>(model.Deserialize <OuterRef>(Stream.Null)); Assert.IsType <OuterVal>(model.Deserialize <OuterVal>(Stream.Null)); Assert.IsType <InnerRef>(model.Deserialize <InnerRef>(Stream.Null)); Assert.IsType <InnerVal>(model.Deserialize <InnerVal>(Stream.Null)); var compiled = model.Compile("SubItems", "SubItems.dll"); PEVerify.Verify("SubItems.dll"); Assert.IsType <OuterRef>(compiled.Deserialize <OuterRef>(Stream.Null)); Assert.IsType <OuterVal>(compiled.Deserialize <OuterVal>(Stream.Null)); Assert.IsType <InnerRef>(compiled.Deserialize <InnerRef>(Stream.Null)); Assert.IsType <InnerVal>(compiled.Deserialize <InnerVal>(Stream.Null)); }
public void TestCanDeserialierAllFromEmptyStream() { var model = CreateModel(); Assert.IsInstanceOfType(typeof(OuterRef), model.Deserialize(Stream.Null, null, typeof(OuterRef))); Assert.IsInstanceOfType(typeof(OuterVal), model.Deserialize(Stream.Null, null, typeof(OuterVal))); Assert.IsInstanceOfType(typeof(InnerRef), model.Deserialize(Stream.Null, null, typeof(InnerRef))); Assert.IsInstanceOfType(typeof(InnerVal), model.Deserialize(Stream.Null, null, typeof(InnerVal))); model.CompileInPlace(); Assert.IsInstanceOfType(typeof(OuterRef), model.Deserialize(Stream.Null, null, typeof(OuterRef))); Assert.IsInstanceOfType(typeof(OuterVal), model.Deserialize(Stream.Null, null, typeof(OuterVal))); Assert.IsInstanceOfType(typeof(InnerRef), model.Deserialize(Stream.Null, null, typeof(InnerRef))); Assert.IsInstanceOfType(typeof(InnerVal), model.Deserialize(Stream.Null, null, typeof(InnerVal))); var compiled = model.Compile("SubItems", "SubItems.dll"); PEVerify.Verify("SubItems.dll"); Assert.IsInstanceOfType(typeof(OuterRef), compiled.Deserialize(Stream.Null, null, typeof(OuterRef))); Assert.IsInstanceOfType(typeof(OuterVal), compiled.Deserialize(Stream.Null, null, typeof(OuterVal))); Assert.IsInstanceOfType(typeof(InnerRef), compiled.Deserialize(Stream.Null, null, typeof(InnerRef))); Assert.IsInstanceOfType(typeof(InnerVal), compiled.Deserialize(Stream.Null, null, typeof(InnerVal))); }
public void TestCanDeserialierAllFromEmptyStream() { var model = CreateModel(); #pragma warning disable CS0618 Assert.IsType <OuterRef>(model.Deserialize(Stream.Null, null, typeof(OuterRef))); Assert.IsType <OuterVal>(model.Deserialize(Stream.Null, null, typeof(OuterVal))); Assert.IsType <InnerRef>(model.Deserialize(Stream.Null, null, typeof(InnerRef))); Assert.IsType <InnerVal>(model.Deserialize(Stream.Null, null, typeof(InnerVal))); model.CompileInPlace(); Assert.IsType <OuterRef>(model.Deserialize(Stream.Null, null, typeof(OuterRef))); Assert.IsType <OuterVal>(model.Deserialize(Stream.Null, null, typeof(OuterVal))); Assert.IsType <InnerRef>(model.Deserialize(Stream.Null, null, typeof(InnerRef))); Assert.IsType <InnerVal>(model.Deserialize(Stream.Null, null, typeof(InnerVal))); var compiled = model.Compile("SubItems", "SubItems.dll"); PEVerify.Verify("SubItems.dll"); Assert.IsType <OuterRef>(compiled.Deserialize(Stream.Null, null, typeof(OuterRef))); Assert.IsType <OuterVal>(compiled.Deserialize(Stream.Null, null, typeof(OuterVal))); Assert.IsType <InnerRef>(compiled.Deserialize(Stream.Null, null, typeof(InnerRef))); Assert.IsType <InnerVal>(compiled.Deserialize(Stream.Null, null, typeof(InnerVal))); #pragma warning restore CS0618 }
public void CanCompileModelFully() { CreateModel().Compile("InheritanceTests", "InheritanceTests.dll"); PEVerify.Verify("InheritanceTests.dll", 0, false); }
public void TestDateTimeCanCompileFully() { _ = CreateModel().Compile("TestDateTimeCanCompileFully", "TestDateTimeCanCompileFully.dll"); PEVerify.Verify("TestDateTimeCanCompileFully.dll"); }