Exemple #1
0
        public void op_Write_bytes_int_int()
        {
            try
            {
                const string expected = "<title>Test</title>";
                string       actual;

                var encoding = Encoding.UTF8;

                var response = new Mock <HttpResponseBase>(MockBehavior.Strict);
                response
                .Setup(x => x.ContentEncoding)
                .Returns(encoding)
                .Verifiable();
                response
                .Setup(x => x.ContentType)
                .Returns("text/html")
                .Verifiable();

                var context = new Mock <HttpContextBase>(MockBehavior.Strict);
                context
                .Setup(x => x.Response)
                .Returns(response.Object)
                .Verifiable();

                Static <HttpContextBase> .Instance = context.Object;

                using (var stream = new MemoryStream())
                {
                    var obj = new WrappedStream(stream);

                    var bytes = encoding.GetBytes("<title>Test</title>");
                    obj.Write(bytes, 0, bytes.Length);

                    bytes = encoding.GetBytes("</title>");
                    obj.Write(bytes, 0, bytes.Length);

                    stream.Position = 0;

                    var raw = new byte[expected.Length];
                    obj.Read(raw, 0, expected.Length);

                    actual = encoding.GetString(raw);
                }

                Assert.Equal(expected, actual);

                context.VerifyAll();
            }
            finally
            {
                Static <HttpContextBase> .Reset();
            }
        }
Exemple #2
0
        public void prop_Position_set()
        {
            using (var stream = new MemoryStream())
            {
                var obj = new WrappedStream(stream)
                {
                    Position = 0
                };

                Assert.Equal(stream.Position, obj.Position);
            }
        }
Exemple #3
0
        public void prop_ContentMD5_getEmpty()
        {
            const string expected = _emptyHash;
            string       actual;

            using (var stream = new MemoryStream())
            {
                actual = new WrappedStream(stream).ContentMD5;
            }

            Assert.Equal(expected, actual);
        }
Exemple #4
0
 public void op_Flush()
 {
     using (var stream = new MemoryStream())
     {
         using (var writer = new StreamWriter(stream))
         {
             writer.Write("a");
             var obj = new WrappedStream(stream);
             obj.Flush();
             Assert.Equal(0, obj.Length);
         }
     }
 }
 public void op_Flush()
 {
     using (var stream = new MemoryStream())
     {
         using (var writer = new StreamWriter(stream))
         {
             writer.Write("a");
             var obj = new WrappedStream(stream);
             obj.Flush();
             Assert.Equal(0, obj.Length);
         }
     }
 }
Exemple #6
0
        public void op_SetLength_long()
        {
            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    writer.Write("abc");
                    writer.Flush();
                    stream.Position = 0;

                    var obj = new WrappedStream(stream);
                    obj.SetLength(10);
                    Assert.Equal(10, obj.Length);
                }
            }
        }
Exemple #7
0
        public void prop_ContentMD5_get()
        {
            const string expected = _emptyHash;
            string       actual;

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    writer.Write(_jigsawHtml);
                    writer.Flush();
                    stream.Position = 0;

                    actual = new WrappedStream(stream).ContentMD5;
                }
            }

            Assert.Equal(expected, actual);
        }
        public void prop_Position_set()
        {
            using (var stream = new MemoryStream())
            {
                var obj = new WrappedStream(stream)
                              {
                                  Position = 0
                              };

                Assert.Equal(stream.Position, obj.Position);
            }
        }
        public void prop_ContentMD5_getEmpty()
        {
            const string expected = _emptyHash;
            string actual;

            using (var stream = new MemoryStream())
            {
                actual = new WrappedStream(stream).ContentMD5;
            }

            Assert.Equal(expected, actual);
        }
        public void prop_ContentMD5_get()
        {
            const string expected = _emptyHash;
            string actual;

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    writer.Write(_jigsawHtml);
                    writer.Flush();
                    stream.Position = 0;

                    actual = new WrappedStream(stream).ContentMD5;
                }
            }

            Assert.Equal(expected, actual);
        }
        public void op_Write_bytes_int_int()
        {
            try
            {
                const string expected = "<title>Test</title>";
                string actual;

                var encoding = Encoding.UTF8;

                var response = new Mock<HttpResponseBase>(MockBehavior.Strict);
                response
                    .Setup(x => x.ContentEncoding)
                    .Returns(encoding)
                    .Verifiable();
                response
                    .Setup(x => x.ContentType)
                    .Returns("text/html")
                    .Verifiable();

                var context = new Mock<HttpContextBase>(MockBehavior.Strict);
                context
                    .Setup(x => x.Response)
                    .Returns(response.Object)
                    .Verifiable();

                Static<HttpContextBase>.Instance = context.Object;

                using (var stream = new MemoryStream())
                {
                    var obj = new WrappedStream(stream);

                    var bytes = encoding.GetBytes("<title>Test</title>");
                    obj.Write(bytes, 0, bytes.Length);

                    bytes = encoding.GetBytes("</title>");
                    obj.Write(bytes, 0, bytes.Length);

                    stream.Position = 0;

                    var raw = new byte[expected.Length];
                    obj.Read(raw, 0, expected.Length);

                    actual = encoding.GetString(raw);
                }

                Assert.Equal(expected, actual);

                context.VerifyAll();
            }
            finally
            {
                Static<HttpContextBase>.Reset();
            }
        }
        public void op_SetLength_long()
        {
            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    writer.Write("abc");
                    writer.Flush();
                    stream.Position = 0;

                    var obj = new WrappedStream(stream);
                    obj.SetLength(10);
                    Assert.Equal(10, obj.Length);
                }
            }
        }