public LazinatorStack(LazinatorMemory serializedBytes, ILazinator parent = null, IncludeChildrenMode originalIncludeChildrenMode = IncludeChildrenMode.IncludeAllChildren, int?lazinatorObjectVersion = null) { if (lazinatorObjectVersion != null) { LazinatorObjectVersion = (int)lazinatorObjectVersion; } OriginalIncludeChildrenMode = originalIncludeChildrenMode; LazinatorParents = new LazinatorParentsCollection(parent); DeserializeLazinator(serializedBytes); HasChanged = false; DescendantHasChanged = false; }
public ContainerForNullableStructInAnotherNamespace(LazinatorMemory serializedBytes, ILazinator parent = null, IncludeChildrenMode originalIncludeChildrenMode = IncludeChildrenMode.IncludeAllChildren, int?lazinatorObjectVersion = null) { if (lazinatorObjectVersion != null) { LazinatorObjectVersion = (int)lazinatorObjectVersion; } OriginalIncludeChildrenMode = originalIncludeChildrenMode; LazinatorParents = new LazinatorParentsCollection(parent); DeserializeLazinator(serializedBytes); HasChanged = false; DescendantHasChanged = false; }
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); }