public void When_Get_Length_Then_0()
 {
     using (var filter = new CapturingResponseFilter(new MemoryStream()))
     {
         Assert.That(filter.Length, Is.EqualTo(0));
     }
 }
 public void When_Seek_Then_0()
 {
     using (var filter = new CapturingResponseFilter(new MemoryStream()))
     {
         Assert.That(filter.Seek(0, SeekOrigin.Current), Is.EqualTo(0));
     }
 }
 public void When_CanRead_Then_True()
 {
     using(var filter = new CapturingResponseFilter(new MemoryStream()))
     {
         Assert.That(filter.CanRead, Is.True);
     }
 }
 public void When_CanWrite_Then_False()
 {
     using (var filter = new CapturingResponseFilter(new MemoryStream()))
     {
         Assert.That(filter.CanWrite, Is.False);
     }
 }
예제 #5
0
        /// <summary>Renders the action and returns a string.</summary>
        /// <param name="viewRenderer">The delegate to render.</param>
        /// <returns>The rendered text.</returns>
        public string Capture(Action viewRenderer)
        {
            HttpResponseBase resp = _httpContext.Response;
            Stream originalFilter = null;
            CapturingResponseFilter innerFilter;
            string capturedHtml = "";

            if (viewRenderer != null)
            {
                try
                {
                    resp.Flush();
                    originalFilter = resp.Filter;
                    innerFilter = new CapturingResponseFilter(resp.Filter);
                    resp.Filter = innerFilter;
                    viewRenderer();
                    resp.Flush();
                    capturedHtml = innerFilter.GetContents(resp.ContentEncoding);
                }
                finally
                {
                    if (originalFilter != null)
                    {
                        resp.Filter = originalFilter;
                    }
                }
            }
            return capturedHtml;
        }
예제 #6
0
        /// <summary>Renders the action and returns a string.</summary>
        /// <param name="viewRenderer">The delegate to render.</param>
        /// <returns>The rendered text.</returns>
        public string Capture(Action viewRenderer)
        {
            HttpResponseBase        resp           = _httpContext.Response;
            Stream                  originalFilter = null;
            CapturingResponseFilter innerFilter;
            string                  capturedHtml = "";

            if (viewRenderer != null)
            {
                try
                {
                    resp.Flush();
                    originalFilter = resp.Filter;
                    innerFilter    = new CapturingResponseFilter(resp.Filter);
                    resp.Filter    = innerFilter;
                    viewRenderer();

                    resp.Flush();
                    capturedHtml = innerFilter.GetContents(resp.ContentEncoding);
                }
                finally
                {
                    if (originalFilter != null)
                    {
                        resp.Filter = originalFilter;
                    }
                }
            }
            return(capturedHtml);
        }
 public void When_Set_Position_Then_Get_Position()
 {
     using (var filter = new CapturingResponseFilter(new MemoryStream()))
     {
         filter.Position = 100;
         Assert.That(filter.Position, Is.EqualTo(100));
     }
 }
 public void Then_GetContents_Returns_The_Contents()
 {
     string text = null;
     using(var sink = new MemoryStream())
     using(var filter = new CapturingResponseFilter(sink))
     {
         {
             byte[] bytes = Encoding.UTF8.GetBytes("Goose");
             filter.Write(bytes, 0, bytes.Length);
             text = filter.GetContents(Encoding.UTF8);
         }
         Assert.That(text, Is.EqualTo("Goose"));
     }
 }
            public void When_SetLength_Then_Sink_SetLength()
            {
                var sink = _mocks.DynamicMock<Stream>();

                using (_mocks.Record())
                {
                    sink.SetLength(100);
                }
                using (_mocks.Playback())
                {
                    using (_filter = new CapturingResponseFilter(sink))
                        _filter.SetLength(100);
                }
            }
 public void When_Read_Then_Sink_Is_Read()
 {
     var sink = _mocks.DynamicMock<Stream>();
     var buf = new byte[100];
     using (_mocks.Record())
     {
         Expect.Call(sink.Read(buf, 0, 20)).Return(0);
     }
     using (_mocks.Playback())
     {
         using (_filter = new CapturingResponseFilter(sink))
             _filter.Read(buf, 0, 20);
     }
 }
            public void When_Flush_Then_Sink_Is_Flushed()
            {
                var sink = _mocks.DynamicMock<Stream>();

                using (_mocks.Record())
                {
                    sink.Flush();
                }
                using (_mocks.Playback())
                {
                    using (_filter = new CapturingResponseFilter(sink))
                        _filter.Flush();
                }
            }