Exemplo n.º 1
0
        public void EnhancedMemoryStream_Int16()
        {
            var es = new EnhancedMemoryStream();

            es.WriteInt16(0);
            es.WriteInt16(55);
            es.WriteInt16(0x1234);

            es.Seek(0, SeekOrigin.Begin);

            Assert.AreEqual(0, es.ReadInt16());
            Assert.AreEqual(55, es.ReadInt16());
            Assert.AreEqual(0x1234, es.ReadInt16());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Renders the instance into a string suitable for using as an HTTP cookie.
        /// </summary>
        /// <returns>The cookie string.</returns>
        public override string ToString()
        {
            using (var ms = new EnhancedMemoryStream())
            {
                ms.WriteInt16(Magic);
                ms.WriteInt64(IssueDateUtc.Ticks);
                ms.WriteBytesNoLen(ID.ToByteArray());

                return(Convert.ToBase64String(ms.GetBuffer(), 0, (int)ms.Length));
            }
        }
Exemplo n.º 3
0
        public void EnhancedMemoryStream_VerifyBufLength()
        {
            var es = new EnhancedMemoryStream();

            es.WriteInt16(5000);
            es.Seek(0, SeekOrigin.Begin);
            try
            {
                es.ReadBytes16();
                Assert.Fail();
            }
            catch
            {
            }

            es.Seek(0, SeekOrigin.Begin);
            try
            {
                es.ReadString16();
                Assert.Fail();
            }
            catch
            {
            }

            es.Seek(0, SeekOrigin.Begin);
            es.WriteInt32(500000);
            try
            {
                es.ReadBytes32();
                Assert.Fail();
            }
            catch
            {
            }

            es.Seek(0, SeekOrigin.Begin);
            try
            {
                es.ReadString32();
                Assert.Fail();
            }
            catch
            {
            }
        }