public void When_prepending_item_on_cache_will_not_modify_flags()
        {
            var buffer = new byte[] { 1, 2, 3, 4 };
            ICommand command = new SetCommand();
            command.SetContext(GetStreamWithData(buffer));
            command.Init("foo", "1", "6000", "4");

            command.FinishedExecuting += () => { wait.Set(); };
            command.Execute();
            wait.WaitOne();

            wait.Reset();

            buffer = new byte[] { 5, 6, 7, 8 };
            MemoryStream stream = GetStreamWithData(buffer);
            command = new PrependCommand();
            command.SetContext(stream);
            command.Init("foo", "15", "6000", "4");

            command.FinishedExecuting += () => { wait.Set(); };
            command.Execute();
            wait.WaitOne();

            var item = (CachedItem)Cache.Get("foo");

            Assert.AreEqual(1, item.Flags);
        }
        public void When_prepending_item_on_cache_will_prepend_to_data_already_on_cache()
        {
            var buffer = new byte[] { 1, 2, 3, 4 };
            ICommand command = new SetCommand();
            command.SetContext(GetStreamWithData(buffer));
            command.Init("foo", "1", "6000", "4");

            command.FinishedExecuting += () => { wait.Set(); };
            command.Execute();
            wait.WaitOne();

            wait.Reset();

            buffer = new byte[] { 5, 6, 7, 8 };
            MemoryStream stream = GetStreamWithData(buffer);
            command = new PrependCommand();
            command.SetContext(stream);
            command.Init("foo", "1", "6000", "4");

            command.FinishedExecuting += () => { wait.Set(); };
            command.Execute();
            wait.WaitOne();

            var item = (CachedItem)Cache.Get("foo");

            CollectionAssert.AreEqual(new byte[] { 5, 6, 7, 8, 1, 2, 3, 4, }, item.Buffer);
        }
        public void When_item_end_in_just_LF_will_send_error()
        {
            var buffer = new byte[] { 1, 2, 3, 4, 10 };
            var stream = new MemoryStream();
            stream.Write(buffer, 0, 5);
            stream.Position = 0;
            var command = new SetCommand();
            command.SetContext(stream);
            command.Init("foo", "1", "6000", "4");

            command.FinishedExecuting += () => { wait.Set(); };
            command.Execute();
            wait.WaitOne();

            Assert.AreEqual("CLIENT_ERROR Data section should end with a line break (\\r\\n)\r\n", ReadAll(5, stream));
        }
        public void When_prepending_item_on_cache_will_reply_with_stored()
        {
            var buffer = new byte[] { 1, 2, 3, 4 };
            ICommand command = new SetCommand();
            command.SetContext(GetStreamWithData(buffer));
            command.Init("foo", "1", "6000", "4");

            command.FinishedExecuting += () => { wait.Set(); };
            command.Execute();
            wait.WaitOne();

            wait.Reset();

            buffer = new byte[] { 5, 6, 7, 8 };
            MemoryStream stream = GetStreamWithData(buffer);
            command = new PrependCommand();
            command.SetContext(stream);
            command.Init("foo", "1", "6000", "4");

            command.FinishedExecuting += () => { wait.Set(); };
            command.Execute();
            wait.WaitOne();

            Assert.AreEqual("STORED\r\n", ReadAll(6, stream));
        }
        public void When_setting_item_will_put_it_in_cache()
        {
            var buffer = new byte[] { 1, 2, 3, 4 };
            var command = new SetCommand();
            command.SetContext(GetStreamWithData(buffer));

            command.Init("foo", "1","6000","4");

            command.FinishedExecuting += () => { wait.Set(); };
            command.Execute();
            wait.WaitOne();

            var cachedItem = (CachedItem)Cache.Get("foo");
            Assert.IsNotNull(cachedItem);
            CollectionAssert.AreEqual(buffer, cachedItem.Buffer);
            Assert.AreEqual(1, cachedItem.Flags);
        }
        private MemoryStream SetItem()
        {
            wait.Reset();

            var buffer = new byte[] { 1, 2, 3, 4 };
            MemoryStream stream = GetStreamWithData(buffer);
            var command = new SetCommand();
            command.SetContext(stream);
            command.Init("foo", "1", "6000", "4");

            command.FinishedExecuting += () => { wait.Set(); };
            command.Execute();
            wait.WaitOne();
            return stream;
        }
        public void When_setting_item_will_reply_that_it_was_stored()
        {
            var buffer = new byte[] { 1, 2, 3, 4 };
            MemoryStream stream = GetStreamWithData(buffer);
            var command = new SetCommand();
            command.SetContext(stream);
            command.Init("foo", "1", "6000", "4");

            command.FinishedExecuting += () => { wait.Set(); };
            command.Execute();
            wait.WaitOne();

            Assert.AreEqual("STORED\r\n", ReadAll(6, stream));
        }