public override IOperation Clone()
 {
     var cloned = new Touch(Key, VBucket, Transcoder, Timeout)
     {
         Attempts = Attempts,
         Cas = Cas,
         CreationTime = CreationTime,
         Expires = Expires
     };
     return cloned;
 }
        public void Test_That_Write_Returns_Correct_Values_Ignoring_CAS_And_Opaque()
        {
            //A memcached request packet for touch command to compare against
            var buffer = new byte[] { 128, 28, 0, 9, 4, 0, 1, 26, 0, 0, 0, 13, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 1,
                109, 121, 107, 101, 121, 50, 50, 50, 50 };

            //create a touch operations
            var touch = new Touch("mykey2222", GetVBucket(), new DefaultTranscoder(), OperationLifespanTimeout)
            {
                Expires = new TimeSpan(0, 0, 0, 1).ToTtl()
            };

            //get the request packet the operation will generate
            var actual = touch.Write();

            //test the byte fields which should be equivalent
            Assert.AreEqual(buffer.Take(6), actual.Take(6)); //magic, opcode, key lngth, extra lngth and datatype
            Assert.AreEqual(buffer.Skip(23).Take(4), actual.Skip(23).Take(4)); //expires value
            Assert.AreEqual(buffer.Skip(27).Take(9), actual.Skip(27).Take(9)); //key
        }
        public void When_Key_Exists_Touch_Returns_Success()
        {
            var key = "When_Key_Exists_Touch_Returns_Success";

            //delete the value if it exists
            var delete = new Delete(key, GetVBucket(), Transcoder, OperationLifespanTimeout);
            IOService.Execute(delete);

            //Add the key
            var add = new Add<dynamic>(key, new { foo = "foo" }, GetVBucket(), Transcoder, OperationLifespanTimeout);
            Assert.IsTrue(IOService.Execute(add).Success);

            var touch = new Touch(key, GetVBucket(), Transcoder, OperationLifespanTimeout)
            {
                Expires = new TimeSpan(0, 0, 0, 3).ToTtl()
            };

            var result = IOService.Execute(touch);
            Console.WriteLine(result.Message);
            Assert.IsTrue(result.Success);
        }