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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:36:39+00:00 2026-06-04T21:36:39+00:00

I am familiar with the fact, that i should not use dependency injection in

  • 0

I am familiar with the fact, that i should not use dependency injection in unit tests, so i can unit test each layer independently.

Still, I want to create integration tests for my controllers. Therefore I need to inject my repositories into the Controllers from a unit test.

I a following a generic approach using a T4 script, that creates a test class for each controller, containing a test method for each ActionResult. This test method should simply call the method to make sure no exceptions are thrown to the surface.

Because of using this T4 script, I cannot manually feed the repositories into the controllers. I need to make use of dependency injection.

Based on my former experience, this should work, but i keep getting the error:

Unable to get default constructor for class <<UnitTest>>

My generated classes look like this at the moment:

[TestClass]
public class TestControllersHomeController
{
    private EL.NET.Web.Controllers.HomeController c;
    //setup
    public TestControllersHomeController(Project.Controllers.HomeController c)
    {
        this.c = c;
    }
    [ClassInitialize]
    public void ClassInitialize()
    {

        var kernel = NinjectWebCommon.CreatePublicKernel();
        kernel.Bind<TestControllersHomeController>().ToSelf();
        kernel.Bind<Project.Controllers.HomeController>().ToSelf();
    }
    [TestMethod]
    public void TestIndex()
    {
        var result = c.Index();
        Assert.IsNotNull(result);
    }

Edit:

I already found out, that the repositories can be loaded with help of the GetService() method of IKernel. But for the Membership provider, this doesn’t work.
Again, I do not want to mock the provider, I want to perform an integration test so I know if my Controller methods throw any exceptions.

  • 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-04T21:36:41+00:00Added an answer on June 4, 2026 at 9:36 pm

    The unit test must have a default constructor:

    [TestClass]
    public class TestControllersHomeController
    {
        private HomeController _sut;
    
        [TestInitialize]
        public void MyTestInitialize() 
        {
            var kernel = NinjectWebCommon.CreatePublicKernel();
            _sut = kernel.Resolve<HomeController>();
        }
    
        [TestMethod]
        public void TestIndex()
        {
            var result = _sut.Index();
            Assert.IsNotNull(result);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm familiar with the fact that you can create LaTeX reports directly from R
I familiar with the fact that I should set the HTTP_RPOXY environment variable to
Pardon me for the woolly question - I'm not really that familiar with OLAP
Being very familiar with the subversion workflow and that fact that 99.9% of the
I realize that referring to these as dimension and fact tables is not exactly
I am familiar with the fact that exception thrown in a thread normally couldn't
I am familiar with the fact that an interface contains only the signatures of
People familiar with Homographies will know that you have to normalize it dividing by
Anyone familiar with a way how can I can i write something to the
I am not terribly familiar with either tech, so bear with me. I have

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.