Beispiel #1
0
        public void ShouldFindNoDifferences()
        {
            var obj            = DynamicType.CreateClass("C", DynamicType.CreateClass("B", DynamicType.CreateClass("A"))).Instantiate();
            var typeDescriptor = ((TypeFullDescriptor)obj.GetType());

            var compareResult = typeDescriptor.CompareWith(typeDescriptor);

            Assert.IsTrue(compareResult.Empty);
        }
Beispiel #2
0
        public void ShouldNotDetectInsertionOfTransientField()
        {
            var objPrev = DynamicType.CreateClass("A").Instantiate();
            var objCurr = DynamicType.CreateClass("A").WithTransientField("a", typeof(int)).Instantiate();

            var descPrev = ((TypeFullDescriptor)objPrev.GetType());
            var descCurr = ((TypeFullDescriptor)objCurr.GetType());

            var compareResult = descCurr.CompareWith(descPrev);

            Assert.IsTrue(compareResult.Empty);
        }
        public void TestGuidVerification(
            [Values(
                 0,
                 VersionToleranceLevel.AllowInheritanceChainChange,
                 VersionToleranceLevel.AllowFieldAddition,
                 VersionToleranceLevel.AllowFieldRemoval,
                 VersionToleranceLevel.AllowGuidChange
                 )] VersionToleranceLevel vtl)
        {
            var type   = DynamicType.CreateClass("A").WithField <int>("Field");
            var result = SerializeAndDeserializeOnTwoAppDomains(type, type, vtl, false);

            Assert.AreEqual(vtl.HasFlag(VersionToleranceLevel.AllowGuidChange), result);
        }
Beispiel #4
0
        public void ShouldHandleAssemblyVersionChange()
        {
            var objPrev = DynamicType.CreateClass("A").WithField("a", DynamicType.CreateClass("C").WithField <int>("c")).Instantiate(new Version(1, 0));
            var objCurr = DynamicType.CreateClass("A").WithField("a", DynamicType.CreateClass("C").WithField <int>("c")).Instantiate(new Version(1, 1));

            var descPrev = ((TypeFullDescriptor)objPrev.GetType());
            var descCurr = ((TypeFullDescriptor)objCurr.GetType());

            var compareResult = descCurr.CompareWith(descPrev, VersionToleranceLevel.AllowAssemblyVersionChange);

            Assert.IsEmpty(compareResult.FieldsAdded);
            Assert.IsEmpty(compareResult.FieldsChanged);
            Assert.IsEmpty(compareResult.FieldsRemoved);
        }
Beispiel #5
0
        public void ShouldHandleAssemblyVersionChange()
        {
            var type1 = DynamicType.CreateClass("A").WithField("a", DynamicType.CreateClass("C").WithField <int>("c"));
            var type2 = DynamicType.CreateClass("A").WithField("a", DynamicType.CreateClass("C").WithField <int>("c"));

            testsOnDomain1.CreateInstanceOnAppDomain(type1, new Version(1, 0));
            testsOnDomain1.SetValueOnAppDomain("a.c", 1);

            var bytes = testsOnDomain1.SerializeOnAppDomain();

            testsOnDomain2.CreateInstanceOnAppDomain(type2, new Version(1, 1));
            testsOnDomain2.DeserializeOnAppDomain(bytes, settings.GetSettingsAllowingGuidChange(Antmicro.Migrant.Customization.VersionToleranceLevel.AllowAssemblyVersionChange));

            Assert.AreEqual(1, testsOnDomain2.GetValueOnAppDomain("a.c"));
        }
Beispiel #6
0
        public void ShouldSerializeGenericTypeWithInterface()
        {
            var type1 = DynamicType.CreateClass("A", genericArgument: DynamicType.CreateInterface("IX")).WithField <int>("f");
            var type2 = DynamicType.CreateClass("A", genericArgument: DynamicType.CreateInterface("IX")).WithField <int>("f");

            testsOnDomain1.CreateInstanceOnAppDomain(type1);
            testsOnDomain1.SetValueOnAppDomain("f", 1);

            var bytes = testsOnDomain1.SerializeOnAppDomain();

            testsOnDomain2.CreateInstanceOnAppDomain(type2);
            testsOnDomain2.DeserializeOnAppDomain(bytes, settings.GetSettingsAllowingGuidChange(Antmicro.Migrant.Customization.VersionToleranceLevel.AllowInheritanceChainChange));

            Assert.AreEqual(1, testsOnDomain2.GetValueOnAppDomain("f"));
        }
Beispiel #7
0
        public void ShouldDeserializeConstructorFields()
        {
            var type1 = DynamicType.CreateClass("A").WithConstructorField <object>("f");
            var type2 = DynamicType.CreateClass("A").WithConstructorField <object>("f");

            testsOnDomain1.CreateInstanceOnAppDomain(type1);
            testsOnDomain1.SetValueOnAppDomain("f", new Object());

            var bytes = testsOnDomain1.SerializeOnAppDomain();

            testsOnDomain2.CreateInstanceOnAppDomain(type2);
            testsOnDomain2.DeserializeOnAppDomain(bytes, settings.GetSettingsAllowingGuidChange());

            Assert.IsNotNull(testsOnDomain2.GetValueOnAppDomain("f"));
        }
        public void TestSimpleFieldRemoval(
            [Values(
                 0,
                 VersionToleranceLevel.AllowInheritanceChainChange,
                 VersionToleranceLevel.AllowFieldAddition,
                 VersionToleranceLevel.AllowFieldRemoval,
                 VersionToleranceLevel.AllowGuidChange
                 )] VersionToleranceLevel vtl)
        {
            var type1             = DynamicType.CreateClass("A").WithField <int>("a").WithField <float>("b");
            var type2             = DynamicType.CreateClass("A").WithField <int>("a");
            var deserializationOK = SerializeAndDeserializeOnTwoAppDomains(type1, type2, vtl);

            Assert.IsTrue(vtl.HasFlag(VersionToleranceLevel.AllowFieldRemoval) ? deserializationOK : !deserializationOK);
        }
Beispiel #9
0
        public void ShouldHandleBaseClassAddition()
        {
            var type1 = DynamicType.CreateClass("A").WithField <object>("f");
            var type2 = DynamicType.CreateClass("A", DynamicType.CreateClass("X")).WithField <object>("f");

            testsOnDomain1.CreateInstanceOnAppDomain(type1);
            testsOnDomain1.SetValueOnAppDomain("f", new Object());

            var bytes = testsOnDomain1.SerializeOnAppDomain();

            testsOnDomain2.CreateInstanceOnAppDomain(type2);
            testsOnDomain2.DeserializeOnAppDomain(bytes, settings.GetSettingsAllowingGuidChange(Antmicro.Migrant.Customization.VersionToleranceLevel.AllowInheritanceChainChange));

            Assert.IsNotNull(testsOnDomain2.GetValueOnAppDomain("f"));
        }
Beispiel #10
0
        public void ShouldDetectFieldInsertionSimple()
        {
            var objPrev = DynamicType.CreateClass("A").Instantiate();
            var objCurr = DynamicType.CreateClass("A").WithField("a", typeof(int)).Instantiate();

            var descPrev = TypeDescriptor.CreateFromType(objPrev.GetType());
            var descCurr = TypeDescriptor.CreateFromType(objCurr.GetType());

            var compareResult = descCurr.CompareWith(descPrev);

            Assert.IsEmpty(compareResult.FieldsRemoved);
            Assert.IsEmpty(compareResult.FieldsChanged);

            Assert.AreEqual(1, compareResult.FieldsAdded.Count);
            Assert.AreEqual("A:a", compareResult.FieldsAdded[0].FullName);
        }
Beispiel #11
0
        public void ShouldDetectInsertionOfOverridingField()
        {
            var objPrev = DynamicType.CreateClass("A", DynamicType.CreateClass("Base").WithField("a", typeof(int))).Instantiate();
            var objCurr = DynamicType.CreateClass("A", DynamicType.CreateClass("Base").WithField("a", typeof(int))).WithField("a", typeof(int)).Instantiate();

            var descPrev = ((TypeFullDescriptor)objPrev.GetType());
            var descCurr = ((TypeFullDescriptor)objCurr.GetType());

            var compareResult = descCurr.CompareWith(descPrev);

            Assert.IsEmpty(compareResult.FieldsRemoved);
            Assert.IsEmpty(compareResult.FieldsChanged);

            Assert.AreEqual(1, compareResult.FieldsAdded.Count);
            Assert.AreEqual("A:a", compareResult.FieldsAdded[0].FullName);
        }
Beispiel #12
0
        public void ShouldDetectFieldTypeChange()
        {
            var objPrev = DynamicType.CreateClass("A").WithField("a", typeof(int)).Instantiate();
            var objCurr = DynamicType.CreateClass("A").WithField("a", typeof(long)).Instantiate();

            var descPrev = ((TypeFullDescriptor)objPrev.GetType());
            var descCurr = ((TypeFullDescriptor)objCurr.GetType());

            var compareResult = descCurr.CompareWith(descPrev);

            Assert.IsEmpty(compareResult.FieldsAdded);
            Assert.IsEmpty(compareResult.FieldsRemoved);

            Assert.AreEqual(1, compareResult.FieldsChanged.Count);
            Assert.AreEqual("A:a", compareResult.FieldsChanged.ElementAt(0).FullName);
        }
        public void TestBaseClassRemoval(
            [Values(
                 0,
                 VersionToleranceLevel.AllowInheritanceChainChange,
                 VersionToleranceLevel.AllowFieldAddition,
                 VersionToleranceLevel.AllowFieldRemoval,
                 VersionToleranceLevel.AllowGuidChange
                 )] VersionToleranceLevel vtl)
        {
            var deserializationOK = SerializeAndDeserializeOnTwoAppDomains(
                DynamicType.CreateClass("A", DynamicType.CreateClass("BaseA")),
                DynamicType.CreateClass("A", additionalTypes: new [] { DynamicType.CreateClass("BaseA") }),
                vtl);

            Assert.IsTrue(vtl.HasFlag(VersionToleranceLevel.AllowInheritanceChainChange) ? deserializationOK : !deserializationOK);
        }
        public void TestBaseClassInsertion(
            [Values(
                 0,
                 VersionToleranceLevel.AllowInheritanceChainChange,
                 VersionToleranceLevel.AllowFieldAddition,
                 VersionToleranceLevel.AllowFieldRemoval,
                 VersionToleranceLevel.AllowGuidChange
                 )] VersionToleranceLevel vtl)
        {
            var deserializationOK = SerializeAndDeserializeOnTwoAppDomains(
                DynamicType.CreateClass("A"),
                DynamicType.CreateClass("A", DynamicType.CreateClass("BaseA")),
                vtl);

            Assert.AreEqual(vtl.HasFlag(VersionToleranceLevel.AllowInheritanceChainChange), deserializationOK);
        }
Beispiel #15
0
        public void ShouldHandleFieldMoveUpSimple()
        {
            var objPrev = DynamicType.CreateClass("A", DynamicType.CreateClass("Base")).WithField("a", typeof(int)).Instantiate();
            var objCurr = DynamicType.CreateClass("A", DynamicType.CreateClass("Base").WithField("a", typeof(int))).Instantiate();

            var descPrev = TypeDescriptor.CreateFromType(objPrev.GetType());
            var descCurr = TypeDescriptor.CreateFromType(objCurr.GetType());

            var compareResult = descCurr.CompareWith(descPrev);

            Assert.IsEmpty(compareResult.FieldsChanged);

            Assert.AreEqual(1, compareResult.FieldsAdded.Count);
            Assert.AreEqual(1, compareResult.FieldsRemoved.Count);
            Assert.AreEqual("A:a", compareResult.FieldsRemoved.ElementAt(0).FullName);
            Assert.AreEqual("Base:a", compareResult.FieldsAdded.ElementAt(0).FullName);
        }
Beispiel #16
0
        public void ShouldHandleFieldRemovalInStructNestedInClass()
        {
            var type1 = DynamicType.CreateClass("A").WithField <string>("a").WithField("b", DynamicType.CreateStruct("B").WithField <string>("a").WithField <int>("b"));
            var type2 = DynamicType.CreateClass("A").WithField <string>("a").WithField("b", DynamicType.CreateStruct("B").WithField <int>("b"));

            testsOnDomain1.CreateInstanceOnAppDomain(type1);
            testsOnDomain1.SetValueOnAppDomain("a", "testing");
            testsOnDomain1.SetValueOnAppDomain("b.a", "text");
            testsOnDomain1.SetValueOnAppDomain("b.b", 147);

            var bytes = testsOnDomain1.SerializeOnAppDomain();

            testsOnDomain2.CreateInstanceOnAppDomain(type2);
            testsOnDomain2.DeserializeOnAppDomain(bytes, settings.GetSettingsAllowingGuidChange(Antmicro.Migrant.Customization.VersionToleranceLevel.AllowFieldRemoval));

            Assert.AreEqual("testing", testsOnDomain2.GetValueOnAppDomain("a"));
            Assert.AreEqual(147, testsOnDomain2.GetValueOnAppDomain("b.b"));
        }
Beispiel #17
0
        public void ShouldHandleFieldInsertion()
        {
            var type1 = DynamicType.CreateClass("A").WithField <string>("a").WithField <string>("c");
            var type2 = DynamicType.CreateClass("A").WithField <string>("a").WithField <int>("b").WithField <string>("c");

            testsOnDomain1.CreateInstanceOnAppDomain(type1);
            testsOnDomain1.SetValueOnAppDomain("a", "testing");
            testsOnDomain1.SetValueOnAppDomain("c", "finish");

            var bytes = testsOnDomain1.SerializeOnAppDomain();

            testsOnDomain2.CreateInstanceOnAppDomain(type2);
            testsOnDomain2.DeserializeOnAppDomain(bytes, settings.GetSettingsAllowingGuidChange(Antmicro.Migrant.Customization.VersionToleranceLevel.AllowFieldAddition));

            Assert.AreEqual("testing", testsOnDomain2.GetValueOnAppDomain("a"));
            Assert.AreEqual(0, testsOnDomain2.GetValueOnAppDomain("b"));
            Assert.AreEqual("finish", testsOnDomain2.GetValueOnAppDomain("c"));
        }
        public void TestFieldMovedBetweenClasses(
            [Values(
                 VersionToleranceLevel.AllowInheritanceChainChange,
                 VersionToleranceLevel.AllowFieldAddition,
                 VersionToleranceLevel.AllowFieldRemoval,
                 VersionToleranceLevel.AllowGuidChange,
                 VersionToleranceLevel.AllowFieldAddition | VersionToleranceLevel.AllowFieldRemoval
                 )] VersionToleranceLevel vtl)
        {
            var deserializationOK = SerializeAndDeserializeOnTwoAppDomains(
                DynamicType.CreateClass("A", DynamicType.CreateClass("BaseA").WithField("a", typeof(string))).WithField("b", typeof(int)),
                DynamicType.CreateClass("A", DynamicType.CreateClass("BaseA")).WithField("a", typeof(string)).WithField("b", typeof(int)),
                vtl);

            Assert.AreEqual(
                vtl.HasFlag(VersionToleranceLevel.AllowFieldAddition) && vtl.HasFlag(VersionToleranceLevel.AllowFieldRemoval),
                deserializationOK);
        }