Beispiel #1
0
        public void LazinatorListWithStructsWorks()
        {
            LazinatorList <WInt32> l = new LazinatorList <WInt32>()
            {
                3
            };

            var c = l.CloneLazinatorTyped();

            c[0].WrappedValue.Should().Be(3);

            c = l.CloneLazinatorTyped();
            c.Insert(0, 2);
            var c2 = c.CloneLazinatorTyped();

            c2[0].WrappedValue.Should().Be(2);
            c2[1].WrappedValue.Should().Be(3);

            c = l.CloneLazinatorTyped();
            c.Add(4);
            var c3 = c.CloneLazinatorTyped();

            c3[0].WrappedValue.Should().Be(3);
            c3[1].WrappedValue.Should().Be(4);
            c3.Add(5);
            c3[2].Should().Be(5);

            c = c2.CloneLazinatorTyped();
            var accessed = c[1];
            var c2b      = c.CloneLazinatorTyped();

            c2b[0].WrappedValue.Should().Be(2);
            c2b[1].WrappedValue.Should().Be(3);
        }
Beispiel #2
0
        public void LazinatorListItemParentSet()
        {
            LazinatorList <ExampleChild> l = new LazinatorList <ExampleChild>()
            {
                new ExampleChild(),
                new ExampleChild()
            };

            l[0].LazinatorParents.LastAdded.Should().Be(l);
            l[1].LazinatorParents.LastAdded.Should().Be(l);
            var c = l.CloneLazinatorTyped();

            c[0].LazinatorParents.LastAdded.Should().Be(c);
            c[1].LazinatorParents.LastAdded.Should().Be(c);
            var c2 = l.CloneLazinatorTyped();

            c2.Insert(0, new ExampleChild());
            c2[1].LazinatorParents.LastAdded.Should().Be(c2);
            var c3  = l.CloneLazinatorTyped();
            var lc3 = c3.ToList();

            lc3[1].LazinatorParents.LastAdded.Should().Be(c3);
            var c4  = l.CloneLazinatorTyped();
            var lc4 = c4.AsEnumerable().ToList();

            lc4[1].LazinatorParents.LastAdded.Should().Be(c4);
            var c5 = l.CloneLazinatorTyped();

            c5[0] = new ExampleChild();
            c5[0].LazinatorParents.LastAdded.Should().Be(c5);
        }
Beispiel #3
0
        public void CanCloneListOfLazinatorsAndThenEnsureUpToDate()
        {
            var l = new LazinatorList <Example>()
            {
                GetTypicalExample(), GetTypicalExample()
            };
            var l2 = l.CloneLazinatorTyped();
            var l3 = l.CloneLazinatorTyped();

            l.SerializeLazinator();
        }
Beispiel #4
0
        public void CanCloneListOfStructsAndThenEnsureUpToDate()
        {
            // Note: This works because of IsStruct parameter in ReplaceBuffer. Without that parameter, the last call would lead to disposal of memory still needed.
            var l = new LazinatorList <WInt32>()
            {
                1
            };
            var l2 = l.CloneLazinatorTyped();
            var l3 = l.CloneLazinatorTyped();

            l.SerializeLazinator();
        }
Beispiel #5
0
        public void LazinatorListWithEightByteContainer()
        {
            LazinatorList <EightByteLengthsContainer> l = new LazinatorList <EightByteLengthsContainer>()
            {
                new EightByteLengthsContainer()
                {
                    Contents = new EightByteLengths()
                    {
                        Example = GetExample(0)
                    }
                },
                new EightByteLengthsContainer()
                {
                    Contents = new EightByteLengths()
                    {
                        Example = GetExample(1)
                    }
                },
                null
            };
            var l2 = l.CloneLazinatorTyped();

            ExampleEqual(l[0].Contents.Example, l2[0].Contents.Example).Should().BeTrue();
            ExampleEqual(l[1].Contents.Example, l2[1].Contents.Example).Should().BeTrue();
            l2[2].Should().BeNull();
        }
Beispiel #6
0
        public void LazinatorListDirtinessWithNestedStructs()
        {
            LazinatorList <ExampleStructContainingStruct> l = new LazinatorList <ExampleStructContainingStruct>()
            {
                new ExampleStructContainingStruct()
                {
                    MyExampleStructContainingClasses = new ExampleStructContainingClasses()
                    {
                        MyChar = 'Q'
                    }
                }
            };

            l.SerializeLazinator();
            var c = l.CloneLazinatorTyped();

            // consider original list, which should be clean
            l.IsDirty.Should().BeFalse();
            l.DescendantIsDirty.Should().BeFalse();
            l[0].IsDirty.Should().BeFalse();
            l[0].MyExampleStructContainingClasses.IsDirty.Should().BeFalse();
            // now consider clone
            c.IsDirty.Should().BeFalse();
            c.DescendantIsDirty.Should().BeFalse();
            c[0].IsDirty.Should().BeFalse();
            c[0].MyExampleStructContainingClasses.IsDirty.Should().BeFalse();
            c[0].MyExampleStructContainingClasses.MyChar.Should().Be('Q');
        }
Beispiel #7
0
        public void EmptyLazinatorListWorks()
        {
            LazinatorList <WInt32> l = new LazinatorList <WInt32>();
            var c = l.CloneLazinatorTyped();

            c.Count().Should().Be(0);
        }
Beispiel #8
0
        public void ShortLazinatorListWorks()
        {
            LazinatorList <WInt32> l = new LazinatorList <WInt32>();

            l.Add(3);
            var c      = l.CloneLazinatorTyped();
            var result = c[0];

            result.Should().Be(3);
        }
Beispiel #9
0
        public void LazinatorListEnumerateNodesWorks()
        {
            LazinatorList <Example> l = new LazinatorList <Example>()
            {
                GetExample(1), GetExample(1)
            };
            var c        = l.CloneLazinatorTyped();
            var results2 = c.EnumerateAllNodes().ToList();

            results2[0].Should().Be(c);
            results2[1].LazinatorParents.LastAdded.Should().Be(c);
        }
Beispiel #10
0
        public void LazinatorListEnumeratorWorks()
        {
            LazinatorList <Example> l = new LazinatorList <Example>()
            {
                GetExample(1), GetExample(1)
            };
            var results = l.ToList();

            results[0].LazinatorParents.LastAdded.Should().Be(l);
            results[1].LazinatorParents.LastAdded.Should().Be(l);
            var c = l.CloneLazinatorTyped();

            results = c.ToList();
            results[0].LazinatorParents.LastAdded.Should().Be(c);
            results[1].LazinatorParents.LastAdded.Should().Be(c);
            c = l.CloneLazinatorTyped();
            foreach (var result in c)
            {
                result.LazinatorParents.LastAdded.Should().Be(c);
            }
        }
Beispiel #11
0
        void BinaryHashInList()
        {
            var wrapped              = new WInt32(1);
            var wrapped2             = new WInt32(1);
            LazinatorList <WInt32> x = new LazinatorList <WInt32>();

            x.Add(wrapped2);
            x.GetListMemberHash32(0).Should().Be(wrapped.GetBinaryHashCode32());
            var clone = x.CloneLazinatorTyped();

            clone.GetListMemberHash32(0).Should().Be(wrapped.GetBinaryHashCode32());
        }
Beispiel #12
0
        public void LazinatorListWorksWithPartialAccessAfterChange()
        {
            LazinatorList <WInt32> l = new LazinatorList <WInt32>();

            l.Add(3);
            l.Add(4);
            var c = l.CloneLazinatorTyped();

            c[0] = 999999;
            var c2 = c.CloneLazinatorTyped();

            c2[1].WrappedValue.Should().Be(4);
        }
Beispiel #13
0
        public void ChangeToObjectAppearingTwiceInLazinatorListAffectsBoth()
        {
            LazinatorList <ExampleChild> e = new LazinatorList <ExampleChild>()
            {
                new ExampleChild(),
                new ExampleChild()
                {
                    MyLong = -123456
                }
            };
            var c = e.CloneLazinatorTyped();

            c[0]        = c[1];
            c[0].MyLong = -987;
            var c2 = c.CloneLazinatorTyped();

            c2[0].MyLong.Should().Be(-987);
            c2[1].MyLong.Should().Be(-987);
        }
Beispiel #14
0
        public void LazinatorListDirtinessWithStructs()
        {
            LazinatorList <WInt32> l = new LazinatorList <WInt32>()
            {
                new WInt32(3)
            };

            l.SerializeLazinator();
            var c = l.CloneLazinatorTyped();

            // consider original list, which should be clean
            l.IsDirty.Should().BeFalse();
            l.DescendantIsDirty.Should().BeFalse();
            l[0].IsDirty.Should().BeFalse();
            // now consider clone
            c.IsDirty.Should().BeFalse();
            c.DescendantIsDirty.Should().BeFalse();
            c[0].IsDirty.Should().BeFalse();
        }
Beispiel #15
0
        public void LazinatorListCountWorks()
        {
            LazinatorList <Example> l = new LazinatorList <Example>()
            {
                GetExample(1), GetExample(1)
            };

            l.Count.Should().Be(2);
            l.Add(null);
            l.Count.Should().Be(3);
            l.RemoveAt(1);
            l.Count.Should().Be(2);
            var c = l.CloneLazinatorTyped();

            c.Count.Should().Be(2);
            c.Insert(0, GetExample(1));
            c.Count.Should().Be(3);
            c.Add(GetExample(2));
            c.Count.Should().Be(4);
            c.RemoveAll(x => true);
            c.Count.Should().Be(0);
        }
Beispiel #16
0
        public void LazinatorListForEachLazinatorWorks()
        {
            LazinatorList <WString> l = new LazinatorList <WString>()
            {
                "hello", "world"
            };
            StringBuilder sb = new StringBuilder();
            var           c  = l.ForEachLazinator(x =>
            {
                if (x is WString ws)
                {
                    sb.Append(ws.WrappedValue);
                }
                return(x);
            }, true, true);

            sb.ToString().Should().Be("helloworld");
            l  = l.CloneLazinatorTyped();
            sb = new StringBuilder();
            c  = l.ForEachLazinator(x =>
            {
                if (x is WString ws)
                {
                    sb.Append(ws.WrappedValue);
                }
                return(x);
            }, true, true);
            sb.ToString().Should().Be("");
            c = l.ForEachLazinator(x =>
            {
                if (x is WString ws)
                {
                    sb.Append(ws.WrappedValue);
                }
                return(x);
            }, false, true); // now deserialize
            sb.ToString().Should().Be("helloworld");
        }
Beispiel #17
0
        public void SimplifiableWorks()
        {
            Simplifiable s = new Simplifiable()
            {
                ANonSkippableEarlierExample = new Example()
                {
                    MyChar = 'A'
                }
            };
            var c = s.CloneLazinatorTyped();

            s.MyInt.Should().Be(0);
            s.MyOtherInt.Should().Be(0);
            s.Example.Should().BeNull();
            s.Example2.Should().BeNull();
            s.Example3.Should().BeNull();
            var originalbytes = s.SerializeLazinator(new LazinatorSerializationOptions(IncludeChildrenMode.IncludeAllChildren, false, false, false));


            // take advantage of simplifications
            s = new Simplifiable()
            {
                MyInt      = 3,
                MyOtherInt = 3,
                ANonSkippableEarlierExample = new Example()
                {
                    MyChar = 'A'
                },
                Example = new Example()
                {
                    MyChar = 'X', MyString = Simplifiable.LongString
                },
                Example2 = new Example()
                {
                    MyChar = 'Z'
                },
                Example3 = null
            };
            c = s.CloneLazinatorTyped();
            s.MyInt.Should().Be(3);
            s.MyOtherInt.Should().Be(3);
            s.ANonSkippableEarlierExample.MyChar.Should().Be('A');
            s.Example.MyChar.Should().Be('X');
            s.Example.MyString.Should().Be(Simplifiable.LongString);
            s.Example2.MyChar.Should().Be('Z');
            s.Example3.Should().BeNull();
            var d = s.SerializeLazinator(new LazinatorSerializationOptions(IncludeChildrenMode.IncludeAllChildren, false, false, false));

            d.InitialReadOnlyMemory.Length.Should().BeLessOrEqualTo(originalbytes.InitialReadOnlyMemory.Length); // shorter even though it is more complex once constructed

            // now use the values that are not simplified
            s = new Simplifiable()
            {
                MyInt      = 4,
                MyOtherInt = 5,
                Example    = new Example()
                {
                    MyChar = 'A', MyString = "Hello"
                },
                Example2 = null,
                Example3 = new Example()
                {
                    MyDateTime = new System.DateTime(123456)
                }
            };
            c = s.CloneLazinatorTyped();
            s.MyInt.Should().Be(4);
            s.MyOtherInt.Should().Be(5);
            s.Example.MyChar.Should().Be('A');
            s.Example.MyString.Should().Be("Hello");
            s.Example2.Should().BeNull();
            s.Example3.MyDateTime.Ticks.Should().Be(123456);

            var l = new LazinatorList <Simplifiable>()
            {
                new Simplifiable()
                {
                    MyInt = 3, MyOtherInt = 3
                }
            };
            var cl = l.CloneLazinatorTyped();

            cl[0].MyIntsAre3.Should().BeTrue();
            cl[0].MyInt.Should().Be(3);
            cl[0].MyOtherInt.Should().Be(3);

            cl[0].MyInt = 2;
            cl          = cl.CloneLazinatorTyped();
            cl[0].MyIntsAre3.Should().BeFalse();

            cl[0].MyInt = 3;
            cl          = cl.CloneLazinatorTyped();
            cl[0].MyIntsAre3.Should().BeTrue();

            cl[0].MyInt = 2;
            cl.SerializeLazinator();
            cl[0].MyIntsAre3.Should().BeFalse();
        }