AssertValid() public static method

public static AssertValid ( string path ) : bool
path string
return bool
Example #1
0
        public void TestWithSupportForNullsCompilesCleanly()
        {
            var model = GetModelWithSupportForNulls();

            model.Compile("Issue243_b", "Issue243_b.dll");
            PEVerify.AssertValid("Issue243_b.dll");
        }
Example #2
0
        public void VerifyCompile()
        {
            var model = GetModel();

            model.Compile("SO16838287", "SO16838287.dll");
            PEVerify.AssertValid("SO16838287.dll");
        }
Example #3
0
        public void ShouldSerializeArrayOfEnums()
        {
            var model = RuntimeTypeModel.Create();

            model.AutoCompile = false;
            model.Add(typeof(E));
            TestArray(model);
            model.Compile("ShouldSerializeArrayOfEnums", "ShouldSerializeArrayOfEnums.dll");
            PEVerify.AssertValid("ShouldSerializeArrayOfEnums.dll");
            model.CompileInPlace();
            TestArray(model);
            TestArray(model.Compile());

            var schema = model.GetSchema(typeof(E[]));

            Assert.Equal(@"syntax = ""proto3"";
package Examples.Issues;

message Array_E {
   repeated E items = 1;
}
enum E {
   V0 = 0;
   V1 = 1;
   V2 = 2;
}
", schema);
        }
Example #4
0
        public void TestNotNull()
        {
            var model = RuntimeTypeModel.Create();

            model.AutoCompile = false;

            TypeWithNulls twn = new TypeWithNulls {
                Foo = 150
            },
                          clone = model.DeepClone(twn);

            Assert.NotNull(twn.Foo);
            Program.CheckBytes(twn, model, "08-96-01");
            Assert.NotNull(clone.Foo);
            Program.CheckBytes(clone, model, "08-96-01");

            var compiled = model.Compile("TestNotNull", "TestNotNull.dll");

            PEVerify.AssertValid("TestNotNull.dll");
            clone = compiled.DeepClone(twn);
            Program.CheckBytes(twn, compiled, "08-96-01");
            Program.CheckBytes(clone, compiled, "08-96-01");

            model.CompileInPlace();
            clone = model.DeepClone(twn);
            Program.CheckBytes(twn, model, "08-96-01");
            Program.CheckBytes(clone, model, "08-96-01");

            compiled = model.Compile();
            clone    = compiled.DeepClone(twn);
            Program.CheckBytes(twn, compiled, "08-96-01");
            Program.CheckBytes(clone, compiled, "08-96-01");
        }
Example #5
0
        public void CompilesCleanly()
        {
            var model = GetModel();

            model.Compile("Issue243_a", "Issue243_a.dll");
            PEVerify.AssertValid("Issue243_a.dll");
        }
        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");
        }
Example #7
0
        private static void DateTimeKind_SerializedElectively(bool includeDateTimeKind, string name)
        {
            var model = RuntimeTypeModel.Create();

            model.AutoCompile         = false;
            model.IncludeDateTimeKind = includeDateTimeKind;
            var original = HazTime.Create();

            var clone = (HazTime)model.DeepClone(original);

            CompareDates(original, clone, includeDateTimeKind, "runtime");

            model.CompileInPlace();
            clone = (HazTime)model.DeepClone(original);
            CompareDates(original, clone, includeDateTimeKind, "CompileInPlace");

            TypeModel compiled = model.Compile();

            Assert.Equal(includeDateTimeKind, SerializeDateTimeKind(compiled));

            clone = (HazTime)compiled.DeepClone(original);
            CompareDates(original, clone, includeDateTimeKind, "Compile");

            compiled = model.Compile(name, name + ".dll");
            Assert.Equal(includeDateTimeKind, SerializeDateTimeKind(compiled));
            clone = (HazTime)compiled.DeepClone(original);
            CompareDates(original, clone, includeDateTimeKind, "Compile-dll");
            PEVerify.AssertValid(name + ".dll");
        }
        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");
        }
Example #9
0
        public void ShouldSerializeListOfEnums()
        {
            var model = RuntimeTypeModel.Create();

            model.AutoCompile = false;
            model.Add(typeof(E));
            TestList(model);
            model.Compile("ShouldSerializeListOfEnums", "ShouldSerializeListOfEnums.dll");
            PEVerify.AssertValid("ShouldSerializeListOfEnums.dll");
            model.CompileInPlace();
            TestList(model);
            TestList(model.Compile());

            var schema = model.GetSchema(typeof(List <E>));

            Assert.Equal(@"syntax = ""proto3"";
package Examples.Issues;

enum E {
   V0 = 0;
   V1 = 1;
   V2 = 2;
}
message List_E {
   repeated E items = 1;
}
", schema, ignoreLineEndingDifferences: true);
        }
Example #10
0
        public void Execute()
        {
            var model = TypeModel.Create();

            model.AutoCompile = false;
            // message hierarchy
            {
                var messages = model.Add(typeof(Message), true);
                messages.AddSubType(1, typeof(SomeMessage));
                model[typeof(SomeMessage)].UseConstructor = false;
            }

            // events hierarchy
            {
                var events = model.Add(typeof(Event), true);
                events.AddSubType(1, typeof(SomeEvent));
                model[typeof(SomeEvent)].Add("SomeField").UseConstructor = false;
            }

            // descriptor
            var eventDescriptorModel = model.Add(typeof(Descriptor), true);

            eventDescriptorModel.UseConstructor = false;

            RunTest(model, "Runtime");

            model.CompileInPlace();
            RunTest(model, "CompileInPlace");

            RunTest(model.Compile(), "Compile");

            model.Compile("SO7719000", "SO7719000.dll");
            PEVerify.AssertValid("SO7719000.dll");
        }
Example #11
0
        public void VerifyIL()
        {
            var model = RuntimeTypeModel.Create();

            model.Add(typeof(Query));
            model.Compile("ComplexGenericTest", "ComplexGenericTest.dll");
            PEVerify.AssertValid("ComplexGenericTest.dll");
        }
Example #12
0
        public void GenerateModel()
        {
            var model = RuntimeTypeModel.Create();

            model.Add(typeof(DatabaseCompat), true);
            model.Compile("CompatDbBuffers", "CompatDbBuffers.dll");
            Log?.WriteLine(Path.Combine(Environment.CurrentDirectory, "CompatDbBuffers.dll"));
            PEVerify.AssertValid("CompatDbBuffers.dll");
        }
Example #13
0
        public void SanityCheckListWrapper()
        {
            var model = TypeModel.Create();

            model.Add(typeof(ListWrapper), true);

            model.Compile("SanityCheckListWrapper", "SanityCheckListWrapper.dll");
            PEVerify.AssertValid("SanityCheckListWrapper.dll");
        }
Example #14
0
 public void VerifyCompile()
 {
     Assert.Throws <NotSupportedException>(() =>
     {
         var model = GetModel();
         model.Compile("SO16838287", "SO16838287.dll");
         PEVerify.AssertValid("SO16838287.dll");
     });
 }
Example #15
0
        public void ExecuteNet45WithInternalTypes()
        {
            PreCompileContext ctx;

            Assert.IsTrue(CommandLineAttribute.TryParse(new[] { @"..\..\..\Net45Dto\bin\release\Net45Dto.dll"
                                                                , @"-o:..\..\..\Net45Dto\bin\release\Net45Serializer.dll", "-t:MySerializer" }, out ctx), "TryParse");
            Assert.IsTrue(ctx.SanityCheck(), "SanityCheck");
            Assert.IsTrue(ctx.Execute(), "Execute");
            PEVerify.AssertValid(@"..\..\..\Net45Dto\bin\release\Net45Serializer.dll");
        }
Example #16
0
        public void Execute()
        {
            var model = GetModel();

            Execute(model, "Runtime");
            model.CompileInPlace();
            Execute(model, "CompileInPlace");
            Execute(model.Compile(), "Compile");
            model.Compile("SO11705351", "SO11705351.dll");
            PEVerify.AssertValid("SO11705351.dll");
        }
 public void ShouldSerializeArrayOfEnums()
 {
     var model = TypeModel.Create();
     model.AutoCompile = false;
     TestArray(model);
     model.Compile("ShouldSerializeArrayOfEnums", "ShouldSerializeArrayOfEnums.dll");
     PEVerify.AssertValid("ShouldSerializeArrayOfEnums.dll");
     model.CompileInPlace();
     TestArray(model);
     TestArray(model.Compile());
 }
 public void ShouldSerializeIndividualEnum()
 {
     var model = TypeModel.Create();
     model.AutoCompile = false;
     TestIndividual(model);
     model.Compile("ShouldSerializeIndividualEnum", "ShouldSerializeIndividualEnum.dll");
     PEVerify.AssertValid("ShouldSerializeIndividualEnum.dll");
     model.CompileInPlace();
     TestIndividual(model);
     TestIndividual(model.Compile());
 }
 public void ShouldSerializeEnumArrayMember()
 {
     var model = TypeModel.Create();
     model.AutoCompile = false;
     TestMember(model);
     model.Compile("ShouldSerializeEnumArrayMember", "ShouldSerializeEnumArrayMember.dll");
     PEVerify.AssertValid("ShouldSerializeEnumArrayMember.dll");
     model.CompileInPlace();
     TestMember(model);
     TestMember(model.Compile());
 }
 void ExecuteAllModes(RuntimeTypeModel model, [CallerMemberName] string caller = null, bool standalone = false)
 {
     Execute(model, "Runtime");
     Execute(model, "CompileInPlace");
     if (standalone)
     {
         Execute(model.Compile(), "Compile");
         model.Compile(caller, caller + ".dll");
         PEVerify.AssertValid(caller + ".dll");
     }
 }
Example #21
0
        public void ShouldSerializeValueTypeSubTypes()
        {
            var model = RuntimeTypeModel.Create();

            ConfigureTypeModel(model);
            model.Compile("ShouldSerializeValueTypeSubTypes", "ShouldSerializeValueTypeSubTypes.dll");
            PEVerify.AssertValid("ShouldSerializeValueTypeSubTypes.dll");
            TestValueType(model);
            // This bug only occured in compiled type models
            TestValueType(model.Compile());
        }
Example #22
0
        public void SerializeImmutable()
        {
            var model = RuntimeTypeModel.Create();

            model.AutoCompile = false;
            ExecuteImmutable(model, "Runtime");
            model.CompileInPlace();
            ExecuteImmutable(model, "CompileInPlace");
            ExecuteImmutable(model.Compile(), "Compile");
            model.Compile("Issue354", "SerializeImmutable.dll");
            PEVerify.AssertValid("SerializeImmutable.dll");
        }
Example #23
0
        public void Test_WithLengthPrefix([Values(false, true)] bool comp)
        {
            var model = TypeModel.Create(false, comp ? ProtoCompatibilitySettingsValue.FullCompatibility : ProtoCompatibilitySettingsValue.Incompatible);

            model.AutoCompile = false;
            Execute_WithLengthPrefix(model, "Runtime");
            model.CompileInPlace();
            Execute_WithLengthPrefix(model, "CompileInPlace");
            Execute_WithLengthPrefix(model.Compile(), "Compile");
            model.Compile("SO16803233b", "SO16803233b.dll");
            PEVerify.AssertValid("SO16803233b.dll");
        }
Example #24
0
        public void ShouldSerializeIndividualEnum()
        {
            var model = TypeModel.Create(false, ProtoCompatibilitySettingsValue.FullCompatibility);

            model.AutoCompile = false;
            TestIndividual(model);
            model.Compile("ShouldSerializeIndividualEnum", "ShouldSerializeIndividualEnum.dll");
            PEVerify.AssertValid("ShouldSerializeIndividualEnum.dll");
            model.CompileInPlace();
            TestIndividual(model);
            TestIndividual(model.Compile());
        }
Example #25
0
        public void ShouldSerializeArrayOfEnums()
        {
            var model = TypeModel.Create(false, ProtoCompatibilitySettingsValue.FullCompatibility);

            model.AutoCompile = false;
            TestArray(model);
            model.Compile("ShouldSerializeArrayOfEnums", "ShouldSerializeArrayOfEnums.dll");
            PEVerify.AssertValid("ShouldSerializeArrayOfEnums.dll");
            model.CompileInPlace();
            TestArray(model);
            TestArray(model.Compile());
        }
Example #26
0
        public void Test_WithLengthPrefix()
        {
            var model = RuntimeTypeModel.Create();

            model.AutoCompile = false;
            Execute_WithLengthPrefix(model, "Runtime");
            model.CompileInPlace();
            Execute_WithLengthPrefix(model, "CompileInPlace");
            Execute_WithLengthPrefix(model.Compile(), "Compile");
            model.Compile("SO16803233b", "SO16803233b.dll");
            PEVerify.AssertValid("SO16803233b.dll");
        }
Example #27
0
        public void Test_Vanilla()
        {
            var model = RuntimeTypeModel.Create();

            model.AutoCompile = false;
            Execute_Vanilla(model, "Runtime");
            model.CompileInPlace();
            Execute_Vanilla(model, "CompileInPlace");
            Execute_Vanilla(model.Compile(), "Compile");
            model.Compile("SO16803233a", "SO16803233a.dll");
            PEVerify.AssertValid("SO16803233a.dll");
        }
Example #28
0
        public void ExecuteSigned()
        {
            PreCompileContext ctx;

            Assert.IsTrue(CommandLineAttribute.TryParse(new[] { @"..\..\..\SignedDto\bin\release\SignedDto.dll"
                                                                , @"-o:..\..\..\SignedDto\bin\release\SignedSerializer.dll",
                                                                "-t:MySignedSerializer",
                                                                @"-keyfile:..\..\..\AqlaSerializer2Key.snk" }, out ctx), "TryParse");
            Assert.IsTrue(ctx.SanityCheck(), "SanityCheck");
            Assert.IsTrue(ctx.Execute(), "Execute");
            PEVerify.AssertValid(@"..\..\..\SignedDto\bin\release\SignedSerializer.dll");
        }
Example #29
0
        public void Test_Vanilla()
        {
            var model = TypeModel.Create(false, ProtoCompatibilitySettingsValue.FullCompatibility);

            model.AutoCompile = false;
            Execute_Vanilla(model, "Runtime");
            model.CompileInPlace();
            Execute_Vanilla(model, "CompileInPlace");
            Execute_Vanilla(model.Compile(), "Compile");
            model.Compile("SO16803233a", "SO16803233a.dll");
            PEVerify.AssertValid("SO16803233a.dll");
        }
Example #30
0
        public void Execute()
        {
            var model = RuntimeTypeModel.Create();

            model.AutoCompile = false;

            Execute(model, "Runtime");
            model.CompileInPlace();
            Execute(model, "CompileInPlace");
            Execute(model.Compile(), "Compile");
            model.Compile("SO17040488", "SO17040488.dll");
            PEVerify.AssertValid("SO17040488.dll");
        }