public void Test_Reading_An_Instance_Of_A_Tree_With_Nested_Empty_Lists() { uint offsetPosition1 = 20, offsetPosition2 = 30; IDataNode rootNode = TreeWithNestedLists.Build(); TreeWithNestedLists.Class expected = new TreeWithNestedLists.Class { List1 = new List <TreeWithHeight1.Class> { }, List2 = new List <TreeWithHeight2.Class> { } }; SetupTreeWithNestedLists(rootNode, expected, offsetPosition1, offsetPosition2); object result = treeReader.Read(binaryReader, rootNode); binaryReader.DidNotReceive().GetPosition(); Received.InOrder(() => VerifyReadTreeWithNestedLists(rootNode)); result.Should().BeEquivalentTo(expected); }
private void VerifyWriteTreeWithNestedLists( IDataNode node, TreeWithNestedLists.Class value, uint originalPosition1, uint originalPosition2, uint offsetPosition1, uint offsetPosition2 ) { node.Write(binaryWriter, value); IListNode listNode1 = node.Edges[0].ChildNode as IListNode; listNode1.Write(binaryWriter, value.List1); IListNode listNode2 = node.Edges[1].ChildNode as IListNode; listNode2.Write(binaryWriter, value.List2); VerifyBinaryWriterWritesOffset(originalPosition1, offsetPosition1); foreach (var entry in value.List1) { VerifyWriteTreeWithHeight1(listNode1.ChildNode, entry); } VerifyBinaryWriterWritesOffset(originalPosition2, offsetPosition2); foreach (var entry in value.List2) { VerifyWriteTreeWithHeight2(listNode2.ChildNode, entry); } }
private void VerifyReadTreeWithNestedLists( IDataNode node, TreeWithNestedLists.Class value, uint originalPosition1, uint originalPosition2, uint offsetPosition1, uint offsetPosition2 ) { node.Read(binaryReader); void verifyReadList <T>(IListNode listNode, IList <T> list, uint originalPosition, uint offset, Action <IDataNode> verifyReadValue) { listNode.ReadEntryCount(binaryReader); listNode.ReadOffset(binaryReader); binaryReader.VerifyDoAtPosition(originalPosition, offset, () => { foreach (var entry in list) { verifyReadValue(listNode.ChildNode); } }); } verifyReadList(node.Edges[0].ChildNode as IListNode, value.List1, originalPosition1, offsetPosition1, VerifyReadTreeWithHeight1); verifyReadList(node.Edges[1].ChildNode as IListNode, value.List2, originalPosition2, offsetPosition2, VerifyReadTreeWithHeight2); }
public void Test_Reading_An_Instance_Of_A_Tree_With_Nested_Lists() { uint originalPosition1 = 26, originalPosition2 = 38; uint offsetPosition1 = 20, offsetPosition2 = 30; IDataNode rootNode = TreeWithNestedLists.Build(); TreeWithNestedLists.Class expected = new TreeWithNestedLists.Class { List1 = new List <TreeWithHeight1.Class> { new TreeWithHeight1.Class { Int = 1, Float = 2.4f, Byte = 3 }, new TreeWithHeight1.Class { Int = 4, Float = 5.5f, Byte = 6 } }, List2 = new List <TreeWithHeight2.Class> { new TreeWithHeight2.Class { Long = 7, Child = new TreeWithHeight1.Class { Int = 8, Float = 9.6f, Byte = 10 } }, new TreeWithHeight2.Class { Long = 11, Child = new TreeWithHeight1.Class { Int = 12, Float = 13.7f, Byte = 14 } } } }; binaryReader.GetPosition().Returns(originalPosition1, originalPosition2); SetupTreeWithNestedLists(rootNode, expected, offsetPosition1, offsetPosition2); object result = treeReader.Read(binaryReader, rootNode); Received.InOrder(() => VerifyReadTreeWithNestedLists(rootNode, expected, originalPosition1, originalPosition2, offsetPosition1, offsetPosition2)); result.Should().BeEquivalentTo(expected); }
private void SetupTreeWithNestedLists(IDataNode node, TreeWithNestedLists.Class expected, uint offset1, uint offset2) { node.Read(binaryReader).Returns(_ => new TreeWithNestedLists.Class()); void setupListNode <T>(IListNode listNode, IList <T> expectedList, uint offset, Action <IDataNode, T, T[]> setupValues) { listNode.ReadEntryCount(binaryReader).Returns(expectedList.Count); listNode.ReadOffset(binaryReader).Returns(offset); if (expectedList.IsNotEmpty()) { setupValues(listNode.ChildNode, expectedList[0], expectedList.Skip(1).ToArray()); } } setupListNode(node.Edges[0].ChildNode as IListNode, expected.List1, offset1, SetupTreeWithHeight1); setupListNode(node.Edges[1].ChildNode as IListNode, expected.List2, offset2, SetupTreeWithHeight2); }
public void Test_Writing_An_Instance_Of_A_Tree_With_Nested_Empty_Lists() { uint originalPosition1 = 28, originalPosition2 = 39; uint offsetPosition1 = 20, offsetPosition2 = 30; IDataNode rootNode = TreeWithNestedLists.Build(); TreeWithNestedLists.Class value = new TreeWithNestedLists.Class { List1 = new List <TreeWithHeight1.Class> { }, List2 = new List <TreeWithHeight2.Class> { } }; IOffsetNode list1ChildNode = rootNode.Edges[0].ChildNode as IOffsetNode; list1ChildNode .Write(binaryWriter, Arg.Any <object>()) .Returns(offsetPosition1); IOffsetNode list2ChildNode = rootNode.Edges[1].ChildNode as IOffsetNode; list2ChildNode .Write(binaryWriter, Arg.Any <object>()) .Returns(offsetPosition2); binaryWriter.GetPosition().Returns(originalPosition1, originalPosition2); treeWriter.Write(binaryWriter, value, rootNode) .Should() .Equal(offsetPosition1, offsetPosition2); list1ChildNode.ChildNode.DidNotReceive().Write(binaryWriter, Arg.Any <object>()); list2ChildNode.ChildNode.DidNotReceive().Write(binaryWriter, Arg.Any <object>()); Received.InOrder(() => VerifyWriteTreeWithNestedLists(rootNode, value, originalPosition1, originalPosition2, offsetPosition1, offsetPosition2)); }
public void Test_Writing_An_Instance_Of_A_Tree_With_Nested_Lists() { uint originalPosition1 = 28, originalPosition2 = 39; uint offsetPosition1 = 20, offsetPosition2 = 30; IDataNode rootNode = TreeWithNestedLists.Build(); TreeWithNestedLists.Class value = new TreeWithNestedLists.Class { List1 = new List <TreeWithHeight1.Class> { new TreeWithHeight1.Class { Int = 1, Float = 2.4f, Byte = 3 }, new TreeWithHeight1.Class { Int = 4, Float = 5.5f, Byte = 6 } }, List2 = new List <TreeWithHeight2.Class> { new TreeWithHeight2.Class { Long = 7, Child = new TreeWithHeight1.Class { Int = 8, Float = 9.6f, Byte = 10 } }, new TreeWithHeight2.Class { Long = 11, Child = new TreeWithHeight1.Class { Int = 12, Float = 13.7f, Byte = 14 } } } }; (rootNode.Edges[0].ChildNode as IOffsetNode) .Write(binaryWriter, Arg.Any <object>()) .Returns(offsetPosition1); (rootNode.Edges[1].ChildNode as IOffsetNode) .Write(binaryWriter, Arg.Any <object>()) .Returns(offsetPosition2); binaryWriter.GetPosition().Returns(originalPosition1, originalPosition2); treeWriter.Write(binaryWriter, value, rootNode) .Should() .Equal(offsetPosition1, offsetPosition2); Received.InOrder(() => VerifyWriteTreeWithNestedLists(rootNode, value, originalPosition1, originalPosition2, offsetPosition1, offsetPosition2)); }