Example #1
0
        public void CloneWithoutBuffer_ExampleStruct()
        {
            ExampleStructContainingClasses GetExampleStruct()
            {
                ExampleStructContainingClasses s = new ExampleStructContainingClasses();

                s.MyBool   = true;
                s.MyChar   = 'x';
                s.MyChild1 = new ExampleChildInherited()
                {
                    MyInt  = 34,
                    MyLong = 341341
                };
                s.MyListValues = new List <int>()
                {
                    3, 4
                };
                s.MyTuple         = (new NonLazinatorClass()
                {
                    MyInt = 5
                }, 4);
                s.MyLazinatorList = new List <Example>()
                {
                    new Example()
                };
                return(s);
            }

            VerifyCloningEquivalence(() => GetExampleStruct());
        }
Example #2
0
        public void DirtinessWorksForClassInStruct()
        {
            ExampleStructContainingClasses s = new ExampleStructContainingClasses()
            {
                MyChild1 = new ExampleChild()
            };
            var c = s.CloneLazinatorTyped();

            c.DescendantIsDirty.Should().BeFalse();
            c.MyChild1.MyLong = 23451243;
            c.DescendantIsDirty.Should().BeTrue();
        }
Example #3
0
        public void StructLazinatorWorks()
        {
            ExampleStructContainingClasses s = new ExampleStructContainingClasses();

            s.MyBool   = true;
            s.MyChar   = 'x';
            s.MyChild1 = new ExampleChildInherited()
            {
                MyInt  = 34,
                MyLong = 341341
            };
            s.MyListValues = new List <int>()
            {
                3, 4
            };
            s.MyTuple         = (new NonLazinatorClass()
            {
                MyInt = 5
            }, 4);
            s.MyLazinatorList = new List <Example>()
            {
                new Example()
            };

            var s2 = s.CloneLazinatorTyped();

            s2.MyBool.Should().BeTrue();
            s2.MyChar.Should().Be('x');
            s2.MyChild1.Should().NotBeNull();
            var child1 = (ExampleChildInherited)s2.MyChild1;

            child1.Should().NotBeNull();
            child1.MyInt.Should().Be(34);
            child1.MyLong.Should().Be(341341);
            s2.IsDirty.Should().BeFalse();
            s2.MyListValues.Should().NotBeNull(); // will cause IsDirty to be false
            s2.MyListValues.Count().Should().Be(2);
            s2.MyTuple.Item1.MyInt.Should().Be(5);
            s2.MyTuple.Item2.Should().Be(4);
            s2.MyLazinatorList.Count().Should().Be(1);
            // make sure that parent knows of descendant dirtiness (remember that the technique is different with structs)
            s2.IsDirty.Should().BeTrue(); // as a result of access above
            s2.DescendantIsDirty.Should().BeFalse();
            child1.MyLong = 17;
            s2.DescendantIsDirty.Should().BeTrue();

            var s3 = s.CloneLazinatorTyped();

            s3.IsDirty.Should().Be(false);
            s3.MyLazinatorList[0] = new Example()
            {
                MyChar = 'y'
            };
            s3.IsDirty.Should().Be(false);
            s3.DescendantIsDirty.Should().Be(false); // struct can't be informed about this kind of change
            Action reserializationAction = () => s3.SerializeLazinator(new LazinatorSerializationOptions(IncludeChildrenMode.IncludeAllChildren, true, false, false));

            reserializationAction.Should().Throw <UnexpectedDirtinessException>();
            s3.MyLazinatorList_Dirty = true;
            var s3Serialized = s3.SerializeLazinator(new LazinatorSerializationOptions(IncludeChildrenMode.IncludeAllChildren, true, false, false));
            ExampleStructContainingClasses s3b = new ExampleStructContainingClasses(s3Serialized);

            s3b.MyLazinatorList[0].MyChar.Should().Be('y');

            var s4 = s.CloneLazinatorTyped();

            s4.IsDirty.Should().Be(false);
            s4.MyListValues[0] = -12345;
            s4.IsDirty.Should().Be(true);            // just accessing should set IsDirty to true
            s4.DescendantIsDirty.Should().Be(false); // struct can't be informed about this kind of change

            var s5 = s4.CloneLazinatorTyped();

            s5.MyListValues[0].Should().Be(-12345); // confirm proper serialization
        }