예제 #1
0
        public void Test_ToUInt32()
        {
            var       converter = new ManualByteConverter();
            var       actual    = converter.ToUInt32(_buffer, 8);
            const int expected  = 5;

            Assert.AreEqual(expected, actual);
        }
예제 #2
0
        public void Test_ToByte()
        {
            var       converter = new ManualByteConverter();
            var       actual    = converter.ToByte(_buffer, 0);
            const int expected  = 128;

            Assert.AreEqual(expected, actual);
        }
예제 #3
0
        public void Test_FromUInt64()
        {
            var converter = new ManualByteConverter();
            var actual    = new byte[15];

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

            Assert.AreEqual(expected, actual);
        }
예제 #4
0
        public void Test_FromString()
        {
            var converter = new ManualByteConverter();
            var buffer    = new byte[Encoding.UTF8.GetByteCount("Hello")];

            converter.FromString("Hello", buffer, 0);
            var expected = new byte[] { 0x48, 0x65, 0x6c, 0x6c, 0x6f };

            Assert.AreEqual(expected, buffer);
        }
        public void Test_ToUInt32()
        {
#pragma warning disable 618
            var converter = new ManualByteConverter();
#pragma warning restore 618
            var       actual   = converter.ToUInt32(_buffer, 8);
            const int expected = 5;

            Assert.AreEqual(expected, actual);
        }
예제 #6
0
        public void Test_ToString()
        {
            const int offset = 24;
            const int length = 5;

            var          converter = new ManualByteConverter();
            var          actual    = converter.ToString(_buffer, offset, length);
            const string expected  = "Hello";

            Assert.AreEqual(expected, actual);
        }
        public void Test_FromUInt64()
        {
#pragma warning disable 618
            var converter = new ManualByteConverter();
#pragma warning restore 618
            var actual = new byte[15];
            converter.FromUInt64(5, actual, 3);
            var expected = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00 };

            Assert.AreEqual(expected, actual);
        }
        public void SetUp()
        {
            var ipEndpoint = UriExtensions.GetEndPoint(Address);
            var factory    = DefaultConnectionFactory.GetGeneric <SslConnection>();
            var converter  = new ManualByteConverter();

            _configuration = new PoolConfiguration(MaxSize, MinSize, WaitTimeout, RecieveTimeout, ShutdownTimeout, SendTimeout)
            {
                UseSsl = true
            };
            _connectionPool = new ConnectionPool <SslConnection>(_configuration, ipEndpoint, factory, converter);
            _connectionPool.Initialize();
        }
        public void When_ByteArray_Is_Stored_With_Legacy_Flags_It_Is_Decoded_As_A_ByteArray()
        {
            var legacyByteArray = new byte[]
            {
                129, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 8, 0,
                0, 0, 5, 19, 185, 8, 248, 3, 104, 208, 188, 0,
                0, 250, 82, 116, 101, 115, 116
            };

            var converter = new ManualByteConverter();
            var format    = new byte();

            var temp = converter.ToByte(legacyByteArray, 24);

            converter.SetBit(ref format, 0, converter.GetBit(temp, 0));
            converter.SetBit(ref format, 1, converter.GetBit(temp, 1));
            converter.SetBit(ref format, 2, converter.GetBit(temp, 2));
            converter.SetBit(ref format, 3, converter.GetBit(temp, 3));

            var compression = new byte();

            converter.SetBit(ref compression, 4, converter.GetBit(temp, 4));
            converter.SetBit(ref compression, 5, converter.GetBit(temp, 5));
            converter.SetBit(ref compression, 6, converter.GetBit(temp, 6));

            var flags = new Flags
            {
                DataFormat  = (DataFormat)format,
                Compression = (Compression)compression,
                TypeCode    = (TypeCode)(converter.ToUInt16(legacyByteArray, 26) & 0xff),
            };

            var transcoder = new DefaultTranscoder(new ManualByteConverter());
            var result     = transcoder.Decode <byte[]>(legacyByteArray, 28, 4, flags);

            Assert.AreEqual("test", Encoding.UTF8.GetString(result));
        }