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"); }
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"); }
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()); }