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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:44:20+00:00 2026-05-10T14:44:20+00:00

I want to wrap a piece of code that uses the Windows Impersonation API

  • 0

I want to wrap a piece of code that uses the Windows Impersonation API into a neat little helper class, and as usual, I’m looking for a way to go test-first. However, while WindowsIdentity is a managed class, the LogonUser call that is required to actually perform the logging in as another user is an unmanaged function in advapi32.dll.

I think I can work around this by introducing an interface for my helper class to use and hiding the P/Invoke calls in an implementation, but testing that implementation will still be a problem. And you can imagine actually performing the impersonation in the test can be a bit problematic, given that the user would actually need to exist on the system.

  • 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-10T14:44:21+00:00Added an answer on May 10, 2026 at 2:44 pm

    Guideline: Don’t test code that you haven’t written.
    You shouldn’t be concerned with WinAPI implementation not working (most probably it works as expected). Your concern should be testing the ‘Wiring’ i.e. if your code makes the right WinAPI call. In which case, all you need is to mock out the interface and let the mock framework tell if you the call was made with the right params. If yes, you’re done.

    • Create IWinAPIFacade (with relevant WinAPI methods) and implementation CWinAPIFacade.
    • Write a test which plugs in a mock of IWinAPIFacade and verify that the appropriate call is made
    • Write a test to ensure that CWinAPIFacade is created and plugged in as a default (in normal functioning)
    • Implement CWinAPIFacade which simply blind-delegates to Platform Invoke calls – no need to auto-test this layer. Just do a manual verification. Hopefully this won’t change that often and nothing breaks. If you find that it does in the future, barricade it with some tests.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've written a class in python that I want to wrap into a .net
I've got a (poorly written) base class that I want to wrap in a
I have a piece of C++ code that generates the data. I want to
Suppose I want to wrap code that can throw exceptions with a try-catch block
I want to wrap any tag that contains a href attribute into an <a>
I have the following script that is working great, but I want to wrap
I have some C source code and want to wrap it in Cython. Now,
I want to wrap my code in a function (and then put it in
I want to wrap the default open method with a wrapper that should also
I want to wrap my recipient email in my string assignment that has 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.