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

  • Home
  • SEARCH
  • 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 8536975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:47:22+00:00 2026-06-11T10:47:22+00:00

I am testing Account Controller in asp.net mvc project. I tested all methods and

  • 0

I am testing Account Controller in asp.net mvc project. I tested all methods and I looked the code coverage results, I noticed the Initialize method is not coveraged.

How can I test this method?

public class AccountController : Controller
{

    public IFormsAuthenticationService FormsService { get; set; }
    public IMembershipService MembershipService { get; set; }

    protected override void Initialize(RequestContext requestContext)
    {
        if (FormsService == null) { FormsService = new FormsAuthenticationService(); }
        if (MembershipService == null) { MembershipService = new AccountMembershipService(); }

        base.Initialize(requestContext);
    }

I tried this test method but error occured.

           [TestMethod]
        public void Constructor_ReturnsController()
        {
            RequestContext requestContext = new RequestContext(new MockHttpContext(), new RouteData());
            AccountController controller = new AccountController
            {
                FormsService = null,
                MembershipService = null,
                Url = new UrlHelper(requestContext),
            };

            IController cont = controller;
            cont.Execute(requestContext);
        }

Error Message:

Test method MVC3Project.Tests.Controllers.AccountControllerTests+AccountControllerTest.Constructor_ReturnsController threw exception:
System.NotImplementedException: The method or operation is not implemented.

  • 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-11T10:47:23+00:00Added an answer on June 11, 2026 at 10:47 am

    You will need to invoke it explicitly in your unit test:

    [TestMethod]
    public void AccountController_Initialize_Method_Should_WireUp_Dependencies()
    {
        // arrange
        AccountController controller = new AccountController();
    
        // act
        controller.Initialize(null);
    
        // assert
        Assert.IsNotNull(controller.FormsService);
        Assert.IsNotNull(controller.MembershipService);
    }
    

    Note that using the Initialize method to setup your dependencies is bad practice. I would recommend you using dependency injection:

    public class AccountController : Controller
    {
    
        public IFormsAuthenticationService FormsService { get; private set; }
        public IMembershipService MembershipService { get; private set; }
    
        public AccountController(IFormsAuthenticationService formsService, IMembershipService membershipService)
        {
            FormsService = formsService;
            MembershipService = membershipService;
        }
    
        ... actions
    }
    

    Now you could setup your favorite dependency injection framework to inject those dependencies into your controller. For example with Ninject that’s pretty easy. Install the Ninject.MVC3 NuGet and then inside the generated ~/App_Start/NinjectWebCommon.cs file configure the kernel:

    /// <summary>
    /// Load your modules or register your services here!
    /// </summary>
    /// <param name="kernel">The kernel.</param>
    private static void RegisterServices(IKernel kernel)
    {
        kernel.Bind<IFormsAuthenticationService>().To<FormsAuthenticationService>();
        kernel.Bind<IMembershipService>().To<AccountMembershipService>();
    }        
    

    and finally you could mock those dependencies into your unit test and then define expectations on them.

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

Sidebar

Related Questions

In my Asp.net MVC app, I have two methods on a controller, one for
I'm looking at the generated code by ASP.NET MVC 1.0, and was wondering; what
Testing out someone elses code, I noticed a few JSP pages printing funky non-ASCII
I have an asp.net mvc 3 site running locally and everything works fine. I
We are developing an ASP.NET MVC web app that will be hosted on Windows
I am testing mvc field validation. For this I did a new ASP MVC
Hi i am testing android E-mail application . I have configured an Exchange account
I am playing with spring MVC 3.1 and testing different features. I wanted to
From the standard LogOn method in the account controller in MVC3 applications, how can
I want to write a test like the following: account = Account.find(1) @controller.should_receive(:authorize!).with(:create, instance_of(User,

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.