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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:34:07+00:00 2026-05-20T12:34:07+00:00

I am adding unit testing to the NerdDinner solution, and ran across this. I

  • 0

I am adding unit testing to the NerdDinner solution, and ran across this. I am testing the Edit POST method, given here:

    [AcceptVerbs(HttpVerbs.Post), Authorize]
    public virtual ActionResult Edit(int id, FormCollection formValues)
    {
        Dinner dinner = dinnerRepository.GetDinner( id );
        if (!dinner.IsHostedBy(User.Identity.Name))
        {
            return View(Views.InvalidOwner);
        }
        try
        {
            UpdateModel(dinner);
            dinnerRepository.Save();

            //return RedirectToAction("Details", new { id = dinner.DinnerID });
            return RedirectToAction(Actions.Details(dinner.DinnerID));
        }
        catch (Exception ex)
        {
            foreach (var issue in dinner.GetRuleViolations())
            {
                ModelState.AddModelError(issue.PropertyName, issue.ErrorMessage);
            }
            return View(new DinnerFormViewModel(dinner));
        }
    }

The System.TypeInitializationException is thrown on the “return RedirectToAction…” line, and says “The type initializer for ‘MVC’ threw an exception.”

When I replace the T4MVC-encoded line with the original line (commented out above), I do not get the exception.

Here is the unit test code:

    [TestMethod]
    public void EditAction_Should_Redirect_When_Update_Successful()
    {
        // Arrange
        var controller = CreateDinnersControllerAs("Some User");
        var formValues = new FormCollection
                             {
                                 { "Title", "Another Value" },
                                 { "Description", "Another Description" }
                             };
        controller.ValueProvider = formValues.ToValueProvider();

        // Act
        var result = controller.Edit(1, formValues) as RedirectToRouteResult;

        // Assert
        Assert.IsNotNull(result);
        Assert.AreEqual("Details", result.RouteValues["Action"]);
    }

I have a couple of ideas what may be causing this exception to be thrown, but I’m not sure enough to posit here. I’m totally unclear as to how to fix it.

Ideas?

Dave

  • 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-20T12:34:08+00:00Added an answer on May 20, 2026 at 12:34 pm

    MVC is a class generated by T4MVC. The error you are seeing simply means that an exception was thrown inside the constructor of this generated MVC class (note that “constructor” in this sense also means initialization of any fields that are assigned a value where declared).

    Open and save the T4MVC.tt file to ensure your code generated file is up to date. If that doesn’t help and you’re using the most recent version available, set a breakpoint in the constructor of the generated MVC class to find out what breaks it.

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

Sidebar

Related Questions

I'm strongly considering adding unit testing to an existing project that is in production.
I am Unit Testing one of my functions. Here is my code: public void
I am working to integrate unit testing into the development process on the team
I've been adding unit tests to some legacy C++ code, and I've run into
I am a fairly new software developer currently working adding unit tests to an
I'm looking into adding some unit tests for some classes in my data access
So I know that unit testing is a must. I get the idea that
Fo unit testing ASP.NET controls I need a stubbed Page. I can create an
Today I started adding unit tests to an ASP.NET MVC project we are developing
I followed Apple's instructions to set up Unit Testing in my project. I followed

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.