コード例 #1
0
        public void ShouldThrowOnCurrentIfNoPendingMessages()
        {
            var pipeline = new ResponsePipeline(null);

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

            exc.Should().BeOfType <InvalidOperationException>();
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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");
        }
コード例 #5
0
        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");
        }
コード例 #6
0
            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);
            }
コード例 #7
0
            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);
            }
コード例 #8
0
            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);
            }
コード例 #9
0
            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.");
            }
コード例 #10
0
            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);
            }
コード例 #11
0
        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();
        }
コード例 #12
0
        public void ShouldStartWithNoPendingMessages()
        {
            var pipeline = new ResponsePipeline(null);

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