Ejemplo n.º 1
0
        public void WriteOperation(int expected, RequestOperation operation)
        {
            // Arrange
            int result = -1;

            m_mockBinaryWriter.Setup(writer => writer.Write(It.IsAny <byte[]>(), 0, It.IsAny <int>()))
            .Callback <byte[], int, int>((b, i, c) =>
                                         result = b[1]).Returns(0);

            // Act
            m_builder.WriteOperation(operation);

            // Assert
            m_builder.WriteTo(m_mockBinaryWriter.Object);
            Assert.Equal(expected, result);
        }
Ejemplo n.º 2
0
        public bool Store <T>(StoreOperation operation, T datakey, int expires)
            where T : DataKey
        {
            datakey.Initialize(m_formatter);
            int flags;
            var bytes = datakey.Save(out flags);
            var key   = m_keyEncoder.GetBytes(datakey.Key);

            m_commandWriter.Store(new StorePacket()
            {
                Operation = operation,
                Key       = key,
                Flags     = flags,
                Expires   = expires,
                Value     = bytes,
                Version   = datakey.Version
            }, Options.NoReply);

            var succeed = true;

            return(m_factory.Context(key)((connection, state) =>
            {
                m_builder.WriteTo(connection.Writer);
                if (!Options.NoReply)
                {
                    var commandReader = m_factory.CreateCommandReader(
                        m_factory.CreatePacketParser(connection.Reader, m_buffer));
                    succeed = commandReader.ReadStored();
                }
            }) && succeed);
        }
Ejemplo n.º 3
0
        public void Reset()
        {
            // Arrange
            string result = null;

            m_mockBinaryWriter.Setup(writer => writer.Write(It.IsAny <byte[]>(), 0, It.IsAny <int>()))
            .Callback <byte[], int, int>((b, i, c) =>
                                         result = Encoding.ASCII.GetString(b, i, c - 2)).Returns(0);

            // Act
            m_builder.Reset();

            // Assert
            m_builder.WriteTo(m_mockBinaryWriter.Object);
            Assert.Equal(string.Empty, result);
        }