Esempio n. 1
0
        public void ShouldNotDetectInsertionOfTransientField()
        {
            var objPrev = DynamicClass.Create("A").Instantiate();
            var objCurr = DynamicClass.Create("A").WithTransientField("a", typeof(int)).Instantiate();

            var stampPrev = new TypeStamp(objPrev.GetType());
            var stampCurr = new TypeStamp(objCurr.GetType());

            var compareResult = stampCurr.CompareWith(stampPrev);

            Assert.IsTrue(compareResult.Empty);
        }
Esempio n. 2
0
        public void TestGuidVerification(
            [Values(VersionToleranceLevel.InheritanceChainChange,
                    VersionToleranceLevel.ExactLayout,
                    VersionToleranceLevel.FieldAddition,
                    VersionToleranceLevel.FieldMove,
                    VersionToleranceLevel.FieldRemoval,
                    VersionToleranceLevel.Guid,
                    VersionToleranceLevel.TypeNameChanged)] VersionToleranceLevel vtl)
        {
            var type   = DynamicClass.Create("A").WithField <int>("Field");
            var result = SerializeAndDeserializeOnTwoAppDomains(type, type, vtl);

            Assert.IsTrue(vtl.HasFlag(VersionToleranceLevel.Guid) ? !result : result);
        }
Esempio n. 3
0
        public void TestSimpleFieldRemoval(
            [Values(VersionToleranceLevel.InheritanceChainChange,
                    VersionToleranceLevel.ExactLayout,
                    VersionToleranceLevel.FieldAddition,
                    VersionToleranceLevel.FieldMove,
                    VersionToleranceLevel.FieldRemoval,
                    VersionToleranceLevel.Guid,
                    VersionToleranceLevel.TypeNameChanged)] VersionToleranceLevel vtl)
        {
            var type1             = DynamicClass.Create("A").WithField <int>("a").WithField <float>("b");
            var type2             = DynamicClass.Create("A").WithField <int>("a");
            var deserializationOK = SerializeAndDeserializeOnTwoAppDomains(type1, type2, vtl);

            Assert.IsTrue(vtl.HasFlag(VersionToleranceLevel.FieldRemoval) ? deserializationOK : !deserializationOK);
        }
Esempio n. 4
0
        public void ShouldDeserializeConstructorFields()
        {
            var type1 = DynamicClass.Create("A").WithConstructorField <object>("f");
            var type2 = DynamicClass.Create("A").WithConstructorField <object>("f");

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

            var bytes = testsOnDomain1.SerializeOnAppDomain();

            testsOnDomain2.CreateInstanceOnAppDomain(type2);
            testsOnDomain2.DeserializeOnAppDomain(bytes, GetSettings());

            Assert.IsNotNull(testsOnDomain2.GetValueOnAppDomain("f"));
        }
Esempio n. 5
0
        public void TestBaseClassRemoval(
            [Values(VersionToleranceLevel.InheritanceChainChange,
                    VersionToleranceLevel.ExactLayout,
                    VersionToleranceLevel.FieldAddition,
                    VersionToleranceLevel.FieldMove,
                    VersionToleranceLevel.FieldRemoval,
                    VersionToleranceLevel.Guid,
                    VersionToleranceLevel.TypeNameChanged)] VersionToleranceLevel vtl)
        {
            var deserializationOK = SerializeAndDeserializeOnTwoAppDomains(
                DynamicClass.Create("A", DynamicClass.Create("BaseA")),
                DynamicClass.Create("A"),
                vtl);

            Assert.IsTrue(vtl.HasFlag(VersionToleranceLevel.InheritanceChainChange) ? deserializationOK : !deserializationOK);
        }
Esempio n. 6
0
        public void ShouldHandleFieldMoveDown()
        {
            var type1 = DynamicClass.Create("A", DynamicClass.Create("Base")).WithField <string>("a").WithField <string>("b");
            var type2 = DynamicClass.Create("A", DynamicClass.Create("Base").WithField <string>("a")).WithField <string>("b");

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

            var bytes = testsOnDomain1.SerializeOnAppDomain();

            testsOnDomain2.CreateInstanceOnAppDomain(type2);
            testsOnDomain2.DeserializeOnAppDomain(bytes, GetSettings(Antmicro.Migrant.Customization.VersionToleranceLevel.FieldMove));

            Assert.AreEqual("testing", testsOnDomain2.GetValueOnAppDomain("a"));
            Assert.AreEqual("finish", testsOnDomain2.GetValueOnAppDomain("b"));
        }
Esempio n. 7
0
        public void ShouldHandleNewFieldMoveUp()
        {
            var type1 = DynamicClass.Create("C", DynamicClass.Create("B", DynamicClass.Create("A").WithField <int>("f")).WithField <int>("f"));
            var type2 = DynamicClass.Create("C", DynamicClass.Create("B", DynamicClass.Create("A")).WithField <int>("f")).WithField <int>("f");

            testsOnDomain1.CreateInstanceOnAppDomain(type1);
            testsOnDomain1.SetValueOnAppDomain("A", "f", 100);
            testsOnDomain1.SetValueOnAppDomain("B", "f", 200);

            var bytes = testsOnDomain1.SerializeOnAppDomain();

            testsOnDomain2.CreateInstanceOnAppDomain(type2);
            testsOnDomain2.DeserializeOnAppDomain(bytes, GetSettings(Antmicro.Migrant.Customization.VersionToleranceLevel.FieldMove));

            Assert.AreEqual(100, testsOnDomain2.GetValueOnAppDomain("C", "f"));
            Assert.AreEqual(200, testsOnDomain2.GetValueOnAppDomain("B", "f"));
        }
Esempio n. 8
0
        public bool SerializeAndDeserializeOnTwoAppDomains(DynamicClass domainOneType, DynamicClass domainTwoType, VersionToleranceLevel vtl)
        {
            testsOnDomain1.CreateInstanceOnAppDomain(domainOneType);
            testsOnDomain2.CreateInstanceOnAppDomain(domainTwoType);

            var bytes = testsOnDomain1.SerializeOnAppDomain();

            try
            {
                testsOnDomain2.DeserializeOnAppDomain(bytes, GetSettings(vtl));
                return(true);
            }
            catch (InvalidOperationException)
            {
                return(false);
            }
        }
Esempio n. 9
0
        public void ShouldDetectInsertionOfOverridingField()
        {
            var objPrev = DynamicClass.Create("A", DynamicClass.Create("Base").WithField("a", typeof(int))).Instantiate();
            var objCurr = DynamicClass.Create("A", DynamicClass.Create("Base").WithField("a", typeof(int))).WithField("a", typeof(int)).Instantiate();

            var stampPrev = new TypeStamp(objPrev.GetType());
            var stampCurr = new TypeStamp(objCurr.GetType());

            var compareResult = stampCurr.CompareWith(stampPrev);

            Assert.IsEmpty(compareResult.ClassesAdded);
            Assert.IsEmpty(compareResult.ClassesRemoved);
            Assert.IsEmpty(compareResult.ClassesRenamed);
            Assert.IsEmpty(compareResult.FieldsMoved);
            Assert.IsEmpty(compareResult.FieldsRemoved);
            Assert.IsEmpty(compareResult.FieldsChanged);

            Assert.AreEqual(1, compareResult.FieldsAdded.Count);
            Assert.AreEqual("a", compareResult.FieldsAdded[0].Name);
        }
Esempio n. 10
0
        public void ShouldDetectBaseClassRemovalSimple()
        {
            var objPrev = DynamicClass.Create("A", DynamicClass.Create("Base")).Instantiate();
            var objCurr = DynamicClass.Create("A").Instantiate();

            var stampPrev = new TypeStamp(objPrev.GetType());
            var stampCurr = new TypeStamp(objCurr.GetType());

            var compareResult = stampCurr.CompareWith(stampPrev);

            Assert.IsEmpty(compareResult.ClassesAdded);
            Assert.IsEmpty(compareResult.ClassesRenamed);
            Assert.IsEmpty(compareResult.FieldsMoved);
            Assert.IsEmpty(compareResult.FieldsRemoved);
            Assert.IsEmpty(compareResult.FieldsAdded);
            Assert.IsEmpty(compareResult.FieldsChanged);

            Assert.AreEqual(1, compareResult.ClassesRemoved.Count);
            Assert.IsTrue(compareResult.ClassesRemoved[0].StartsWith("Base"));
        }
Esempio n. 11
0
 public void CreateInstanceOnAppDomain(DynamicClass type)
 {
     obj = type.Instantiate();
 }