Beispiel #1
0
        public void LazinatorTuple()
        {
            LazinatorTuple <WInt32, WString> item =
                new LazinatorTuple <WInt32, WString>(5, "hello");
            var clone = item.CloneLazinatorTyped();

            clone.Item1.WrappedValue.Should().Be(5);
            clone.Item2.WrappedValue.Should().Be("hello");
        }
Beispiel #2
0
        public void TopNodesComparisonWorks()
        {
            ExampleChild c1 = new ExampleChild()
            {
                MyShort = 3
            };
            ExampleChild c2 = new ExampleChild()
            {
                MyShort = 3
            };

            LazinatorUtilities.TopNodesOfHierarchyEqual(c1, c2, out string comparison).Should().BeTrue();
            c2.MyShort = 5;
            LazinatorUtilities.TopNodesOfHierarchyEqual(c1, c2, out comparison).Should().BeFalse();

            LazinatorTuple <ExampleChild, ExampleChild> e1 = new LazinatorTuple <ExampleChild, ExampleChild>()
            {
                Item1 = new ExampleChild()
                {
                    MyWrapperContainer = new WrapperContainer()
                    {
                        WrappedInt = 3
                    }
                },
                Item2 = null
            };
            var e2 = e1.CloneLazinatorTyped();

            LazinatorUtilities.TopNodesOfHierarchyEqual(e1, e2, out comparison).Should().BeTrue();
            e2.Item1.MyWrapperContainer.WrappedInt = 5;
            LazinatorUtilities.TopNodesOfHierarchyEqual(e1, e2, out comparison).Should().BeTrue(); // top node is still equal

            LazinatorList <ExampleChild> l1 = new LazinatorList <ExampleChild>()
            {
                new ExampleChild()
                {
                    MyWrapperContainer = new WrapperContainer()
                    {
                        WrappedInt = 3
                    }
                }
            };
            LazinatorList <ExampleChild> l2 = new LazinatorList <ExampleChild>()
            {
                new ExampleChild()
                {
                    MyWrapperContainer = new WrapperContainer()
                    {
                        WrappedInt = 6
                    }
                }
            };

            LazinatorUtilities.TopNodesOfHierarchyEqual(l1, l2, out comparison).Should().BeTrue();
            l2.Add(null);
            LazinatorUtilities.TopNodesOfHierarchyEqual(l1, l2, out comparison).Should().BeFalse(); // number of elements differs
        }
Beispiel #3
0
        public void ParentSetForDefaultItem()
        {
            LazinatorTuple <WInt32, WInt32> e = new LazinatorTuple <WInt32, WInt32>()
            {
                Item1 = 0
            };

            e.Item1.LazinatorParents.LastAdded.Should().Be(e);
            e.Item2.LazinatorParents.LastAdded.Should().Be(e);
        }
Beispiel #4
0
        public void DirtinessNotificationOccursWithClassAsGeneric()
        {
            LazinatorTuple <ExampleChild, ExampleChild> e = new LazinatorTuple <ExampleChild, ExampleChild>
                                                            (
                new ExampleChild()
            {
                MyShort = 23
            },
                new ExampleChild()
            {
                MyShort = 24
            }
                                                            );
            var c = e.CloneLazinatorTyped();

            c.Item1 = new ExampleChild()
            {
                MyShort = 25
            };
            c.IsDirty.Should().BeTrue();

            e = new LazinatorTuple <ExampleChild, ExampleChild>
                (
                new ExampleChild()
            {
                MyShort = 23
            },
                new ExampleChild()
            {
                MyShort = 24
            }
                );
            c = e.CloneLazinatorTyped();
            c.IsDirty.Should().BeFalse();

            e = new LazinatorTuple <ExampleChild, ExampleChild>
                (
                new ExampleChild()
            {
                MyShort = 23
            },
                new ExampleChild()
            {
                MyShort = 24
            }
                );
            c = e.CloneLazinatorTyped();
            c.Item1.MyShort = 25;
            c.IsDirty.Should().BeFalse();
            c.DescendantIsDirty.Should().BeTrue();
        }
Beispiel #5
0
        public void SameObjectCanAppearTwice()
        {
            LazinatorTuple <ExampleChild, ExampleChild> e = new LazinatorTuple <ExampleChild, ExampleChild>()
            {
                Item1 = new ExampleChild(),
                Item2 = new ExampleChild()
            };
            var c = e.CloneLazinatorTyped();

            c.Item2.MyLong = -123456;
            c.Item1        = c.Item2;
            var c2 = c.CloneLazinatorTyped();

            c2.Item1.MyLong.Should().Be(-123456);
            c2.Item2.MyLong.Should().Be(-123456);
        }
Beispiel #6
0
        public void GetRootsAndAncestors()
        {
            LazinatorTuple <ExampleChild, ExampleChild> e1 = new LazinatorTuple <ExampleChild, ExampleChild>()
            {
                Item1 = new ExampleChild()
                {
                    MyWrapperContainer = new WrapperContainer()
                    {
                        WrappedInt = 3
                    }
                },
                Item2 = null
            };
            var startingPoint = e1.Item1.MyWrapperContainer.WrappedInt;

            startingPoint.GetSoleRoot().Should().Be(e1);
            startingPoint.GetPrincipalRoot().Should().Be(e1);
            startingPoint.GetSoleClosestAncestorOfType <LazinatorTuple <ExampleChild, ExampleChild> >().Should().Be(e1);
            var closestAncestors = startingPoint.GetAllClosestAncestorsOfType <LazinatorTuple <ExampleChild, ExampleChild> >().ToList();

            closestAncestors.Count().Should().Be(1);
            closestAncestors[0].Should().Be(e1);

            LazinatorTuple <ExampleChild, ExampleChild> e2 = new LazinatorTuple <ExampleChild, ExampleChild>()
            {
                Item1 = null,
                Item2 = e1.Item1
            };

            startingPoint = e2.Item2.MyWrapperContainer.WrappedInt;
            var roots = startingPoint.GetAllRoots().ToList();

            roots.Count().Should().Be(2);
            roots[0].Should().Be(e2);
            roots[1].Should().Be(e1);
            startingPoint.GetAllClosestAncestorsOfType <LazinatorTuple <ExampleChild, ExampleChild> >();
            closestAncestors = startingPoint.GetAllClosestAncestorsOfType <LazinatorTuple <ExampleChild, ExampleChild> >().ToList();
            closestAncestors.Count().Should().Be(2);
            closestAncestors[0].Should().Be(e2);
            closestAncestors[1].Should().Be(e1);
            Action a = () => { var result = startingPoint.GetSoleClosestAncestorOfType <LazinatorTuple <ExampleChild, ExampleChild> >(); };

            a.Should().Throw <Exception>();

            e1.GetSoleClosestAncestorOfType <LazinatorTuple <ExampleChild, ExampleChild> >().Should().Be(null); // don't count node itself
        }
Beispiel #7
0
        public void ChangeAfterCopyingAffectsSource()
        {
            LazinatorTuple <ExampleChild, ExampleChild> e = new LazinatorTuple <ExampleChild, ExampleChild>()
            {
                Item1 = new ExampleChild(),
                Item2 = new ExampleChild()
                {
                    MyLong = -123456
                }
            };
            var c  = e.CloneLazinatorTyped();
            var c2 = e.CloneLazinatorTyped();

            c.Item1         = c2.Item2;
            c2.Item2.MyLong = 543;
            var c3 = c2.CloneLazinatorTyped();

            c3.Item2.MyLong.Should().Be(543);
        }
Beispiel #8
0
        public void ChangeToObjectAppearingTwiceAffectsBoth()
        {
            LazinatorTuple <ExampleChild, ExampleChild> e = new LazinatorTuple <ExampleChild, ExampleChild>()
            {
                Item1 = new ExampleChild(),
                Item2 = new ExampleChild()
                {
                    MyLong = -123456
                }
            };
            var c = e.CloneLazinatorTyped();

            c.Item1        = c.Item2;
            c.Item1.MyLong = -987;
            var c2 = c.CloneLazinatorTyped();

            c2.Item1.MyLong.Should().Be(-987);
            c2.Item2.MyLong.Should().Be(-987);
        }
Beispiel #9
0
        public void ParentRemovedWhenObjectDetached()
        {
            LazinatorTuple <ExampleChild, ExampleChild> e = new LazinatorTuple <ExampleChild, ExampleChild>()
            {
                Item1 = new ExampleChild(),
                Item2 = new ExampleChild()
                {
                    MyLong = -123456
                }
            };
            var c         = e.CloneLazinatorTyped();
            var item1Orig = c.Item1;

            item1Orig.LazinatorParents.Count.Should().Be(1);
            c.Item1 = new ExampleChild();
            item1Orig.LazinatorParents.Count.Should().Be(0);

            // same thing, but going from two parents to 1
            e = new LazinatorTuple <ExampleChild, ExampleChild>()
            {
                Item1 = new ExampleChild(),
                Item2 = new ExampleChild()
                {
                    MyLong = -123456
                }
            };
            var e2 = new LazinatorTuple <ExampleChild, ExampleChild>()
            {
                Item1 = new ExampleChild(),
                Item2 = new ExampleChild()
                {
                    MyLong = -123456
                }
            };

            c         = e.CloneLazinatorTyped();
            e2.Item1  = c.Item1;
            item1Orig = c.Item1;
            item1Orig.LazinatorParents.Count.Should().Be(2);
            c.Item1 = new ExampleChild();
            item1Orig.LazinatorParents.Count.Should().Be(1);
        }
Beispiel #10
0
        public void ChangeToObjectInTwoHierarchiesAffectsBoth()
        {
            LazinatorTuple <ExampleChild, ExampleChild> e = new LazinatorTuple <ExampleChild, ExampleChild>()
            {
                Item1 = new ExampleChild(),
                Item2 = new ExampleChild()
                {
                    MyLong = -123456
                }
            };
            var c = e.CloneLazinatorTyped();

            c.Item1 = e.Item1;
            c.Item1.LazinatorParents.Count.Should().Be(2);
            c.Item1.MyLong = 101;
            var c2 = c.CloneLazinatorTyped();
            var c3 = e.CloneLazinatorTyped();

            c2.Item1.MyLong.Should().Be(101);
            c3.Item1.MyLong.Should().Be(101);
        }
Beispiel #11
0
        public void ParentsWorksWithGenericStruct()
        {
            LazinatorTuple <WInt32, WInt32> e = new LazinatorTuple <WInt32, WInt32>()
            {
                Item1 = new WInt32(1),
                Item2 = new WInt32(2)
            };

            e.Item1.LazinatorParents.LastAdded.Should().Be(e);
            var c = e.CloneLazinatorTyped();
            var d = e.CloneLazinatorTyped();

            d.Item1 = c.Item2;
            d.Item1.LazinatorParents.Count.Should().Be(1);
            d.Item1.LazinatorParents.LastAdded.Should().Be(d);
            d.Item2.LazinatorParents.Count.Should().Be(1);
            d.Item2.LazinatorParents.LastAdded.Should().Be(d);
            c.Item1.LazinatorParents.Count.Should().Be(1);
            c.Item1.LazinatorParents.LastAdded.Should().Be(c);
            c.Item2.LazinatorParents.Count.Should().Be(1);
            c.Item2.LazinatorParents.LastAdded.Should().Be(c);
        }
Beispiel #12
0
        public void DirtinessWithOpenGenericStructChild()
        {
            LazinatorTuple <WInt32, WInt32> e = new LazinatorTuple <WInt32, WInt32>
            {
                Item1 = 3,
                Item2 = 4
            };

            e.Item1.IsDirty.Should().BeTrue();
            e.DescendantIsDirty.Should().BeTrue();

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

            // consider original, which should be clean
            e.IsDirty.Should().BeFalse();
            e.DescendantIsDirty.Should().BeFalse();
            e.Item1.IsDirty.Should().BeFalse();
            // now consider clone
            c.IsDirty.Should().BeFalse();
            c.DescendantIsDirty.Should().BeFalse();
            c.Item1.IsDirty.Should().BeFalse();
        }
Beispiel #13
0
        public void DirtinessNotificationOccursWithStructAsGeneric()
        {
            LazinatorTuple <ExampleStructContainingClasses, ExampleStructContainingClasses> e = new LazinatorTuple <ExampleStructContainingClasses, ExampleStructContainingClasses>
                                                                                                (
                new ExampleStructContainingClasses()
            {
                MyChar = 'B'
            },
                new ExampleStructContainingClasses()
            {
                MyChar = 'C'
            }
                                                                                                );
            var c = e.CloneLazinatorTyped();

            c.Item1 = new ExampleStructContainingClasses()
            {
                MyChar = 'A'
            };
            c.IsDirty.Should().BeTrue();
        }
Beispiel #14
0
        public void DirtinessNotificationOccursWithStructAsGeneric_ChangingFromDefault()
        {
            LazinatorTuple <ExampleStructContainingClasses, ExampleStructContainingClasses> e = new LazinatorTuple <ExampleStructContainingClasses, ExampleStructContainingClasses>();
            var c = e.CloneLazinatorTyped();

            c.Item1 = new ExampleStructContainingClasses()
            {
                MyChar = 'A'
            };                                                               // because Item1 is set, IsDirty notification occurs
            c.IsDirty.Should().BeTrue();

            // The following code is invalid and thus doesn't present a problem.
            //e = new LazinatorTuple<ExampleStructContainingClasses, ExampleStructContainingClasses>();
            //c = e.CloneLazinatorTyped();
            //c.Item1.MyChar = 'A' ; // INVALID -- can't change MyChar b/c Item1 is a struct. Instead, we would do c.Item1 = c.Item1 { MyChar = 'A' }, which works as above
            //c.IsDirty.Should().BeTrue();
        }