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); }
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] */ }
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 }
public void CreateChild() { if (IsDisposed) { return; } // Auto-adds itself! var child = new ExampleChild(this); }
/// <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); }
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)); }
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); }
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); }
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); }
public void Update(ExampleChild entity) { this._context.Update(entity); }
public void Create(ExampleChild entity) { this._context.Create(entity); }
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); }
protected bool Equals(ExampleChild other) { return(_MyLong == other._MyLong && _MyShort == other._MyShort); }