Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9023883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:52:15+00:00 2026-06-16T05:52:15+00:00

I have the following method that writes a stream in a HttpResponse object. public

  • 0

I have the following method that writes a stream in a HttpResponse object.

public HttpResponse ShowPDF(Stream stream)
    {
        MemoryStream memoryStream = (MemoryStream) stream;

        httpResponse.Clear();
        httpResponse.Buffer = true;
        httpResponse.ContentType = "application/pdf";
        httpResponse.BinaryWrite(memoryStream.ToArray());
        httpResponse.End();

        return httpResponse;

    }

In order to test it, I need to recover the processed stream.
Is there someway to read the stream from the httpResponse object?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:52:16+00:00Added an answer on June 16, 2026 at 5:52 am

    I have two ideas… one to mock the HttpResponse, and the other is to simulate a web server.

    1. Mocking HttpResponse

    I wrote this before I knew which mocking framework you used. Here’s how you could test your method using TypeMock.

    This assumes that you pass your httpResponse variable to the method, changing the method as follows:

    public void ShowPDF(Stream stream, HttpResponse httpResponse)
    

    Of course you would change this to passing it to a property on your Page object instead, if it is a member of your Page class.

    And here’s an example of how you could test using a fake HttpResponse:

    internal void TestPDF()
    {
        FileStream fileStream = new FileStream("C:\\deleteme\\The Mischievous Nerd's Guide to World Domination.pdf", FileMode.Open);
        MemoryStream memoryStream = new MemoryStream();
        try
        {
            memoryStream.SetLength(fileStream.Length);
            fileStream.Read(memoryStream.GetBuffer(), 0, (int)fileStream.Length);
    
            memoryStream.Flush();
            fileStream.Close();
    
            byte[] buffer = null;
    
            var fakeHttpResponse = Isolate.Fake.Instance<HttpResponse>(Members.ReturnRecursiveFakes);
            Isolate.WhenCalled(() => fakeHttpResponse.BinaryWrite(null)).DoInstead((context) => { buffer = (byte[])context.Parameters[0]; });
    
            ShowPDF(memoryStream, fakeHttpResponse);
    
            if (buffer == null)
                throw new Exception("It didn't write!");
        }
        finally
        {
            memoryStream.Close();
        }        
    }
    

    2. Simulate a Web Server

    Perhaps you can do this by simulating a web server. It might sound crazy, but it doesn’t look like it’s that much code. Here are a couple of links about running Web Forms outside of IIS.

    Can I run a ASPX and grep the result without making HTTP request?

    http://msdn.microsoft.com/en-us/magazine/cc163879.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an interface (called Subject ) that has the following method: public void
I have the following method which creates instances of objects that are disposable. Public
I have an extension method that looks like the following: //[MethodImpl(MethodImplOptions.NoOptimization)] public static IEnumerable<char>
I have the following method that returns void and I need to use it
I have the following method that is replacing a pound sign from the file
I have the following method that is supposed to be a generic Save to
I have the following static method that prints the data imported from a 40.000
I have a method that contains the following (Java) code: doSomeThings(); doSomeOtherThings(); doSomeThings() creates
I have a method that I will use in the following contexts: 1. User
I have a program that makes use of the following method to get a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.