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 6841185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:56:08+00:00 2026-05-26T23:56:08+00:00

I am attempting to unit test the interactions of my application and the asynchronous

  • 0

I am attempting to unit test the interactions of my application and the asynchronous HttpWebRequest methods and am wondering how to simulate the call of the asynchronous callback. For instance, consider the following code:

Task.Factory
    .FromAsync<Stream>(wr.BeginGetRequestStream, wr.EndGetRequestStream, null)
    .ContinueWith(SomeDelegate);

In this case wr is an object that essentially wraps HttpWebRequest. I can stub and set expectations on this object in the unit test, but I can not think of a way to create the signal that would otherwise call EndRequestStream. Without this signal, the unit test blocks indefinitely waiting for the task to complete, which will never happen.

I can create interfaces and proxies for Task and TaskFactory, then set expectations at that level, but I am hoping there is something less involved.

  • 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-05-26T23:56:09+00:00Added an answer on May 26, 2026 at 11:56 pm

    Can you change the type of wr to expose a GetRequestAsync method that returns a Task<Stream>? That way you can mock it so that it returns a task from a TaskCompletionSource which you can prod within your test. I’ve done something similar with a class myself to test a composition block, and it worked well. The tests are interesting to write, in terms of all the different things that can happen, but it works…

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

Sidebar

Related Questions

I'm attempting to add a Test Settings file to my Unit Tests project in
I'm attempting to unit test some code using NUnit. I have a method: public
I am writing (attempting to write) unit tests for a WPF application. The business
In attempting to create an initial, failing unit test in Visual Studio Professonal 2008's
I'm attempting to create a unit test for my app in Symfony. My /config/app.yml
I have the following class structure that I need to unit test: public interface
I am attempting to run some unit tests in python from what I believe
I'm writing my first app with ASP.NET MVP (attempting Supervisory Controller) and Unit Testing
I'm attemping to add some unit tests to my application in Intellij. Since my
Attempting to implement a poor man's test of whether a process is still running

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.