Beispiel #1
0
            public void ShouldClearResultBuildersSendMessagesAndTheCurrentBuilder()
            {
                var mockResultBuilder = new Mock <IResultBuilder>();
                var mrh = new MessageResponseHandler();

                // Two messages are queued, as one will be popped off when handling a success message.
                mrh.Register(new PullAllMessage(), mockResultBuilder.Object);
                mrh.Register(new PullAllMessage(), mockResultBuilder.Object);
                // We need to handle the success message to et the CurrentResultBuilder
                mrh.HandleSuccessMessage(new Dictionary <string, object> {
                    { "fields", new List <object> {
                          "x"
                      } }
                });

                mrh.SentMessages.Should().HaveCount(1);
                mrh.ResultBuilders.Should().HaveCount(1);
                mrh.CurrentResultBuilder.Should().NotBeNull();

                mrh.Clear();

                mrh.SentMessages.Should().HaveCount(0);
                mrh.ResultBuilders.Should().HaveCount(0);
                mrh.CurrentResultBuilder.Should().BeNull();
            }
Beispiel #2
0
            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);
            }
Beispiel #3
0
            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);
            }
Beispiel #4
0
            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);
            }
Beispiel #5
0
            public void ShouldCollectFieldsIfMessageContainsFields()
            {
                var mockResultBuilder = new Mock <IResultBuilder>();
                var mrh = new MessageResponseHandler();

                // Two messages are queued, as one will be popped off when handling a success message.
                mrh.Register(new PullAllMessage(), 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);
            }
Beispiel #6
0
            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();
            }
Beispiel #7
0
            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);
            }
Beispiel #8
0
            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);
            }
Beispiel #9
0
            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 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);
            }
Beispiel #11
0
            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);
            }
Beispiel #12
0
 public void HandleSuccessMessage(IDictionary <string, object> meta)
 {
     _messageHandler.HandleSuccessMessage(meta);
 }