Beispiel #1
0
            public void ShouldNoNPEIfCurrentResultBuilderIsNull()
            {
                var mrh = new MessageResponseHandler();

                mrh.EnqueueMessage(new PullAllMessage());
                mrh.HandleFailureMessage("code.error", "message");
            }
Beispiel #2
0
            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>();
            }
Beispiel #3
0
            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);
            }
Beispiel #4
0
            public void ShouldCreateTransientExceptionWhenClassificationContainsTransientError(string code)
            {
                var mockResultBuilder = new Mock <IResultBuilder>();
                var mrh = new MessageResponseHandler();

                mrh.Register(new PullAllMessage(), mockResultBuilder.Object);

                mrh.HandleFailureMessage(code, "message");
                mrh.HasError.Should().BeTrue();
                mrh.Error.Should().BeOfType <TransientException>();
            }
Beispiel #5
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.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);
            }
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.HandleFailureMessage("code.error", "message");
                mrh.SentMessages.Should().HaveCount(0);
                mrh.CurrentResponseCollector.Should().NotBeNull();
            }
            public void ShouldClearErrorState()
            {
                var mockResultBuilder = new Mock <IResultBuilder>();
                var mrh = new MessageResponseHandler();

                mrh.Register(new PullAllMessage(), mockResultBuilder.Object);

                mrh.HandleFailureMessage("Neo.ClientError.General.ReadOnly", "message");
                mrh.HasError.Should().BeTrue();
                mrh.Error.Should().BeOfType <ClientException>();

                mrh.Clear();

                mrh.HasError.Should().BeFalse();
                mrh.Error.Should().BeNull();
            }
Beispiel #8
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();
            }
Beispiel #9
0
 public void HandleFailureMessage(string code, string message)
 {
     FailureMessageCalled++;
     _messageHandler.HandleFailureMessage(code, message);
 }