Esempio n. 1
0
        public void Test_FromByte(byte value, int offset, byte[] expected)
        {
            var converter = new DefaultConverter();
            var actual    = new byte[8];

            converter.FromByte(value, actual, offset);

            Assert.Equal(expected, actual);
        }
        public void Create_Header_and_get_server_duration_from_framing_extras(ushort encoded, long?decoded)
        {
            // first four bits is 0 (type: server duration), last four bits is 2 (length)
            const byte frameInfo = 1 << 1;

            var converter = new DefaultConverter();
            var bytes     = new byte[27];

            converter.FromByte((byte)Magic.AltResponse, bytes, HeaderIndexFor.Magic);
            converter.FromByte(3, bytes, HeaderIndexFor.FramingExtras);
            converter.FromByte(frameInfo, bytes, 24);
            converter.FromUInt16(encoded, bytes, 25);

            var header = bytes.CreateHeader();

            Assert.IsNotNull(header);
            Assert.AreEqual(3, header.FramingExtrasLength);

            var serverDuration = header.GetServerDuration(bytes);

            Assert.AreEqual(decoded, serverDuration);
        }
Esempio n. 3
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);
        }