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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:06:45+00:00 2026-06-12T23:06:45+00:00

I am really new to ninject and testing too. I have an mvc4 application

  • 0

I am really new to ninject and testing too.

I have an mvc4 application that I want to start writing tests for. (Yes I know I am meant to write them as I go:) )

Within my NinjectWebCommon

  private static IKernel CreateKernel()
    {
        var kernel = new StandardKernel();
        kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
        kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();

        RegisterServices(kernel);
        return kernel;
    }

    private static void RegisterServices(IKernel kernel)
    {
        kernel.Bind<IConsumerRepository>().To<ConsumerRepository>();
    }

I have written everything in repository’s within my application for example I have

public interface IConsumerRepository
{
    ConsumerModel GetConsumerByUserId(Guid userId);
}
public ConsumerModel GetConsumerByUserId(Guid userId)
    {
        if (HttpContext.Current.Session["ConsumerInfo"] == null)
        {
            var data = RestSharperHelper.GetById<ConsumerModel>("id", userId, ApiEndPointConstants.GetConsumerById);
            LogMessage(data.UserName);
            HttpContext.Current.Session["ConsumerInfo"] = data;
            return data;
        }
        else
        {
            return (ConsumerModel)HttpContext.Current.Session["ConsumerInfo"];
        }
    }

Whats the best way for me to write a test to check that a ConsumerModel is returned from web applications repository? I want it be flexible as in time I want to write more complicated tests and provide a mock ConsumerModel instead of calling the api like the above everytime

Thank you for any 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-06-12T23:06:46+00:00Added an answer on June 12, 2026 at 11:06 pm

    The MVCContrib TestHelper might help. It’ll help you unit test your controller actions and will also initialise all those parts like HttpContext and Session:

    http://mvccontrib.codeplex.com/wikipage?title=TestHelper

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

Sidebar

Related Questions

I'm really new at using awk/sed So, I have text file that is called
I'm really new to android and I got an issue that I don't clearly
I am really new to the programming but I am studying it. I have
I am really new with PHP and all I have to do is to
Im really really new to Javascript but Ive got this script that loads the
I'm really new to testing so go easy on me. I've got Seleneium working
I'm just getting started with IoC containers and have picked up Ninject to start
Im really new to javascript testing. I'm able to test all other functions of
I want to create a simple Ninject provider that returns Moq'd instances instead of
I really new to Python and coding in general, but I have been making

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.