Beispiel #1
0
        public void LazinatorListWithObjectsWorks()
        {
            var original = new LazinatorListContainer()
            {
                MyList = new LazinatorList <ExampleChild>()
                {
                    new ExampleChild()
                    {
                        MyShort = 22
                    },
                    new ExampleChildInherited()
                    {
                        MyShort = 21, MyInt = 23
                    }
                }
            };
            var clone = original.CloneLazinatorTyped(); // second clone
            var list  = clone.MyList;

            list.Should().NotBeNull();
            list[0].MyShort.Should().Be(22);
            var innerDerived = list[1] as ExampleChildInherited;

            innerDerived.Should().NotBeNull();
            innerDerived.MyShort.Should().Be(21);
            innerDerived.MyInt.Should().Be(23);
        }
Beispiel #2
0
        public void BuffersUpdateInTandem_LazinatorList_Struct()
        {
            LazinatorListContainer e = GetLazinatorListContainer();

            e.MyStructList[1] = 6;
            e.MyStructList[1] = e.MyStructList[1].CloneLazinatorTyped(IncludeChildrenMode.IncludeAllChildren, CloneBufferOptions.IndependentBuffers); // generate a new buffer in a list member
            ConfirmBuffersUpdateInTandem(e);
            e.MyInt = 17;                                                                                                                             // keep list clean while making container dirty
            ConfirmBuffersUpdateInTandem(e);
        }
Beispiel #3
0
        public void BuffersUpdateInTandem_LazinatorList()
        {
            LazinatorListContainer e = GetLazinatorListContainer();

            e.MyList[1].MyExampleGrandchild.MyInt = 6;
            e.MyList[1].SerializeLazinator(); // generate a new buffer in a list member
            ConfirmBuffersUpdateInTandem(e);
            e.MyInt = 17;                     // keep list clean while making container dirty
            ConfirmBuffersUpdateInTandem(e);
        }
Beispiel #4
0
        public void UpdateBufferForDeserialized_LazinatorList()
        {
            LazinatorListContainer c = GetLazinatorListContainer();

            c.MyList[0].MyExampleGrandchild.MyInt = 200;
            UpdateStoredBufferFromExisting(c);
            var item = c.MyList[0].CloneLazinatorTyped();
            var c2   = c.CloneLazinatorTyped();

            c.MyList[0].MyExampleGrandchild.MyInt.Should().Be(200);
        }
Beispiel #5
0
        public void LazinatorListNullWorks()
        {
            LazinatorListContainer nonGenericContainer = new LazinatorListContainer()
            {
            };

            nonGenericContainer.MyList = null;
            var clone       = nonGenericContainer.CloneLazinatorTyped();
            var listInClone = clone.MyList;

            listInClone.Should().BeNull();

            // and again
            clone       = nonGenericContainer.CloneLazinatorTyped();
            listInClone = clone.MyList;
            listInClone.Should().BeNull();
        }
Beispiel #6
0
        public void LazinatorListEmptyWorks()
        {
            LazinatorListContainer nonGenericContainer = new LazinatorListContainer()
            {
            };

            nonGenericContainer.MyList = new LazinatorList <ExampleChild>();
            var clone       = nonGenericContainer.CloneLazinatorTyped();
            var listInClone = clone.MyList;

            listInClone.Should().NotBeNull();

            // and again
            clone       = nonGenericContainer.CloneLazinatorTyped();
            listInClone = clone.MyList;
            listInClone.Should().NotBeNull();
        }
Beispiel #7
0
        private LazinatorListContainer GetLazinatorListContainer()
        {
            LazinatorListContainer container = new LazinatorListContainer();

            container.MyList = new LazinatorList <ExampleChild>();
            container.MyList.Add(GetExampleChild(1));
            container.MyList[0].MyExampleGrandchild = new ExampleGrandchild()
            {
                MyInt = 5
            };
            container.MyList.Add(GetExampleChild(1));
            container.MyList[1].MyExampleGrandchild = new ExampleGrandchild()
            {
                MyInt = 5
            };
            container.MyStructList = new LazinatorList <WByte>();
            container.MyStructList.Add(1);
            container.MyStructList.Add(2);
            container = container.CloneLazinatorTyped();
            return(container);
        }
Beispiel #8
0
        public void UpdateBufferForDeserialized_LazinatorList_Struct()
        {
            LazinatorListContainer c = new LazinatorListContainer()
            {
                MyStructList = new LazinatorList <WByte>()
            };

            c.MyStructList.Add(3);
            c.MyStructList.Add(4);
            c = c.CloneLazinatorTyped();
            var x = c.MyStructList[0];

            c.MyInt = -234;
            UpdateStoredBufferFromExisting(c);
            var storageOverall = c.LazinatorMemoryStorage.SingleMemoryChunk;
            var storageItem    = c.MyStructList[0].LazinatorMemoryStorage.SingleMemoryChunk;

            storageOverall.AllocationID.Should().Be(storageItem.AllocationID);
            var item = c.MyStructList[0].CloneLazinatorTyped();
            var c2   = c.CloneLazinatorTyped();

            item.WrappedValue.Should().Be(3);
        }
Beispiel #9
0
        public void LazinatorListDirtinessEnumerationWorks()
        {
            LazinatorListContainer nonGenericContainer = new LazinatorListContainer()
            {
            };

            nonGenericContainer.MyList = new LazinatorList <ExampleChild>();

            var v2 = nonGenericContainer.CloneLazinatorTyped();

            v2.MyList.Add(GetExampleChild(1));
            v2.MyList.Add(GetExampleChild(1));
            v2.MyList.Add(GetExampleChild(1));

            var results = v2.GetDirtyNodes(true);

            results.Count().Should().Be(7);

            var v5 = v2.CloneLazinatorTyped();

            v5.MyList[1].MyLong = -98765;
            results             = v5.GetDirtyNodes(true);
            results.Count().Should().Be(1);
        }
Beispiel #10
0
        public void RemoveBufferWorks_LazinatorList()
        {
            // when we remove the buffer from a lazinatorlist, it completely deserializes.

            LazinatorListContainer lazinator = new LazinatorListContainer()
            {
                MyStructList = new LazinatorList <WByte>()
                {
                    3,
                    4,
                    5
                }
            };

            lazinator.SerializeLazinator();
            lazinator.LazinatorMemoryStorage.IsEmpty.Should().BeFalse();
            var x = lazinator.MyStructList[0].WrappedValue;

            lazinator.MyStructList[0] = 6;
            lazinator.MyStructList[0].LazinatorMemoryStorage.IsEmpty.Should().BeTrue();

            lazinator.RemoveBufferInHierarchy();
            lazinator.LazinatorMemoryStorage.IsEmpty.Should().BeTrue();
            lazinator.MyStructList[0].LazinatorMemoryStorage.IsEmpty.Should().BeTrue();
            lazinator.MyStructList[0].WrappedValue.Should().Be(6);

            lazinator.SerializeLazinator();
            lazinator.MyStructList[0].LazinatorMemoryStorage.IsEmpty.Should().BeTrue();
            lazinator.MyStructList[0].WrappedValue.Should().Be(6);

            lazinator.SerializeLazinator();
            lazinator.MyStructList[0].LazinatorMemoryStorage.IsEmpty.Should().BeTrue();
            lazinator.MyStructList[0].WrappedValue.Should().Be(6);

            lazinator.MyStructList[0] = 7;
            lazinator.SerializeLazinator();
            lazinator.MyStructList[0].LazinatorMemoryStorage.IsEmpty.Should().BeTrue();
            lazinator.MyStructList[0].WrappedValue.Should().Be(7);

            WByte w = new WByte(8).CloneLazinatorTyped(); // make

            lazinator.MyStructList[0] = w;
            lazinator.MyStructList[0].LazinatorMemoryStorage.IsEmpty.Should().BeFalse();
            lazinator.RemoveBufferInHierarchy();
            lazinator.MyStructList[0].LazinatorMemoryStorage.IsEmpty.Should().BeTrue();

            lazinator.MyStructList[1] = w;
            lazinator.MyStructList[1].LazinatorMemoryStorage.IsEmpty.Should().BeFalse();
            lazinator.SerializeLazinator();
            lazinator.MyStructList[1].LazinatorMemoryStorage.IsEmpty.Should().BeTrue();

            lazinator = new LazinatorListContainer()
            {
                MyStructList = new LazinatorList <WByte>()
                {
                    3,
                    4,
                    5
                }
            };
            lazinator = lazinator.CloneLazinatorTyped();
            var list = lazinator.MyStructList;

            lazinator.RemoveBufferInHierarchy();
            lazinator.LazinatorMemoryStorage.IsEmpty.Should().BeTrue();
            lazinator.MyStructList.LazinatorMemoryStorage.IsEmpty.Should().BeTrue();
            lazinator.MyStructList[0].WrappedValue.Should().Be(3);
        }
Beispiel #11
0
        public void LazinatorListDirtinessWorks()
        {
            LazinatorListContainer nonGenericContainer = new LazinatorListContainer()
            {
            };

            nonGenericContainer.MyList = new LazinatorList <ExampleChild>();
            nonGenericContainer.MyList.IsDirty.Should().BeTrue();
            nonGenericContainer.IsDirty.Should().BeTrue();
            nonGenericContainer.DescendantIsDirty.Should().BeTrue();

            var v2 = nonGenericContainer.CloneLazinatorTyped();

            v2.IsDirty.Should().BeFalse();
            v2.DescendantIsDirty.Should().BeFalse();
            v2.MyList.IsDirty.Should().BeFalse();
            v2.MyList.Add(GetExampleChild(1));
            v2.MyList.IsDirty.Should().BeTrue();
            v2.IsDirty.Should().BeFalse();
            v2.DescendantIsDirty.Should().BeTrue();

            var v3 = v2.CloneLazinatorTyped();

            v3.MyList.IsDirty.Should().BeFalse();
            v3.MyList.DescendantIsDirty.Should().BeFalse();
            v3.MyList[0].MyLong = 987654321;
            v3.MyList.IsDirty.Should().BeFalse();
            v3.MyList.DescendantIsDirty.Should().BeTrue();
            var v4 = v3.CloneLazinatorTyped();

            v4.MyList[0].MyLong.Should().Be(987654321);

            // now, back to prior list
            v2.MyList.Add(GetExampleChild(1));
            v2.MyList.Add(GetExampleChild(1));
            v2.MyList.Add(GetExampleChild(1));
            var v5 = v2.CloneLazinatorTyped();

            v5.IsDirty.Should().BeFalse();
            v5.DescendantIsDirty.Should().BeFalse();
            v5.MyList.IsDirty.Should().BeFalse();
            var x = v5.MyList[2];

            v5.MyList.IsDirty.Should().BeFalse();
            v5.MyList.DescendantIsDirty.Should().BeFalse();
            x.MyLong = 25;
            v5.MyList.IsDirty.Should().BeFalse();
            v5.MyList.DescendantIsDirty.Should().BeTrue();
            v5.IsDirty.Should().BeFalse();
            v5.DescendantIsDirty.Should().BeTrue();

            // attaching dirty item
            var v6     = v5.CloneLazinatorTyped();
            var v7     = v5.CloneLazinatorTyped();
            var v6item = v6.MyList[0];

            v6item.MyLong = 987654321;
            v6.DescendantIsDirty.Should().BeTrue();
            v6item.IsDirty.Should().BeTrue();
            v7.MyList[1] = v6item;
            v7.MyList.IsDirty.Should().BeTrue();
            v7.MyList.DescendantIsDirty.Should().BeTrue();
            v7.DescendantIsDirty.Should().BeTrue();

            // attaching item with dirty descendant
            v5.MyList[0].MyWrapperContainer = new WrapperContainer()
            {
                WrappedInt = 4
            };
            v6 = v5.CloneLazinatorTyped();
            v7 = v5.CloneLazinatorTyped();
            LazinatorUtilities.ConfirmMatch(v6.LazinatorMemoryStorage, v7.LazinatorMemoryStorage.GetConsolidatedMemory());
            v6item = v6.MyList[0];
            v6item.MyWrapperContainer.WrappedInt = 5;
            v6item.IsDirty.Should().BeFalse();
            v6item.DescendantIsDirty.Should().BeTrue();
            v6.DescendantIsDirty.Should().BeTrue();
            v7.MyList[1] = v6item;
            v7.MyList[1].IsDirty.Should().BeFalse();
            v7.MyList[1].DescendantIsDirty.Should().BeTrue();
            v7.MyList.IsDirty.Should().BeTrue();
            v7.MyList.DescendantIsDirty.Should().BeTrue();
            v7.DescendantIsDirty.Should().BeTrue();

            // attaching item with dirty descendant after fully deserializing
            v5.MyList[0].MyWrapperContainer = new WrapperContainer()
            {
                WrappedInt = 4
            };
            v6     = v5.CloneLazinatorTyped();
            v7     = v5.CloneLazinatorTyped();
            v6item = v6.MyList[0];
            v6item.MyWrapperContainer.WrappedInt = 5;
            v6item.IsDirty.Should().BeFalse();
            v6item.DescendantIsDirty.Should().BeTrue();
            v6.DescendantIsDirty.Should().BeTrue();
            v7.MyList.Insert(0, null);
            v7.MyList.SerializeLazinator();
            v7.MyList.IsDirty.Should().BeFalse();
            v7.MyList.DescendantIsDirty.Should().BeFalse();
            v7.MyList[1] = v6item;
            v7.MyList[1].IsDirty.Should().BeFalse();
            v7.MyList[1].DescendantIsDirty.Should().BeTrue();
            v7.MyList.DescendantIsDirty.Should().BeTrue();
            v7.DescendantIsDirty.Should().BeTrue();
        }
Beispiel #12
0
        public void LazinatorListWorks(ContainerForLazinatorList containerOption, bool cloneAfterEachStep)
        {
            LazinatorListContainer nonGenericContainer = new LazinatorListContainer()
            {
            };
            LazinatorListContainerGeneric <ExampleChild> genericContainer = new LazinatorListContainerGeneric <ExampleChild>()
            {
            };
            LazinatorList <ExampleChild> withoutContainer = null;

            LazinatorList <ExampleChild> GetList()
            {
                switch (containerOption)
                {
                case ContainerForLazinatorList.NoContainer:
                    return(withoutContainer);

                case ContainerForLazinatorList.NonGenericContainer:
                    return(nonGenericContainer.MyList);

                case ContainerForLazinatorList.GenericContainer:
                    return(genericContainer.MyList);
                }
                throw new NotImplementedException();
            }

            void SetList(LazinatorList <ExampleChild> value)
            {
                switch (containerOption)
                {
                case ContainerForLazinatorList.NoContainer:
                    withoutContainer = value;
                    break;

                case ContainerForLazinatorList.NonGenericContainer:
                    nonGenericContainer.MyList = value;
                    break;

                case ContainerForLazinatorList.GenericContainer:
                    genericContainer.MyList = value;
                    break;
                }
            }

            SetList(new LazinatorList <ExampleChild>()
            {
            });

            LazinatorList <ExampleChild> list = new LazinatorList <ExampleChild>();

            for (int i = 0; i <= 3; i++)
            {
                AddItem(i);
                list.IsDirty.Should().BeTrue();
            }
            void AddItem(int i, int?insertIndex = null)
            {
                if (insertIndex is int insertIndexInt)
                {
                    GetList().Insert(insertIndexInt, GetExampleChild(i));
                    list.Insert(insertIndexInt, GetExampleChild(i));
                }
                else
                {
                    GetList().Add(GetExampleChild(i));
                    list.Add(GetExampleChild(i));
                }
            }

            void RemoveItem(int i, bool useRemoveAt)
            {
                if (useRemoveAt)
                {
                    GetList().RemoveAt(i);
                    list.RemoveAt(i);
                }
                else
                {
                    var item = GetList()[i];
                    GetList().Remove(item);
                    list.RemoveAt(i); // not testing this, so can just do this
                }
            }

            void Clear()
            {
                GetList().Clear();
                list.Clear();
                list.IsDirty.Should().BeTrue();
            }

            void CheckList()
            {
                for (int i = 0; i < list.Count; i++)
                {
                    var currentListItem = GetList()[i];
                    if (currentListItem == null)
                    {
                        list[i].Should().Be(null);
                    }
                    else
                    {
                        ExampleChildEqual(currentListItem, list[i]).Should().BeTrue();
                    }
                }
                // now check another way, using enumerables
                var zipped = GetList().Zip(list, (a, b) => (a, b));

                foreach (var zip in zipped)
                {
                    ExampleChildEqual(zip.a, zip.b).Should().BeTrue();
                }
            }

            void CloneList()
            {
                switch (containerOption)
                {
                case ContainerForLazinatorList.NoContainer:
                    SetList(GetList().CloneLazinatorTyped());
                    break;

                case ContainerForLazinatorList.NonGenericContainer:
                    nonGenericContainer = nonGenericContainer.CloneLazinatorTyped();
                    break;

                case ContainerForLazinatorList.GenericContainer:
                    genericContainer = genericContainer.CloneLazinatorTyped();
                    break;
                }
            }

            void CheckBeforeAndAfterSerialization()
            {
                CheckList();
                CloneList();
                CheckList();
                if (cloneAfterEachStep)
                {
                    CloneList();
                }
            }

            CheckBeforeAndAfterSerialization();
            CheckBeforeAndAfterSerialization(); // do it again
            AddItem(1);
            CheckBeforeAndAfterSerialization();
            AddItem(0);
            CheckBeforeAndAfterSerialization();
            AddItem(2, 1);
            CheckBeforeAndAfterSerialization();
            AddItem(0, 0);
            CheckBeforeAndAfterSerialization();
            RemoveItem(3, true);
            CheckBeforeAndAfterSerialization();
            RemoveItem(3, false);
            CheckBeforeAndAfterSerialization();
            RemoveItem(0, false);
            CheckBeforeAndAfterSerialization();
            RemoveItem(0, true);
            CheckBeforeAndAfterSerialization();
            Clear();
            CheckBeforeAndAfterSerialization();
        }