public void ShouldThrowOnCurrentIfNoPendingMessages()
        {
            var pipeline = new ResponsePipeline(null);

            var exc = Record.Exception(() => pipeline.Peek());

            exc.Should().BeOfType <InvalidOperationException>();
        }
        private static ResponsePipeline CreatePipelineWithHandler(ILogger logger)
        {
            var pipeline = new ResponsePipeline(logger);

            var(msg, handler) = (new Mock <IRequestMessage>(), new Mock <IResponseHandler>());
            pipeline.Enqueue(msg.Object, handler.Object);

            return(pipeline);
        }
        public void ShouldEnqueueResponseHandlers()
        {
            var(msg, handler) = (new Mock <IRequestMessage>(), new Mock <IResponseHandler>());
            var pipeline = new ResponsePipeline(null);

            pipeline.Enqueue(msg.Object, handler.Object);

            pipeline.HasNoPendingMessages.Should().BeFalse();
            pipeline.Peek().Should().Be(handler.Object);
        }
        public void ShouldThrowIfEnqueuedHandlerIsNull()
        {
            var msg      = new Mock <IRequestMessage>();
            var pipeline = new ResponsePipeline(null);

            var exc = Record.Exception(() => pipeline.Enqueue(msg.Object, null));

            exc.Should().BeOfType <ArgumentNullException>()
            .Which.ParamName.Should().Be("handler");
        }
        public void ShouldThrowIfEnqueuedMessageIsNull()
        {
            var handler  = new Mock <IResponseHandler>();
            var pipeline = new ResponsePipeline(null);

            var exc = Record.Exception(() => pipeline.Enqueue(null, handler.Object));

            exc.Should().BeOfType <ArgumentNullException>()
            .Which.ParamName.Should().Be("message");
        }
            public void ShouldInvokeHandler()
            {
                var pipeline = new ResponsePipeline(null);

                var(msg, handler) = (new Mock <IRequestMessage>(), new Mock <IResponseHandler>());
                pipeline.Enqueue(msg.Object, handler.Object);

                pipeline.OnIgnored();

                handler.Verify(x => x.OnIgnored(), Times.Once);
            }
            public void ShouldInvokeHandler()
            {
                var pipeline = new ResponsePipeline(null);

                var(msg, handler) = (new Mock <IRequestMessage>(), new Mock <IResponseHandler>());
                pipeline.Enqueue(msg.Object, handler.Object);

                var fields = new object[] { 1, true, "string" };

                pipeline.OnRecord(fields);

                handler.Verify(x => x.OnRecord(fields), Times.Once);
            }
            public void ShouldInvokeHandler()
            {
                var pipeline = new ResponsePipeline(null);

                var(msg, handler) = (new Mock <IRequestMessage>(), new Mock <IResponseHandler>());
                pipeline.Enqueue(msg.Object, handler.Object);

                var metadata = new Dictionary <string, object> {
                    { "x", 1 }, { "y", true }
                };

                pipeline.OnSuccess(metadata);

                handler.Verify(x => x.OnSuccess(metadata), Times.Once);
            }
            public void ShouldRecordErrorAndThrowOnAssertNoProtocolViolation()
            {
                var pipeline = new ResponsePipeline(null);

                var(code, message) = ("Neo.ClientError.Request.Invalid", "protocol exception.");

                var(msg, handler) = (new Mock <IRequestMessage>(), new Mock <IResponseHandler>());
                pipeline.Enqueue(msg.Object, handler.Object);

                pipeline.OnFailure(code, message);

                var exc = Record.Exception(() => pipeline.AssertNoProtocolViolation());

                exc.Should().BeOfType <ProtocolException>().Which
                .Message.Should().Be("protocol exception.");
            }
            public void ShouldInvokeHandler()
            {
                var pipeline = new ResponsePipeline(null);

                var(code, message) = ("Neo.TransientError.Transaction.Terminated", "transaction terminated.");

                var(msg, handler) = (new Mock <IRequestMessage>(), new Mock <IResponseHandler>());
                pipeline.Enqueue(msg.Object, handler.Object);

                pipeline.OnFailure(code, message);

                handler.Verify(
                    x => x.OnFailure(It.Is <IResponsePipelineError>(e =>
                                                                    e.Is(t => t is TransientException && t.Message.Equals("transaction terminated.")))),
                    Times.Once);
            }
        public void ShouldDequeueResponseHandlersInOrder()
        {
            var(msg1, handler1) = (new Mock <IRequestMessage>(), new Mock <IResponseHandler>());
            var(msg2, handler2) = (new Mock <IRequestMessage>(), new Mock <IResponseHandler>());
            var pipeline = new ResponsePipeline(null);

            pipeline.Enqueue(msg1.Object, handler1.Object);
            pipeline.Enqueue(msg2.Object, handler2.Object);

            pipeline.HasNoPendingMessages.Should().BeFalse();
            pipeline.Peek().Should().Be(handler1.Object);
            pipeline.Dequeue();

            pipeline.HasNoPendingMessages.Should().BeFalse();
            pipeline.Peek().Should().Be(handler2.Object);
            pipeline.Dequeue();

            pipeline.HasNoPendingMessages.Should().BeTrue();
        }
        public void ShouldStartWithNoPendingMessages()
        {
            var pipeline = new ResponsePipeline(null);

            pipeline.HasNoPendingMessages.Should().BeTrue();
        }