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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:15:54+00:00 2026-06-12T09:15:54+00:00

Below I have some code that that I cannot Unit test because it tries

  • 0

Below I have some code that that I cannot Unit test because it tries to read settings from IIS7 and unfortunately our nightly build machine does not have IIS7. The only thing I can think of is to pass the ServerManager into the method, but then again in the caller I will have a ServerManager that will make that method unable to be unit tested. We use MOQ for our Mock library.

        public ISection GetCurrentSettings(string location, Action<string> status)
    {
        #region Sanity Checks

        if (string.IsNullOrEmpty(location))
        {
            throw new ArgumentNullException("location");
        }
        if (status == null)
        {
            throw new ArgumentNullException("status");
        }
        #endregion

        ISection section = null;

        _logger.Debug(string.Format("Retrieving current IIS settings for app at {0}.", location));
        status("Getting current IIS settings.");
        using (ServerManager manager = new ServerManager())
        {
            var data = (from site in manager.Sites
                        from app in site.Applications
                        from vdir in app.VirtualDirectories
                        where vdir.PhysicalPath.Equals(location, StringComparison.CurrentCultureIgnoreCase)
                        select new {Website = site, App = app}).SingleOrDefault();

            if (data == null)
            {
                _logger.Debug(string.Format("Could not find an application at {0} in IIS. Going to load the defaults instead.", location));
                //ToDo possibly load defaults
            }
            else
            {
               _logger.Debug(string.Format("Application found in IIS with website: {0} and a path of {1}", data.Website.Name, data.App.Path));
                int port =
                    data.Website.Bindings.Where(b => b.EndPoint != null).Select(b => b.EndPoint.Port).Single();


                section = new IISSection
                    {
                        ApplicationPoolName = data.App.ApplicationPoolName,
                        VirtualDirectoryAlias = data.App.Path,
                        WebsiteName = data.Website.Name,
                        WebsiteRoot = data.App.VirtualDirectories[0].PhysicalPath,
                        Port = port.ToString(CultureInfo.InvariantCulture),
                        WillApply = true,
                        AnonymousUser = _userService.GetUserByType(UserType.Anonymous)
                    };
            }

            return section;

        }
  • 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-12T09:15:54+00:00Added an answer on June 12, 2026 at 9:15 am

    Without rewriting your code fully, the general idea would be to pass in an ISettingReader* (implemented as IisSettingReader), which would expose methods that would get the data you need from IIS. Then, you can stub in the ISettingReader to return what you need, by passing ISettingReader into the method/class

    *Or, IServerManager as it seems to be the current name, but I am not sure if that is IIS specific

    UPDATE

    To be more specific, as Darin Dimitrov elaborated, you need to pull all of the dependencies outside of the method and pass them in via parameter/constructor/property injection. This will require a rewrite of the code as it stands in its current state.

    If not (and I do suggest a rewrite), then you can use something like TypeMock, which supposedly can fake the dependencies INSIDE a class, but I have not used this myself and only know what I have read on it.

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

Sidebar

Related Questions

Edit: original question below, but I revise it now that I have some code
I have some really funky code. As you can see from the code below
I have a function(please see code below) which reads some data from the web.
I have some code (see below) that works as expected under Python 2, but
I have some code as shown below: - (IBAction)startButtonPressed:(id)sender { statusText.text = @Processing...; //here
I have some doubt on below code #include<stdio.h> int i=6; int main() { int
I have some problem with my cfml website. I have used the below code
UPDATE - I have fixed some mistakes in the code below and the images
i have the code for View and the ViewModel below and some how the
I'm wondering about the .childNodes property, I have the code below, and for some

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.