public async Task ShouldCreateExceptionWhenErrorReceivedFromDatabase() { using (var harness = new SocketClientTestHarness(FakeUri, null)) { var messages = new IRequestMessage[] { new RunMessage("This will cause a syntax error") }; var messageHandler = new MessageResponseHandler(); messageHandler.EnqueueMessage(new InitMessage("MyClient/1.1", new Dictionary <string, object>())); messageHandler.EnqueueMessage(messages[0], new ResultBuilder()); harness.SetupReadStream("00 00 00 01" + "00 03 b1 70 a0 00 00" + "00a0b17fa284636f6465d0274e656f2e436c69656e744572726f722e53746174656d656e742e496e76616c696453796e746178876d657373616765d065496e76616c696420696e707574202754273a206578706563746564203c696e69743e20286c696e6520312c20636f6c756d6e203120286f66667365743a203029290a22546869732077696c6c20636175736520612073796e746178206572726f72220a205e0000"); harness.SetupWriteStream(); await harness.Client.Start(); harness.ResetCalls(); // When harness.Client.Send(messages); Record.Exception(() => harness.Client.Receive(messageHandler)); // Then harness.VerifyWriteStreamUsages(2 /*write + flush*/); messageHandler.HasError.Should().BeTrue(); messageHandler.Error.Code.Should().Be("Neo.ClientError.Statement.InvalidSyntax"); messageHandler.Error.Message.Should().Be( "Invalid input 'T': expected <init> (line 1, column 1 (offset: 0))\n\"This will cause a syntax error\"\n ^"); } }
public void ShouldNoNPEIfCurrentResultBuilderIsNull() { var mrh = new MessageResponseHandler(); mrh.EnqueueMessage(new PullAllMessage()); mrh.HandleIgnoredMessage(); }
public void ShouldNoNPEIfCurrentResultBuilderIsNull() { var mrh = new MessageResponseHandler(); mrh.EnqueueMessage(new PullAllMessage()); mrh.HandleFailureMessage("code.error", "message"); }
public async Task ShouldSendMessagesAsExpected() { // Given var messages = new IRequestMessage[] { new RunMessage("Run message 1"), new RunMessage("Run message 1") }; byte[] expectedBytes = { 0x00, 0x11, 0xB2, 0x10, 0x8D, 0x52, 0x75, 0x6E, 0x20, 0x6D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x20, 0x31, 0xA0, 0x00, 0x00, 0x00, 0x11, 0xB2, 0x10, 0x8D, 0x52, 0x75, 0x6E, 0x20, 0x6D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x20, 0x31, 0xA0, 0x00, 0x00 }; var expectedLength = expectedBytes.Length; expectedBytes = expectedBytes.PadRight(ChunkedOutputStream.BufferSize); var messageHandler = new MessageResponseHandler(); messageHandler.EnqueueMessage(new InitMessage("MyClient/1.1", new Dictionary <string, object>())); var rb = new ResultBuilder(); messageHandler.EnqueueMessage(messages[0], rb); messageHandler.EnqueueMessage(messages[1], rb); using (var harness = new SocketClientTestHarness(FakeUri, null)) { harness.SetupReadStream("00 00 00 01" + "00 03 b1 70 a0 00 00" + "00 0f b1 70 a1 86 66 69 65 6c 64 73 91 83 6e 75 6d 00 00" + "00 0f b1 70 a1 86 66 69 65 6c 64 73 91 83 6e 75 6d 00 00"); harness.SetupWriteStream(); await harness.Client.Start(); harness.ResetCalls(); // When harness.Client.Send(messages); harness.Client.Receive(messageHandler); // Then harness.VerifyWriteStreamUsages(2 /*write + flush*/); harness.VerifyWriteStreamContent(expectedBytes, expectedLength); } }
public void ShouldCreateDatabaseExceptionWhenClassificationContainsDatabaseError(string code) { var mockResultBuilder = new Mock <IMessageResponseCollector>(); var mrh = new MessageResponseHandler(); mrh.EnqueueMessage(new PullAllMessage(), mockResultBuilder.Object); mrh.HandleFailureMessage(code, "message"); mrh.HasError.Should().BeTrue(); mrh.Error.Should().BeOfType <DatabaseException>(); }
public void ShouldCallDoneIgnoredIfCurrentResultBuilderNotNull() { var mockResultBuilder = new Mock <IMessageResponseCollector>(); var mrh = new MessageResponseHandler(); mrh.EnqueueMessage(new PullAllMessage(), mockResultBuilder.Object); mrh.HandleIgnoredMessage(); mockResultBuilder.Verify(x => x.DoneIgnored(), Times.Once); }
public void ShouldSuccessMessageNotClearErrorState() { var mrh = new MessageResponseHandler(); mrh.EnqueueMessage(new PullAllMessage()); mrh.EnqueueMessage(new PullAllMessage()); mrh.HandleFailureMessage("Neo.ClientError.General.ReadOnly", "message"); mrh.HasError.Should().BeTrue(); mrh.Error.Should().BeOfType <ClientException>(); mrh.HandleSuccessMessage(new Dictionary <string, object> { { "fields", new List <object> { "x" } } }); mrh.HasError.Should().BeTrue(); mrh.Error.Should().NotBeNull(); }
public void ShouldCallDoneFailureIfCurrentResultBuilderNotNull() { var mockResultBuilder = new Mock <IMessageResponseCollector>(); var mrh = new MessageResponseHandler(); mrh.EnqueueMessage(new PullAllMessage(), mockResultBuilder.Object); mrh.HandleFailureMessage("code.error", "message"); mockResultBuilder.Verify(x => x.DoneFailure(), Times.Once); }
public void LogsTheMessageToDebug() { var mockResultBuilder = new Mock <IMessageResponseCollector>(); var mockLogger = LoggingHelper.GetTraceEnabledLogger(); var mrh = new MessageResponseHandler(mockLogger.Object); mrh.EnqueueMessage(PullAll, mockResultBuilder.Object); mrh.HandleIgnoredMessage(); mockLogger.Verify(x => x.Debug(It.Is <string>(actual => actual.StartsWith("S: ")), It.Is <object[]>(actual => actual.First() is IgnoredMessage)), Times.Once); }
public void DequeuesFromSentMessagesAndSetsCurrentBuilder() { var mockResultBuilder = new Mock <IMessageResponseCollector>(); var mrh = new MessageResponseHandler(); mrh.EnqueueMessage(PullAll, mockResultBuilder.Object); mrh.SentMessages.Should().HaveCount(1); mrh.CurrentResponseCollector.Should().BeNull(); mrh.HandleIgnoredMessage(); mrh.SentMessages.Should().HaveCount(0); mrh.CurrentResponseCollector.Should().NotBeNull(); }
public void LogsTheMessageToDebug() { var mockResultBuilder = new Mock <IMessageResponseCollector>(); var mockLogger = new Mock <ILogger>(); var mrh = new MessageResponseHandler(mockLogger.Object); mrh.EnqueueMessage(new PullAllMessage(), mockResultBuilder.Object); mrh.HandleFailureMessage("code.error", "message"); mockLogger.Verify(x => x.Debug(It.Is <string>(actual => actual.StartsWith("S: ")), It.Is <object[]>(actual => actual.First() is FailureMessage)), Times.Once); }
public void DequeuesFromSentMessagesAndSetsCurrentBuilder() { var mockResultBuilder = new Mock <IMessageResponseCollector>(); var mrh = new MessageResponseHandler(); mrh.EnqueueMessage(new PullAllMessage(), mockResultBuilder.Object); mrh.SentMessages.Should().HaveCount(1); mrh.CurrentResponseCollector.Should().BeNull(); mrh.HandleFailureMessage("code.error", "message"); mrh.SentMessages.Should().HaveCount(0); mrh.CurrentResponseCollector.Should().NotBeNull(); }
public void NotDequeueFromSentMessagesOrSetsCurrentBuilder() { var mockResultBuilder = new Mock <IMessageResponseCollector>(); var mrh = new MessageResponseHandler(); mrh.EnqueueMessage(new PullAllMessage(), mockResultBuilder.Object); mrh.SentMessages.Should().HaveCount(1); mrh.CurrentResponseCollector.Should().BeNull(); mrh.HandleRecordMessage(new object[] { "x" }); mrh.SentMessages.Should().HaveCount(1); mrh.CurrentResponseCollector.Should().BeNull(); }
public void ShouldNotBufferAnyRecordWhenResetIsEnqueue() { var mockResultBuilder = new Mock <IResultBuilder>(); var mrh = new MessageResponseHandler(); mrh.EnqueueMessage(new PullAllMessage(), mockResultBuilder.Object); mrh.HandleSuccessMessage(new Dictionary <string, object> { { "fields", new List <object> { "x" } } }); mrh.HandleRecordMessage(new object[] { "x" }); mrh.CurrentResultBuilder.Should().NotBeNull(); mrh.EnqueueMessage(new ResetMessage()); mrh.CurrentResultBuilder.Should().BeNull(); mrh.HandleRecordMessage(new object[] { "x" }); mockResultBuilder.Verify(x => x.CollectRecord(It.IsAny <object[]>()), Times.Once); }
public void ShouldTryToCollectSummaryIfMessageDoesNotContainFields() { var mockResultBuilder = new Mock <IMessageResponseCollector>(); var mrh = new MessageResponseHandler(); mrh.EnqueueMessage(new PullAllMessage(), mockResultBuilder.Object); mrh.HandleSuccessMessage(new Dictionary <string, object> { { "summary", new List <object> { "x" } } }); mockResultBuilder.Verify(x => x.CollectSummary(It.IsAny <IDictionary <string, object> >()), Times.Once); }
public void ShouldCollectFieldsIfMessageContainsFields() { var mockResultBuilder = new Mock <IMessageResponseCollector>(); var mrh = new MessageResponseHandler(); mrh.EnqueueMessage(PullAll, mockResultBuilder.Object); mrh.HandleSuccessMessage(new Dictionary <string, object> { { "fields", new List <object> { "x" } } }); mockResultBuilder.Verify(x => x.CollectFields(It.IsAny <IDictionary <string, object> >()), Times.Once); }
public void ShouldCallDoneSuccess() { var mockResultBuilder = new Mock <IMessageResponseCollector>(); var mrh = new MessageResponseHandler(); mrh.EnqueueMessage(new PullAllMessage(), mockResultBuilder.Object); mrh.HandleSuccessMessage(new Dictionary <string, object> { { "fields", new List <object> { "x" } } }); mockResultBuilder.Verify(x => x.DoneSuccess(), Times.Once); }
public void ShouldBufferAnyRecordWhenResetIsEnqueue() { var mockResultBuilder = new Mock <IMessageResponseCollector>(); var mrh = new MessageResponseHandler(); mrh.EnqueueMessage(new RunMessage("run something"), mockResultBuilder.Object); mrh.EnqueueMessage(PullAll, mockResultBuilder.Object); mrh.HandleSuccessMessage(new Dictionary <string, object> { { "fields", new List <object> { "x" } } }); mrh.HandleRecordMessage(new object[] { "x" }); mrh.CurrentResponseCollector.Should().NotBeNull(); mrh.EnqueueMessage(ResetMessage.Reset); mrh.CurrentResponseCollector.Should().NotBeNull(); mrh.HandleRecordMessage(new object[] { "x" }); mockResultBuilder.Verify(x => x.CollectRecord(It.IsAny <object[]>()), Times.Exactly(2)); mrh.UnhandledMessageSize.Should().Be(2); }
public void LogsTheMessageToDebug() { var mockResultBuilder = new Mock <IMessageResponseCollector>(); var mockLogger = new Mock <ILogger>(); var mrh = new MessageResponseHandler(mockLogger.Object); mrh.EnqueueMessage(new PullAllMessage(), mockResultBuilder.Object); mrh.HandleSuccessMessage(new Dictionary <string, object> { { "fields", new List <object> { "x" } } }); mockLogger.Verify(x => x.Debug(It.Is <string>(actual => actual.StartsWith("S: ")), It.Is <object[]>(actual => actual.First() is SuccessMessage)), Times.Once); }
public void DequeuesFromSentMessagesAndSetsCurrentBuilder() { var mockResultBuilder = new Mock <IMessageResponseCollector>(); var mrh = new MessageResponseHandler(); mrh.EnqueueMessage(new PullAllMessage(), mockResultBuilder.Object); mrh.SentMessages.Should().HaveCount(1); mrh.CurrentResponseCollector.Should().BeNull(); mrh.HandleSuccessMessage(new Dictionary <string, object> { { "fields", new List <object> { "x" } } }); mrh.SentMessages.Should().HaveCount(0); mrh.CurrentResponseCollector.Should().NotBeNull(); }
public void CallsRecordOnTheCurrentResultBuilder() { var mockResultBuilder = new Mock <IMessageResponseCollector>(); var mrh = new MessageResponseHandler(); mrh.EnqueueMessage(new PullAllMessage(), mockResultBuilder.Object); mrh.HandleSuccessMessage(new Dictionary <string, object> { { "fields", new List <object> { "x" } } }); mrh.HandleRecordMessage(new object[] { "x" }); mockResultBuilder.Verify(x => x.CollectRecord(It.IsAny <object[]>()), Times.Once); }
public void EnqueueMessage(IRequestMessage requestMessage, IMessageResponseCollector responseCollector = null) { _messageHandler.EnqueueMessage(requestMessage, responseCollector); }
public void EnqueueMessage(IRequestMessage requestMessage, IResultBuilder resultBuilder = null) { _messageHandler.EnqueueMessage(requestMessage, resultBuilder); }