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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:34:45+00:00 2026-05-29T10:34:45+00:00

So here is the scenario, I am refactoring some spaghetti code. My first problem

  • 0

So here is the scenario, I am refactoring some spaghetti code. My first problem was a chain of classes that newed up other classes, I fixed this by making the ctor of the class I want to test (Search.cs) take the class it needs as a dependency, it looks like this now.

 public Search(XmlAccess xmlFile, SearchDatabaseConnect searchDatabaseConnection)
    {
        this.xmlFile = xmlFile;
        FsdcConnection = searchDatabaseConnection;
        Clear();
    }

I’m newing it up further up the chain. That is all good but I have a little problem.

The class that I am ctor injecting inherits from another class, I have Resharper and I have extracted interfaces but the problem is the dependency class inherits from another concrete class – see what I mean?

 public class SearchDatabaseConnect : DatabaseConnect, ISearchDatabaseConnect 
{ // }

I don’t know what to do about the inheritance on DatabaseConnect? How do I mock that? Obviously if that wasn’t there I would be all set I could mock an ISearchDatabaseConnect and away we go but I am stuck on the inheritance of a concrete class. I am sure people have run into this before my googl’ing was a failure when it came to finding examples about this.

Thanks in advance for any useful suggestions.

  • 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-29T10:34:46+00:00Added an answer on May 29, 2026 at 10:34 am

    Does DatabaseConnect also have an interface extracted from it? I think you should be able to set it up like:

    public interface IDatabaseConnect
    
    public class DatabaseConnect : IDatabaseConnect
    
    public interface ISearchDatabaseConnect : IDatabaseConnect
    
    public class SearchDatabaseConnect : DatabaseConnect, ISearchDatabaseConnect
    

    And now making a Mock<ISearchDatabaseConnect> will get all the “stuff” from both interfaces.


    Side-note, your method/constructor there should probably take in the interface, not the concrete:

    public Search(XmlAccess xmlFile, ISearchDatabaseConnect searchDatabaseConnection) { ... }
    

    That way you can inject the mock, like:

    var mockedSearchDatabaseConnect = new Mock<ISearchDatabaseConnect>();
    var search = new Search(xmlFile, mockedSearchDatabaseConnect.Object);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, I'll do my best to explain the problem here: The scenario is that
Let me try to set the scenario here first. This is done using ASP.NET
Here's my scenario - I have an SSIS job that depends on another prior
Here is the scenario: I'm writing an app that will watch for any changes
Here is the scenario that I have. I have a cvs repository in one
Here's the scenario: You have a Windows server that users remotely connect to via
Here's the scenario. I'm debugging my own app (C/C++) which is using some library
I have a rather odd scenario here, hoping someone might have some insight. I
Right, so here the scenario: I've created a class called DiaryPage that inherites from
I am having a strange problem. Here is the scenario Here are my files:

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.