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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:46:04+00:00 2026-05-18T08:46:04+00:00

Folks, I’ve a large legacy .Net code base, and I’m trying to introduce Unit

  • 0

Folks,
I’ve a large legacy .Net code base, and I’m trying to introduce Unit Testing to the team. They’re good guys but this is all new to them (to be honest it’s reasonably new to me too).

One of the problems is the code base makes heavy use of static classes in System.IO, there are extensive in-house libraries of static classes and classes aren’t written to interfaces (unless there’s an actual design reason to do so).

I’m developing an ease-it-in strategy using NUnit and FakeItEasy.

To address the static class dependencies I’ve written a tool that generates wrapper classes and interfaces for existing Static Classes. e.g. In a config file I say I want wrappers for System.IO Directory & File, the tool generates an assembly with code along the lines of . . .

public interface IFile
{
    // All Method signatures taken from System.IO.File
}

internal class File
    : IFile
{
    // All Methods delegate to System.IO.File
}

public interface IIO
{
    IFile File {get;}
    IDirectory Directory {get;}
}

internal class IO
    : IIO
{
    public IFile File {get; private set;}
    public IDirectory Directory {get; private set;}
    public IO()
    {
        File = new File();
        Directory = new Directory();
    }
}


public static class IO
{
    public IIO Instance {get; set;}
    static IO()
    {
        Instance = new IO();
    }
}

The idea is that in the existing code base can be simply updated by a find/replace and adding a new project reference, and that in unit tests you can assign a Mock object to IO.Instance.

One one hand I’m quite happy with this approach, it gives a clean and fast way to move away from using static classes directly, plus gives us a way to mock those static classes and lets us test code that depends on them.

On the other hand, I kind of feel I’ve done a deal with the devil, I’ve replaced dependencies on implicit singletons with dependencies on explicit singletons.

Is this all going to go horribly wrong for me sometime in the near future, or do you think this is a workable approach?

  • 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-18T08:46:04+00:00Added an answer on May 18, 2026 at 8:46 am

    I would do as you did for a legacy application. Not much you can do without having to refactor larger pieces. It’s still flexible since you can change implementation through the static class.

    One idea could be to only make the Instance method static and register the IO class in your IOC instead (as a singleton). Then let the IOC find the correct implementation (which is returned by the static Instance method).

    Nice introduction to IoC containers: http://joelabrahamsson.com/entry/inversion-of-control-introduction-with-examples-in-dotnet

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

Sidebar

Related Questions

No related questions found

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.