private void VerifyWriteTreeWithNodeAtOffset(IDataNode node, TreeWithNodeAtOffset.Class value, uint originalPosition, uint offsetPosition) { node.Write(binaryWriter, value); (node.Edges[0].ChildNode as IOffsetNode).Write(binaryWriter, value.ValueAtOffset); (node.Edges[1].ChildNode as IDataNode).Write(binaryWriter, value.ValueInline); VerifyBinaryWriterWritesOffset(originalPosition, offsetPosition); (node.Edges[0].ChildNode as IOffsetNode).ChildNode.Write(binaryWriter, value.ValueAtOffset); }
private void SetupTreeWithNodeAtOffset(IDataNode node, TreeWithNodeAtOffset.Class expected, uint offset) { node.Read(binaryReader).Returns(_ => new TreeWithNodeAtOffset.Class()); IOffsetNode offsetNode = node.Edges[0].ChildNode as IOffsetNode; offsetNode.ReadOffset(binaryReader).Returns(offset); offsetNode.ChildNode.Read(binaryReader).Returns(expected.ValueAtOffset); (node.Edges[1].ChildNode as IDataNode).Read(binaryReader).Returns(expected.ValueInline); }
public void Test_Writing_An_Instance_Of_A_Tree_With_A_Node_At_A_Large_Offset() { long originalPosition = (long)uint.MaxValue + 1; IDataNode rootNode = TreeWithNodeAtOffset.Build(); TreeWithNodeAtOffset.Class value = new TreeWithNodeAtOffset.Class { ValueAtOffset = "offset too large", ValueInline = 7 }; Action action = () => treeWriter.Write(binaryWriter, value, rootNode); binaryWriter.GetPosition().Returns(originalPosition); action.Should() .ThrowExactly <ArgumentException>() .WithMessage($"Offset 0x{originalPosition:X} is larger than {sizeof(uint)} bytes."); binaryWriter.DidNotReceive().WriteUInt32(Arg.Any <uint>()); }
public void Test_Reading_An_Instance_Of_A_Tree_With_A_Node_At_Offset() { uint originalPosition = 27, offset = 15; IDataNode rootNode = TreeWithNodeAtOffset.Build(); TreeWithNodeAtOffset.Class expected = new TreeWithNodeAtOffset.Class { ValueAtOffset = "value", ValueInline = 54 }; binaryReader.GetPosition().Returns(originalPosition); SetupTreeWithNodeAtOffset(rootNode, expected, offset); object result = treeReader.Read(binaryReader, rootNode); Received.InOrder(() => VerifyReadTreeWithNodeAtOffset(rootNode, originalPosition, offset)); result.Should().BeEquivalentTo(expected); }
public void Test_Writing_An_Instance_Of_A_Tree_With_A_Node_At_Offset() { uint originalPosition = 43, offset = 15; IDataNode rootNode = TreeWithNodeAtOffset.Build(); TreeWithNodeAtOffset.Class value = new TreeWithNodeAtOffset.Class { ValueAtOffset = "value", ValueInline = 54 }; binaryWriter.GetPosition().Returns(originalPosition); (rootNode.Edges[0].ChildNode as IOffsetNode) .Write(binaryWriter, Arg.Any <object>()) .Returns(offset); treeWriter.Write(binaryWriter, value, rootNode) .Should() .Equal(offset); Received.InOrder(() => VerifyWriteTreeWithNodeAtOffset(rootNode, value, originalPosition, offset)); }