public void Test_ToString(byte[] bytes, string expected, int offset, int length) { var converter = new DefaultConverter(); var actual = converter.ToString(bytes.AsSpan(offset, length)); Assert.Equal(expected, actual); }
public void Test_ToString() { const int offset = 24; const int length = 5; var converter = new DefaultConverter(); var actual = converter.ToString(_buffer, offset, length); const string expected = "Hello"; Assert.AreEqual(expected, actual); }
public void Result_Has_UnknownError_Status_If_ErrorMap_Not_Available() { const string codeString = "2c"; // 44 var code = short.Parse(codeString, NumberStyles.HexNumber); var errorCode = new ErrorCode { Name = "test" }; var errorMap = new ErrorMap { Version = 1, Revision = 1, Errors = new Dictionary <string, ErrorCode>() }; var converter = new DefaultConverter(); var responseBytes = new byte[24]; converter.FromInt16(code, responseBytes, HeaderIndexFor.Status); var mockConnection = new Mock <IConnection>(); mockConnection.Setup(x => x.IsConnected).Returns(true); mockConnection.Setup(x => x.Send(It.IsAny <byte[]>())).Returns(responseBytes); var mockConnectionPool = new Mock <IConnectionPool>(); mockConnectionPool.Setup(x => x.Acquire()).Returns(mockConnection.Object); mockConnectionPool.SetupGet(x => x.Configuration).Returns(new PoolConfiguration()); mockConnectionPool.Setup(x => x.Connections).Returns(new List <IConnection> { mockConnection.Object }); var service = new PooledIOService(mockConnectionPool.Object) { ErrorMap = errorMap }; var result = service.Execute(new FakeOperationWithRequiredKey("key", null, new DefaultTranscoder(), 0, 0)); Assert.AreEqual(ResponseStatus.UnknownError, result.Status); Assert.AreEqual(converter.ToString(responseBytes, 0, 24), result.Message); }