Пример #1
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);
        }
Пример #2
0
        private static void Setup()
        {
            // The root "menu"
            var root = new SuperParent("Root");

            // A normal Menu
            var comboParent = new Parent("Combo");

            comboParent.Switch = new BoolSwitch(comboParent.Menu, "Disabled", false, comboParent);

            // 2 children containing the same logic
            var child  = new ExampleChild("Child");
            var child2 = new ExampleChild("Child2");

            /* "Connects" each composition element
             *
             * compositionElement.AddChild(compositionElement)
             *
             */

            root.Add(comboParent);

            comboParent.Add(child);
            comboParent.Add(child2);

            /* Example Output:
             * Root > Combo            > Child            > Enabled [On/Off]
             *        Enabled [On/Off]   Child2           > Enabled [On/Off]
             *                           Enabled [On/Off]
             */
        }
Пример #3
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
        }
Пример #4
0
 public void CreateChild()
 {
     if (IsDisposed)
     {
         return;
     }
     // Auto-adds itself!
     var child = new ExampleChild(this);
 }
Пример #5
0
        /// <summary>
        /// Returns a list of siblings.
        ///
        /// Requires Includes:
        /// * Parent
        ///   * Children
        /// </summary>
        /// <param name="child">Self</param>
        /// <returns>List<ExampleChild></returns>
        public static List <ExampleChild> GetSiblings(this ExampleChild child)
        {
            if (child.Parent == null)
            {
                throw new ArgumentException("Missing Include Parent");
            }

            var siblings = child.Parent.Children.Where(c => c.Id != child.Id).ToList();

            return(siblings);
        }
            public async Task <int> Handle(CreateExampleChildCommand request, CancellationToken cancellationToken)
            {
                var exampleEntity = new ExampleChild
                {
                    Name     = request.Child.Name,
                    Type     = request.Child.Type,
                    ParentId = request.Child.ParentId,
                };

                _context.ExampleChildren.Add(exampleEntity);

                await _context.SaveChangesAsync(cancellationToken);

                return(exampleEntity.Id);
            }
Пример #7
0
        public async Task SaveChangesAsync_GivenNewTodoItem_ShouldSetCreatedProperties()
        {
            var item = new ExampleChild
            {
                Id   = 2,
                Name = "Test2",
                Type = ExampleEnum.Youngest
            };

            _context.ExampleChildren.Add(item);

            await _context.SaveChangesAsync();

            item.Created.Should().Be(_dateTimeOffset);
            item.CreatedBy.Should().Be(_userId);
        }
        public ActionResult Create(ExampleChildViewModel model)
        {
            if (ModelState.IsValid)
            {
                var child = new ExampleChild()
                {
                    Name     = model.Name,
                    ParentId = model.ParentId
                };

                _exampleChildrensRepository.Create(child);

                return(List(model.ParentId));
            }

            return(View(model));
        }
Пример #9
0
 public void OutputFormatSingleTest()
 {
     var exl = new ExampleChild
     {
         BaseId = 1,
         BaseTitle = "Base element",
         Amount = 23.5439,
         ChildId = 11,
         Complex = new ExampleComplex { Title = "Antoni", Value = 7 }
     };
     IOutputFormat formatter = new TextOutputFormat();
     var result = formatter.FormatSingle(exl);
     var expected = "Base ID: 1" + Environment.NewLine +
                    "Base title: Base element" + Environment.NewLine +
                    "Inner ID: 11" + Environment.NewLine +
                    "Amount: 23,54 zł" + Environment.NewLine +
                    "Complex:" + Environment.NewLine + "Antoni: 7,00";
     Assert.Equal(expected, result);
 }
Пример #10
0
        internal bool ExampleChildEqual(ExampleChild child1, ExampleChild child2)
        {
            if (child1 == null && child2 == null)
            {
                return(true);
            }
            if ((child1 == null) != (child2 == null))
            {
                return(false);
            }
            if ((child1 is ExampleChildInherited) != (child2 is ExampleChildInherited))
            {
                return(false);
            }
            bool basicFieldsEqual     = (child1.MyLong == child2.MyLong && child1.MyShort == child2.MyShort && child1.ByteSpan.ToArray().SequenceEqual(child2.ByteSpan.ToArray()));
            bool inheritedFieldsEqual = !(child1 is ExampleChildInherited child1Inherited) || child1Inherited.MyInt == ((ExampleChildInherited)child2).MyInt;

            return(basicFieldsEqual && inheritedFieldsEqual);
        }
Пример #11
0
        public void LazinatorListParentItemsWorks()
        {
            LazinatorList <ExampleChild> e = new LazinatorList <ExampleChild>();
            var child = new ExampleChild();

            e.Add(child);
            child.LazinatorParents.LastAdded.Should().Be(e);
            e.Add(child);
            child.LazinatorParents.LastAdded.Should().Be(e);
            e[0] = null;
            child.LazinatorParents.LastAdded.Should().Be(e);
            e[1] = null;
            child.LazinatorParents.Count.Should().Be(0);

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

            e.Add(child);
            e2.Add(child);
            child.LazinatorParents.Count.Should().Be(2);
            e2[0] = null;
            child.LazinatorParents.Count.Should().Be(1);
        }
Пример #12
0
 public void Update(ExampleChild entity)
 {
     this._context.Update(entity);
 }
Пример #13
0
 public void Create(ExampleChild entity)
 {
     this._context.Create(entity);
 }
Пример #14
0
        public void LazinatorParentsCollectionWorks()
        {
            ExampleChild e1 = new ExampleChild();
            Example      e2 = new Example();
            ExampleChild e3 = new ExampleChild();

            LazinatorParentsCollection c = new LazinatorParentsCollection();

            c.Count.Should().Be(0);
            c.Any().Should().BeFalse();
            c.LastAdded.Should().BeNull();
            c.EnumerateParents().Count().Should().Be(0);

            c = c.WithAdded(e1);
            c.Count.Should().Be(1);
            c.Any().Should().BeTrue();
            c.LastAdded.Should().Be(e1);
            c.EnumerateParents().SequenceEqual(new ILazinator[] { e1 }).Should().BeTrue();

            c = c.WithAdded(e1); // added a second time
            c.Count.Should().Be(1);
            c.Any().Should().BeTrue();
            c.LastAdded.Should().Be(e1);
            c.EnumerateParents().SequenceEqual(new ILazinator[] { e1 }).Should().BeTrue();

            c = c.WithRemoved(e1);
            c.Count.Should().Be(1);
            c.Any().Should().BeTrue();
            c.LastAdded.Should().Be(e1);
            c.EnumerateParents().SequenceEqual(new ILazinator[] { e1 }).Should().BeTrue();

            c = c.WithRemoved(e1);
            c.Count.Should().Be(0);
            c.Any().Should().BeFalse();
            c.LastAdded.Should().BeNull();
            c.EnumerateParents().Count().Should().Be(0);

            c = c.WithAdded(e1).WithAdded(e2);
            c.Count.Should().Be(2);
            c.Any().Should().BeTrue();
            c.LastAdded.Should().Be(e2);
            c.EnumerateParents().SequenceEqual(new ILazinator[] { e2, e1 }).Should().BeTrue();

            c = c.WithAdded(e3);
            c.Count.Should().Be(3);
            c.Any().Should().BeTrue();
            c.LastAdded.Should().Be(e3);
            c.EnumerateParents().Count().Should().Be(3);

            c = c.WithRemoved(e3);
            c.Count.Should().Be(2);
            c.Any().Should().BeTrue();
            c.LastAdded.Should().Be(null);
            c.EnumerateParents().Count().Should().Be(2);

            c = c.WithAdded(e2);
            c.Count.Should().Be(2); // e2 only counts 1 time
            c.Any().Should().BeTrue();
            c.LastAdded.Should().Be(e2);
            c.EnumerateParents().SequenceEqual(new ILazinator[] { e2, e1 }).Should().BeTrue();

            c = c.WithRemoved(e2);
            c.Count.Should().Be(2);      // e2 only counts 1 time
            c.Any().Should().BeTrue();
            c.LastAdded.Should().Be(e2); // still listed as LastAdded
            c.EnumerateParents().Count().Should().Be(2);

            c = c.WithRemoved(e2).WithRemoved(e1);
            c.Count.Should().Be(0);
            c.Any().Should().BeFalse();
            c.LastAdded.Should().Be(null);
            c.EnumerateParents().Count().Should().Be(0);
        }
Пример #15
0
 protected bool Equals(ExampleChild other)
 {
     return(_MyLong == other._MyLong && _MyShort == other._MyShort);
 }