示例#1
0
        public void Test_FromInt16_NoNboSpecified(short value, int offset, byte[] expected)
        {
            var converter = new DefaultConverter();
            var actual    = new byte[8];

            converter.FromInt16(value, actual, offset);

            Assert.Equal(expected, actual);
        }
示例#2
0
        public void Test_FromInt16(short value, int offset, bool useNbo, byte[] expected)
        {
            var converter = new DefaultConverter();
            var actual    = new byte[8];

            converter.FromInt16(value, ref actual, offset, useNbo);

            Assert.Equal(expected, actual);
        }
示例#3
0
        public void Test_FromInt16()
        {
            var converter = new DefaultConverter();
            var actual    = new byte[8];

            converter.FromInt16(5, actual, 2);
            var expected = new byte[] { 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00 };

            Assert.AreEqual(expected, actual);
        }
示例#4
0
        public void Result_Has_Failure_Status_If_ErrorMap_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>
                {
                    { codeString, errorCode }
                }
            };

            var converter     = new DefaultConverter();
            var responseBytes = new byte[24];

            converter.FromByte((byte)Magic.Response, responseBytes, HeaderIndexFor.Magic);
            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
            {
                ClientConfiguration = new ClientConfiguration {
                    Tracer = NullTracer.Instance
                }
            });
            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.Failure, result.Status);
            Assert.AreEqual(errorCode.ToString(), result.Message);
        }
示例#5
0
        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());

            var service = new MultiplexingIOService(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);
        }