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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:59:39+00:00 2026-05-29T16:59:39+00:00

I am able to Mole WebRequest.CreateUri so that I can replace the hostname of

  • 0

I am able to Mole WebRequest.CreateUri so that I can replace the hostname of the request with another. However, I would like to Mole Dns.GetAddrInfo instead so that I can keep the hostname the same, but make it so that the hostname resolves to another IP address.

In this way, I do not have to edit my hosts file for example as this is a less flexible approach.

Any advice?

Thank you.

Edit
I’ve uploaded a sample Visual Studio 2010 sln to the problem here:

When opening the sln,

  1. Click on the “Create Virtual Directory” button in the Service project properties’ Web tab.
  2. Rebuild the solution
  3. Add the following entry to c:\windows\system32\drivers\etc\hosts:
    127.0.0.1 www.productionserver.com
  4. Run the TestMethod1 unit test in the Tests project.
    The unit tests should succeed.
  5. Remove the entry from the hosts file and re-run the unit test.
    It should fail.

I have looked at the implementation of System.ServiceModel.ClientBase<TChannel> using a decompiler and noticed that it eventually calls System.Net.Dns.GetAddrInfo to resolve the hostname to an IP address.

I am hoping this sln is simple enough to update and send back (or just comment what needs to be done and\or changed) so I can simply see what is required to solve the problem.

Thank you.

Edit 2
It seems this is not currently possible with Moles.

  • 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-29T16:59:44+00:00Added an answer on May 29, 2026 at 4:59 pm

    The System.Net stack generally can not be moled, as much of he functionality are outside the control of the managed code.

    Instead, create an interface and stub in your production code. Use the interface with dependency injection, to pass the stub to the target code. This stub simply calls the System.Net methods you wish to intercept, during testing.

    Moles will automatically generate a Stub type, from the interface. Simply instantiate the stub type, detour the desired methods/properties/events of the stub, and then pass the Stub type to the method being tested.

    Using stubs and dependency injection works wherever Mole types can not be created.

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

Sidebar

Related Questions

I would like be able to run a single command in my project folder
Am able to load and call the functions but I would like to reload
I want to be able to capture the exception that is thrown when a
Not able to get a clear distinction between these concepts that are used very
Iam able to upload the image using MTOM-XOP by value concept.After that I tried
Being able to create javascript code on the fly is pretty cool. That is
I able to use LocalizedResource.properties with uibinder. let say i have widget that created
I'm able to perform a search over the Facebook API and I'm aware that
Would someone be able to point in the right direction for a similar jquery
I want to be able to list the items that either a user has

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.