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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:29:14+00:00 2026-05-27T23:29:14+00:00

I am trying to create a NUnit test for a project that uses Ninject.

  • 0

I am trying to create a NUnit test for a project that uses Ninject. The Ninject was installed via Nuget, so the Configuration clas looks similar to this simplified version:

[assembly: WebActivator.PreApplicationStartMethod(typeof(NinjectMVC3), "Start")]
[assembly: WebActivator.ApplicationShutdownMethodAttribute(typeof(NinjectMVC3), "Stop")]

public static class NinjectMVC3 
{
    private static readonly Bootstrapper Bootstrapper = new Bootstrapper();

    private static IKernel _kernel;

    public static void Start() 
    {
        DynamicModuleUtility.RegisterModule(typeof(OnePerRequestModule));
        DynamicModuleUtility.RegisterModule(typeof(HttpApplicationInitializationModule));
        Bootstrapper.Initialize(CreateKernel);
    }

    public static void Stop()
    {
        Bootstrapper.ShutDown();
    }
}

I want those methods to be called in my startup test class. I tried:

[TestFixture]
public class TestBase
{

    [SetUp]
    public void Setup()
    {
        NinjectMVC3.Startup();
    }


    [TearDown]
    public void TearDown()
    {
        NinjectMVC3.TearDown();
    }
}

It will not work because I am trying to manually call methods that are managed by WebActivator. So I am looking for a way to instruct WebActivator to call those methods in a ‘right time’. Let me remind you that there are two project that I am dealing with, one is a MVC Web Project (and it uses WebActivator for Ninject), and the other one is a Test project for my MVC Web Project. I tried to call WebActivator by changing implementation of my Setup method:

[SetUp]
public void Setup()
{
    WebActivator.ActivationManager.Run();
}

It doesn’t work. As far As I understand underneath this call WebActivator should do something similar to:

foreach (var assemblyFile in Directory.GetFiles(HttpRuntime.BinDirectory, "*.dll")) {
    var assembly = Assembly.LoadFrom(assemblyFile);
    foreach (PreApplicationStartMethodAttribute preStartAttrib in assembly.GetCustomAttributes(
        typeof(PreApplicationStartMethodAttribute),
        inherit: false)) {
        preStartAttrib.InvokeMethod();
    }
}

So I guess that it is unable to find an assembly. So the question is – how can I order WebActivator to scan thru some additional assembly and fire some methods in a ‘right time’. Or maybe I am mislead here, and in order to test my Ninject project I should take a different approach?

I am able to test my solutions w/o WebActivator, but because it is widely used recently, I am keen to learn how to deal with it and force it to do things that I want.

  • 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-27T23:29:15+00:00Added an answer on May 27, 2026 at 11:29 pm

    Unfortunately by default WebActivator looks for a “*.dll” in a c:\tmp… directory, and due to that it is unable to find project libriaries that are included to the solution.

    I ended up geting the source code and adding a following code to the ActivationManager class:

    public static void AddAssembly(Assembly assembly)
    {
        if (_assemblies == null)
        {
            _assemblies = new List<Assembly>();
        }
        _assemblies.Add(assembly);
    }
    

    And in test class:

     private const int PreStartInitStage_DuringPreStartInit = 1;
        [SetUp]
        public void Setup(){
            WebActivator.ActivationManager.AddAssembly(Assembly.GetAssembly(typeof(NinjectMVC3)));
            typeof(BuildManager).GetProperty("PreStartInitStage", BindingFlags.NonPublic | BindingFlags.Static).SetValue(null, PreStartInitStage_DuringPreStartInit, null);
            WebActivator.ActivationManager.RunPreStartMethods();
            Kernel = NinjectMVC3.GetKernel();
        }
    

    This is ugly code, and I hope to see one day a better approach.

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

Sidebar

Related Questions

Iam trying to create a new test project. I remember selecting the names of
Trying to create a simple plugin that simply connects to an ftp site, looks
I am trying to test a class in Service handler using NUnit project. My
I'm trying to create a nUnit test to do the following: 1) Load the
I use NUnit integration tests. I am trying to test to make sure that
I am trying create a WCF service that leverages the WPF MediaPlayer on the
Trying to create a user account in a test. But getting a Object reference
Trying to create my first iPhone app that would play back audio. When I
Trying to create a small monitor application that displays current internet usage as percentage
I'm trying to write a test for an UrlHelper extensionmethod that is used like

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.