public async void ShouldReadRecordMessageReturningRelationship() { var fields = new object[0]; var mockInput = IOExtensions.CreateMockStream("00 0A b1 71 91 B5 52 01 02 03 80 a0 00 00"); var mockResponseHandler = new Mock <IMessageResponseHandler>(); mockResponseHandler.Setup(x => x.HandleRecordMessage(It.IsAny <object[]>())) .Callback <object[]>(x => fields = x); var reader = new BoltReader(mockInput.Object); await reader.ReadAsync(mockResponseHandler.Object); mockResponseHandler.Verify(x => x.HandleRecordMessage(It.IsAny <object[]>()), Times.Once); fields.Should().NotBeNull(); fields.Should().HaveCount(1); var rel = fields[0] as IRelationship; rel.Should().NotBeNull(); rel.Id.Should().Be(1); rel.StartNodeId.Should().Be(2); rel.EndNodeId.Should().Be(3); rel.Type.Should().BeEmpty(); rel.Properties.Should().BeEmpty(); }
public async void ShouldReadRecordMessageReturningPath() { var fields = new object[0]; var mockInput = IOExtensions.CreateMockStream("00 0d b1 71 91 B3 50 91 B3 4E 01 90 A0 90 90 00 00"); var mockResponseHandler = new Mock <IMessageResponseHandler>(); mockResponseHandler.Setup(x => x.HandleRecordMessage(It.IsAny <object[]>())) .Callback <object[]>(x => fields = x); var reader = new BoltReader(mockInput.Object); await reader.ReadAsync(mockResponseHandler.Object); mockResponseHandler.Verify(x => x.HandleRecordMessage(It.IsAny <object[]>()), Times.Once); fields.Should().NotBeNull(); fields.Should().HaveCount(1); var p = fields[0] as IPath; p.Should().NotBeNull(); p.Start.Should().NotBeNull(); p.End.Should().NotBeNull(); p.Start.Id.Should().Be(1); p.Start.Properties.Should().BeEmpty(); p.Start.Labels.Should().BeEmpty(); p.Nodes.Should().HaveCount(1); p.Relationships.Should().HaveCount(0); }
public void ShouldReadSuccessMessage() { var dict = (IDictionary <string, object>)null; var mockInput = IOExtensions.CreateMockStream("00 14 B1 70 A1 86 66 69 65 6C 64 73 92 84 6E 61 6D 65 83 61 67 65 00 00"); var mockResponseHandler = new Mock <IMessageResponseHandler>(); mockResponseHandler.Setup(x => x.HandleSuccessMessage(It.IsAny <IDictionary <string, object> >())) .Callback <IDictionary <string, object> >(x => dict = x); var reader = new BoltReader(mockInput.Object); reader.Read(mockResponseHandler.Object); mockResponseHandler.Verify(x => x.HandleSuccessMessage(It.IsAny <IDictionary <string, object> >()), Times.Once); dict.Should().NotBeNull(); dict.Should().HaveCount(1); dict.Should().ContainKey("fields"); var fieldsValue = dict["fields"]; fieldsValue.Should().NotBeNull(); fieldsValue.Should().BeAssignableTo <IList <object> >(); var fields = (IList <object>)fieldsValue; fields.Should().HaveCount(2); fields.Should().Contain("name"); fields.Should().Contain("age"); }
private void CreateReaderAndWriter(IPackStreamFactory packStreamFactory) { Reader = new BoltReader(_tcpSocketClient.ReadStream, _bufferSettings.DefaultReadBufferSize, _bufferSettings.MaxReadBufferSize, _logger, packStreamFactory); Writer = new BoltWriter(_tcpSocketClient.WriteStream, _bufferSettings.DefaultWriteBufferSize, _bufferSettings.MaxWriteBufferSize, _logger, packStreamFactory); }
public void ShouldReadRecordMessageReturningNode() { var fields = new object[0]; var mockInput = IOExtensions.CreateMockStream("00 08 b1 71 91 B3 4E 01 90 A0 00 00"); var mockResponseHandler = new Mock <IMessageResponseHandler>(); mockResponseHandler.Setup(x => x.HandleRecordMessage(It.IsAny <object[]>())) .Callback <object[]>(x => fields = x); var reader = new BoltReader(mockInput.Object); reader.Read(mockResponseHandler.Object); mockResponseHandler.Verify(x => x.HandleRecordMessage(It.IsAny <object[]>()), Times.Once); fields.Should().NotBeNull(); fields.Should().HaveCount(1); var n = fields[0] as INode; n.Should().NotBeNull(); n.Id.Should().Be(1); n.Properties.Should().BeEmpty(); n.Labels.Should().BeEmpty(); }
private void CreateReaderAndWriter(bool supportBytes = true) { Reader = new BoltReader(_tcpSocketClient.ReadStream, _bufferSettings.DefaultReadBufferSize, _bufferSettings.MaxReadBufferSize, _logger, supportBytes); Writer = new BoltWriter(_tcpSocketClient.WriteStream, _bufferSettings.DefaultWriteBufferSize, _bufferSettings.MaxWriteBufferSize, _logger, supportBytes); }
public void ShouldReadFailureMessage() { var mockInput = IOExtensions.CreateMockStream("00 47 B1 7F A2 84 63 6F 64 65 D0 25 4E 65 6F 2E 43 6C 69 65 6E 74 45 72 72 6F 72 2E 53 74 61 74 65 6D 65 6E 74 2E 53 79 6E 74 61 78 45 72 72 6F 72 87 6D 65 73 73 61 67 65 8F 49 6E 76 61 6C 69 64 20 73 79 6E 74 61 78 2E 00 00"); var mockResponseHandler = new Mock <IMessageResponseHandler>(); var reader = new BoltReader(mockInput.Object); reader.Read(mockResponseHandler.Object); mockResponseHandler.Verify(x => x.HandleFailureMessage("Neo.ClientError.Statement.SyntaxError", "Invalid syntax."), Times.Once); }
public BoltProtocolV2(ITcpSocketClient tcpSocketClient, BufferSettings bufferSettings, ILogger logger = null) { _tcpSocketClient = tcpSocketClient; _bufferSettings = bufferSettings; _logger = logger; Reader = new BoltReader(_tcpSocketClient.ReadStream, _bufferSettings.DefaultReadBufferSize, _bufferSettings.MaxReadBufferSize, _logger, BoltProtocolPackStream.V2); Writer = new BoltWriter(_tcpSocketClient.WriteStream, _bufferSettings.DefaultWriteBufferSize, _bufferSettings.MaxWriteBufferSize, _logger, BoltProtocolPackStream.V2); }
public async void ShouldReadMessageAsync() { var responseHandler = new Mock <IMessageResponseHandler>(); var reader = new BoltReader(new MemoryStream(CreateSuccessMessage()), CreatePackStreamFactory()); await reader.ReadAsync(responseHandler.Object); responseHandler.Verify( x => x.HandleSuccessMessage( It.Is <IDictionary <string, object> >(m => m.ContainsKey("x") && m["x"].Equals(1L))), Times.Once); }
public async void ShouldThrowWhenReadMessageIsNotAResponseMessageAsync() { var responseHandler = new Mock <IMessageResponseHandler>(); var reader = new BoltReader(new MemoryStream(CreateNodeMessage()), CreatePackStreamFactory()); var ex = await Record.ExceptionAsync(() => reader.ReadAsync(responseHandler.Object)); ex.Should().NotBeNull(); ex.Should().BeOfType <ProtocolException>().Subject.Message.Should().StartWith("Unknown response message type"); }
public void ShouldReadIgnoredMessage() { var mockInput = IOExtensions.CreateMockStream("00 02 B0 7E 00 00"); var mockResponseHandler = new Mock <IMessageResponseHandler>(); var reader = new BoltReader(mockInput.Object); reader.Read(mockResponseHandler.Object); mockResponseHandler.Verify(x => x.HandleIgnoredMessage(), Times.Once); }
public async void ShouldReadRecordMessageReturningNumberNodeRelationShipPath() { var fields = new object[0]; var mockInput = IOExtensions.CreateMockStream("00 1a b1 71 94 01 B3 4E 01 90 A0 B5 52 01 02 03 80 a0 B3 50 91 B3 4E 01 90 A0 90 90 00 00"); var mockResponseHandler = new Mock <IMessageResponseHandler>(); mockResponseHandler.Setup(x => x.HandleRecordMessage(It.IsAny <object[]>())) .Callback <object[]>(x => fields = x); var reader = new BoltReader(mockInput.Object); await reader.ReadAsync(mockResponseHandler.Object); mockResponseHandler.Verify(x => x.HandleRecordMessage(It.IsAny <object[]>()), Times.Once); fields.Should().NotBeNull(); fields.Should().HaveCount(4); var first = fields[0]; first.Should().NotBeNull(); first.Should().BeOfType <long>(); first.Should().Be(1L); var second = fields[1] as INode; second.Should().NotBeNull(); second.Id.Should().Be(1); second.Properties.Should().BeEmpty(); second.Labels.Should().BeEmpty(); var third = fields[2] as IRelationship; third.Should().NotBeNull(); third.Id.Should().Be(1); third.StartNodeId.Should().Be(2); third.EndNodeId.Should().Be(3); third.Type.Should().BeEmpty(); third.Properties.Should().BeEmpty(); var fourth = fields[3] as IPath; fourth.Should().NotBeNull(); fourth.Start.Should().NotBeNull(); fourth.End.Should().NotBeNull(); fourth.Start.Id.Should().Be(1); fourth.Start.Properties.Should().BeEmpty(); fourth.Start.Labels.Should().BeEmpty(); fourth.Nodes.Should().HaveCount(1); fourth.Relationships.Should().HaveCount(0); }
public async void ShouldResetCapacityWhenCapacityExceedsMaxBufferSizeAsync() { var dict = (IDictionary <string, object>)null; var mockInput = IOExtensions.CreateMockStream("00 14 B1 70 A1 86 66 69 65 6C 64 73 92 84 6E 61 6D 65 83 61 67 65 00 00"); var mockResponseHandler = new Mock <IMessageResponseHandler>(); mockResponseHandler.Setup(x => x.HandleSuccessMessage(It.IsAny <IDictionary <string, object> >())) .Callback <IDictionary <string, object> >(x => dict = x); var mockLogger = new Mock <ILogger>(); var reader = new BoltReader(mockInput.Object, 10, 15, mockLogger.Object, true); await reader.ReadAsync(mockResponseHandler.Object); mockLogger.Verify(x => x.Info(It.Is <string>(s => s.StartsWith("Shrinking read buffers to the default read buffer size"))), Times.Once); }
public void ShouldNotResetCapacityWhenCapacityDoesNotExceedMaxBufferSize() { var dict = (IDictionary <string, object>)null; var mockInput = IOExtensions.CreateMockStream("00 14 B1 70 A1 86 66 69 65 6C 64 73 92 84 6E 61 6D 65 83 61 67 65 00 00"); var mockResponseHandler = new Mock <IMessageResponseHandler>(); mockResponseHandler.Setup(x => x.HandleSuccessMessage(It.IsAny <IDictionary <string, object> >())) .Callback <IDictionary <string, object> >(x => dict = x); var mockLogger = new Mock <ILogger>(); var reader = new BoltReader(mockInput.Object, 256, 512, mockLogger.Object, true); reader.Read(mockResponseHandler.Object); mockLogger.Verify(x => x.Info(It.IsAny <string>(), It.IsAny <object[]>()), Times.Never); }
public async void ShouldThrowExceptionWhenMessageHasInvalidSignature() { var fields = new object[0]; var mockInput = IOExtensions.CreateMockStream("00 04 b1 95 91 01 00 00"); var mockResponseHandler = new Mock <IMessageResponseHandler>(); mockResponseHandler.Setup(x => x.HandleRecordMessage(It.IsAny <object[]>())) .Callback <object[]>(x => fields = x); var reader = new BoltReader(mockInput.Object); var ex = await Record.ExceptionAsync(() => reader.ReadAsync(mockResponseHandler.Object)); ex.Should().NotBeNull(); ex.Should().BeOfType <ProtocolException>(); }
public async void ShouldReadConsecutiveMessagesAsync() { var responseHandler = new Mock <IMessageResponseHandler>(); var stream = new MemoryStream(); for (var i = 0; i < 5; i++) { stream.Write(CreateSuccessMessage()); } var reader = new BoltReader(new MemoryStream(stream.ToArray()), CreatePackStreamFactory()); await reader.ReadAsync(responseHandler.Object); responseHandler.Verify( x => x.HandleSuccessMessage( It.Is <IDictionary <string, object> >(m => m.ContainsKey("x") && m["x"].Equals(1L))), Times.Exactly(5)); }
public void ShouldReadRecordMessageReturningNumber() { var fields = new object[0]; var mockInput = IOExtensions.CreateMockStream("00 04 b1 71 91 01 00 00"); var mockResponseHandler = new Mock <IMessageResponseHandler>(); mockResponseHandler.Setup(x => x.HandleRecordMessage(It.IsAny <object[]>())) .Callback <object[]>(x => fields = x); var reader = new BoltReader(mockInput.Object); reader.Read(mockResponseHandler.Object); mockResponseHandler.Verify(x => x.HandleRecordMessage(It.IsAny <object[]>()), Times.Once); fields.Should().NotBeNull(); fields.Should().HaveCount(1); fields.Should().Contain(1L); }
public void ShouldReadRecordMessageWithInnerStructs() { var fields = new object[0]; var mockInput = IOExtensions.CreateMockStream( "00 79 B1 71 92 B3 4E 02 91 86 50 65 72 73 6F 6E A1 84 6E 61 6D 65 81 63 92 A2 83 72 65 6C B5 52 03 02 05 84 4F 57 4E 53 A0 87 70 72 6F 64 75 63 74 B3 4E 05 91 87 50 72 6F 64 75 63 74 A1 84 6E 61 6D 65 84 69 70 6F 64 A2 83 72 65 6C B5 52 02 02 03 84 4F 57 4E 53 A0 87 70 72 6F 64 75 63 74 B3 4E 03 91 87 50 72 6F 64 75 63 74 A1 84 6E 61 6D 65 88 63 6F 6D 70 75 74 65 72 00 00"); var mockResponseHandler = new Mock <IMessageResponseHandler>(); mockResponseHandler.Setup(x => x.HandleRecordMessage(It.IsAny <object[]>())) .Callback <object[]>(x => fields = x); var reader = new BoltReader(mockInput.Object); reader.Read(mockResponseHandler.Object); mockResponseHandler.Verify(x => x.HandleRecordMessage(It.IsAny <object[]>()), Times.Once); fields.Should().NotBeNull(); fields.Should().HaveCount(2); fields[0].Should().BeAssignableTo <INode>(); fields[0].ValueAs <INode>().Labels.Should().Contain("Person"); fields[0].ValueAs <INode>().Properties.Keys.Should().Contain("name"); fields[0].ValueAs <INode>().Properties.Values.Should().Contain("c"); fields[1].Should().BeAssignableTo <IList>(); var el0 = ((IList)fields[1])[0]; el0.Should().BeAssignableTo <IDictionary <string, object> >(); el0.ValueAs <IDictionary <string, object> >().Should().ContainKey("rel"); var rel0 = el0.ValueAs <IDictionary <string, object> >()["rel"]; rel0.Should().BeAssignableTo <IRelationship>(); rel0.ValueAs <IRelationship>().Type.Should().Be("OWNS"); rel0.ValueAs <IRelationship>().StartNodeId.Should().Be(2L); rel0.ValueAs <IRelationship>().EndNodeId.Should().Be(5L); rel0.ValueAs <IRelationship>().Properties.Should().BeEmpty(); el0.ValueAs <IDictionary <string, object> >().Should().ContainKey("product"); var prod0 = el0.ValueAs <IDictionary <string, object> >()["product"]; prod0.Should().BeAssignableTo <INode>(); prod0.ValueAs <INode>().Labels.Should().Contain("Product"); prod0.ValueAs <INode>().Properties.Keys.Should().Contain("name"); prod0.ValueAs <INode>().Properties.Values.Should().Contain("ipod"); var el1 = ((IList)fields[1])[1]; el1.Should().BeAssignableTo <IDictionary <string, object> >(); el1.ValueAs <IDictionary <string, object> >().Should().ContainKey("rel"); var rel1 = el1.ValueAs <IDictionary <string, object> >()["rel"]; rel1.Should().BeAssignableTo <IRelationship>(); rel1.ValueAs <IRelationship>().Type.Should().Be("OWNS"); rel1.ValueAs <IRelationship>().StartNodeId.Should().Be(2L); rel1.ValueAs <IRelationship>().EndNodeId.Should().Be(3L); rel1.ValueAs <IRelationship>().Properties.Should().BeEmpty(); el1.ValueAs <IDictionary <string, object> >().Should().ContainKey("product"); var prod1 = el1.ValueAs <IDictionary <string, object> >()["product"]; prod1.Should().BeAssignableTo <INode>(); prod1.ValueAs <INode>().Labels.Should().Contain("Product"); prod1.ValueAs <INode>().Properties.Keys.Should().Contain("name"); prod1.ValueAs <INode>().Properties.Values.Should().Contain("computer"); }