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

  • Home
  • SEARCH
  • 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 54577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:14:31+00:00 2026-05-10T17:14:31+00:00

I have a C# module responsible for acquiring the list of network adapters that

  • 0

I have a C# module responsible for acquiring the list of network adapters that are ‘connected to the internet’ on a windows Vista machine. The module uses the ‘Network List Manager API‘ (or NLM API) to iterate over all network connections and returns all those for which the IsConnectedToInternet value is true.

I received some suggestions for the implementation of this module in this SO question

To test this module I’ve decided to write a helper that returns the list of internet connected interfaces based on another logic, so it would be a sort of a ‘reality check’ for the original module’s logic. Note that for the test helper I am willing to use detection methods that might be considered bad practice for production code (e.g. relying on some internet resource like ‘Google’ to be available – in case it shuts down, blocked by our internal firewall etc. it’s relatively easy to fix the test as opposed to a deployed product base).

The alternative detection method I chose was to try to connect to ‘www.google.com:80’ with a TcpClient. My problem: When I have more than one connected adapter (e.g. both wireless and LAN) the detection method fails for one of them with the error ‘A connect request was made on an already-connected socket’.

My question is three fold:

  1. How would you go about testing such a module in general? Do you support the idea of doing the same thing in a different way and comparing the results or is it an overkill and I should rely on the system’s API? My main problem here, is that it’s very hard to pre-configure the system so that I’ll know what the expected results are in advance.

  2. What alternative logic would you suggest? One thing that was suggested in the aforementioned question was looking at the routing table – what about considering each adapter that has a routing entry with a destination of 0.0.0.0 as ‘connected to the internet’? Other suggestions?

  3. Do you understand why I get the ‘already-connected’ error with the current test logic?

  • 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. 2026-05-10T17:14:31+00:00Added an answer on May 10, 2026 at 5:14 pm

    I can only answer your question about the unit test.

    The code you’re testing is, in your own words, ‘a C# module responsible for acquiring the list of network adapters that are ‘connected to the internet’ on a windows Vista machine. The module uses the ‘Network List Manager API’ (or NLM API) to iterate over all network connections and returns all those for which the IsConnectedToInternet value is true.’

    If I were writing this module, I would first use an interface for the NLM API, call it…NLMAPIService. Now, for the real code, create an Adapter that implements NLMAPIService and adapts the real NLM API.

    For testing, create a class FakeNLMAPI that implements NLMAPIService and has all of its data in-memory somewhere, or in an XML file, or whatever. Your module calls methods only on the NLMAPIService, so you don’t have to change any ‘real’ code depending on whether you’re testing or not.

    Therefore, in your test setup method, you can instantiate FakeNLMAPI and pass it to your module, and in production, instantiate your NLM API Adapter.

    I’m going to assume that you can instantiate and modify the object that represents a network connection. If not, you can follow the same pattern for faking the actual network connection object.

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

Sidebar

Related Questions

I have a module that is responsible for reading, processing, and writing bytes to
I have a module that is responsible for handling special products in ubercart (product
I have module application. When I run it, the main window of that app
I have module that implements custom content type via NodeAPI hooks ( hook_insert ,
I have this module pattern that stores a bunch of vars. I want to
I have a module that is being used to create only a few page
I have an class definition with a __hash__ function that uses the object properties
I have developed module with sql script upgrade and after that my phpunit tests
I have a module which will be responsible for parsing CSV data received from
I have a project with multiple modules, including on that is responsible for building

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.