public void Get_NotFound(GetOperation operation)
        {
            // Arrange
            var         options  = new ProtocolOptions();
            var         protocol = new DefaultProtocol(m_mockFactory.Object, options);
            var         datakey  = new DataKey <int>("Key1");
            var         key      = new byte[] { };
            ValuePacket packet   = null;

            m_mockEncoder.Setup(encoder => encoder.GetBytes("Key1")).Returns(key);
            m_mockCommandWriter.Setup(writer => writer.Get(operation, key));
            m_mockFactory.Setup(factory => factory.Context(key))
            .Returns <byte[]>(state => (Action2 <IClientConnection, object> action) =>
            {
                action(m_mockClientConnection.Object, state);
                return(true);
            });
            m_mockClientConnection.SetupGet(connection => connection.Writer).Returns(m_mockBinaryWriter.Object);
            m_mockPacketBuilder.Setup(builder => builder.WriteTo(m_mockBinaryWriter.Object)).Returns(0);
            m_mockClientConnection.SetupGet(connection => connection.Reader).Returns(m_mockBinaryReader.Object);
            m_mockFactory.Setup(factory => factory.CreatePacketParser(m_mockBinaryReader.Object, It.IsAny <Buffer <byte> >())).Returns(m_mockPacketParser.Object);
            m_mockFactory.Setup(factory => factory.CreateCommandReader(m_mockPacketParser.Object)).Returns(m_mockCommandReader.Object);
            m_mockCommandReader.Setup(reader => reader.ReadValue(operation == GetOperation.Gets)).Returns(packet);

            // Act
            var result = protocol.Get(operation, datakey);

            // Assert
            Assert.True(result);
            Assert.False(datakey.HasValue);
        }
        public void Get(GetOperation operation)
        {
            // Arrange
            var options  = new ProtocolOptions();
            var protocol = new DefaultProtocol(m_mockFactory.Object, options);
            var datakey  = new DataKey <int>("Key1");
            var key      = new byte[] { };
            var packet   = new ValuePacket()
            {
                Flags   = 101,
                Key     = key,
                Value   = new ArraySegment <byte>(new byte[] { }),
                Version = 245
            };

            m_mockEncoder.Setup(encoder => encoder.GetBytes("Key1")).Returns(key);
            m_mockCommandWriter.Setup(writer => writer.Get(operation, key));
            m_mockFactory.Setup(factory => factory.Context(key))
            .Returns <byte[]>(state => (Action2 <IClientConnection, object> action) =>
            {
                action(m_mockClientConnection.Object, state);
                return(true);
            });
            m_mockClientConnection.SetupGet(connection => connection.Writer).Returns(m_mockBinaryWriter.Object);
            m_mockPacketBuilder.Setup(builder => builder.WriteTo(m_mockBinaryWriter.Object)).Returns(0);
            m_mockClientConnection.SetupGet(connection => connection.Reader).Returns(m_mockBinaryReader.Object);
            m_mockFactory.Setup(factory => factory.CreatePacketParser(m_mockBinaryReader.Object, It.IsAny <Buffer <byte> >())).Returns(m_mockPacketParser.Object);
            m_mockFactory.Setup(factory => factory.CreateCommandReader(m_mockPacketParser.Object)).Returns(m_mockCommandReader.Object);
            m_mockCommandReader.Setup(reader => reader.ReadValue(operation == GetOperation.Gets)).Returns(packet);
            m_mockObjectFormatter.Setup(formatter => formatter.Deserialize <int>(packet.Value, packet.Flags)).Returns(507);
            m_mockCommandReader.Setup(reader => reader.ReadSucceed());

            // Act
            var result = protocol.Get(operation, datakey);

            // Assert
            Assert.True(result);
            Assert.True(datakey.HasValue);
            Assert.Equal(245, datakey.Version);
            Assert.Equal(507, datakey.Value);
        }