Exemplo n.º 1
0
        public void Execute_RequestIsNull_Throws()
        {
            var target = new RespClient(new RedisCacheOptions {
                Host = "foo"
            });
            IRequest request = null;
            var      e       = Assert.ThrowsException <ArgumentNullException>(() => target.Execute(request));

            Assert.AreEqual(e.ParamName, "request");
        }
Exemplo n.º 2
0
        public void Execute_RequestsIsEmpty_Throws()
        {
            var target = new RespClient(new RedisCacheOptions {
                Host = "foo"
            });
            var requests = Array.Empty <IRequest>();
            var e        = Assert.ThrowsException <ArgumentException>(() => target.Execute(requests));

            Assert.AreEqual(e.ParamName, "requests");
        }
Exemplo n.º 3
0
        public void Execute_WithValidRequest_InvokesSend()
        {
            var transportMock = new Mock <ITransport>();

            transportMock.Setup(t => t.State).Returns(TransportState.Connected);
            transportMock.Setup(t => t.Send(It.IsAny <ReadOnlySequence <byte> >()))
            .Returns(new ReadOnlySequence <byte>(Encoding.UTF8.GetBytes($"+foo\r\n")));

            var target = new RespClient(new RedisCacheOptions {
                Host = "foo"
            }, transportMock.Object);
            var request = Mock.Of <IRequest>(r => r.Command == "foo" && r.GetArgs() == Array.Empty <object>());

            var response = target.Execute(request);

            Assert.IsNotNull(response);
            transportMock.Verify(t => t.Send(It.IsAny <ReadOnlySequence <byte> >()), Times.Once());
        }