public void Test()
        {
            Init(1);
            WriteThreadFunc(0);
            ReadThreadFunc(0);
            Assert.AreEqual(value, Result, "value should be equal to result.");

            Init(1);
            WriteThreadFunc(0);
            var result = ypipe.ReadAll();

            Assert.IsNotNull(result, "result should not be null.");
            foreach (var i in result)
            {
                value += i;
            }
            Assert.AreEqual(value, Result, "value should be equal to result.");
        }
        public void TestApi()
        {
            ypipe = new CachePipe <int>();

            int valueResult;

            valueResult = ypipe.Peek();
            Assert.AreEqual(valueResult, default(int));

            int value = 1;
            var rc    = ypipe.Write(ref value);

            Assert.IsTrue(rc);
            Assert.AreEqual(ypipe.Count, 1);

            valueResult = ypipe.Peek();
            Assert.AreEqual(valueResult, value);

            rc = ypipe.CheckRead();
            Assert.IsTrue(rc);

            rc = ypipe.Unwrite(out valueResult);
            Assert.IsFalse(rc);
            Assert.AreEqual(valueResult, default(int));

            rc = ypipe.Read(out valueResult);
            Assert.IsTrue(rc);
            Assert.AreEqual(valueResult, value);

            rc = ypipe.CheckRead();
            Assert.IsFalse(rc);

            rc = ypipe.Read(out valueResult);
            Assert.IsFalse(rc);
            Assert.AreEqual(valueResult, default(int));

            ypipe.WriteBegin(ref value);
            rc = ypipe.CheckRead();
            Assert.IsFalse(rc);
            rc = ypipe.Read(out valueResult);
            Assert.IsFalse(rc);

            rc = ypipe.Write(ref value);
            Assert.IsFalse(rc);
            rc = ypipe.CheckRead();
            Assert.IsFalse(rc);
            rc = ypipe.Read(out valueResult);
            Assert.IsFalse(rc);

            rc = ypipe.Unwrite(out valueResult);
            Assert.IsTrue(rc);
            Assert.AreEqual(valueResult, value);

            rc = ypipe.WriteEnd(ref value);
            Assert.IsTrue(rc);
            rc = ypipe.CheckRead();
            Assert.IsTrue(rc);

            rc = ypipe.Unwrite(out valueResult);
            Assert.IsFalse(rc);
            Assert.AreEqual(valueResult, default(int));

            ypipe.Clear();
            Assert.AreEqual(ypipe.Count, 0);

            rc = ypipe.Write(ref value);
            Assert.IsTrue(rc);
            rc = ypipe.Write(ref value);
            Assert.IsTrue(rc);

            var array = ypipe.ReadAll();

            Assert.AreEqual(array.Length, 2);
            for (int i = 0; i < array.Length; i++)
            {
                Assert.AreEqual(array[i], value);
            }

            Assert.AreEqual(ypipe.Count, 0);
        }