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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:27:05+00:00 2026-06-02T10:27:05+00:00

I cannot successfully run unit tests for MvcMailer using the visual studio test suite

  • 0

I cannot successfully run unit tests for MvcMailer using the visual studio test suite and Moq.
I have copied the example from the wiki word for word but get the following exception every time:

Test method MvcMailerTest.Tests.MailerTest.TestMethod1 threw exception: 
System.ArgumentNullException: Value cannot be null.
Parameter name: httpContext

Code is as follows: (Using the VS unit test framework – exact same error when using nUnit as in the example)

        //Arrange: Moq out the PopulateBody method
        var _userMailerMock = new Mock<UserMailer>();
        _userMailerMock.Setup(mailer => mailer.PopulateBody(It.IsAny<MailMessage>(), "Welcome", null));            
        _userMailerMock.CallBase = true;

        //Act
        var mailMessage = _userMailerMock.Object.Welcome();

Fails on the following line in the Welcome() method (copied straight out of the wiki):

 PopulateBody(mailMessage, viewName: "Welcome");

The wiki is here: https://github.com/smsohan/MvcMailer/wiki/MvcMailer-Step-by-Step-Guide

Similar (almost exactly the same) Question: MvcMailer: Can't complete NUnit tests on Razor Views which use Url.Action

Anyone know how to fix/get around this? The linked question says I need to mock out the PopulateBody method which I have done (as per wiki).

  • 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-02T10:27:07+00:00Added an answer on June 2, 2026 at 10:27 am

    a workaround is to change your code to this:

    PopulateBody(mailMessage, "Welcome", null);

    This will work because you have a mock setup for that overload of PopulateBody and not for the 2 parameter version of it..

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

Sidebar

Related Questions

I have an application in linux, which is compiled successfully. I want to run
I run a mysql query and get the results successfully. However, I cannot read
I am trying to run IRSSI on my Bluehost account. I have successfully installed
Symptom: Some users cannot successfully POST, most can successfully POST. When the error occurs,
Cannot find any example on Google.
I have downloaded the source for VIM (7.3) and compiled it successfully with a
I am successfully using RJS to implement AJAX on a page.replace.html create.js.rjs. I am
I have referenced this previous question as well as other sources, but cannot get
I am attempting to run VLCJ test jar from command line. VLCJ requires two
I have successfully set up Jenkins to pull from my private github repo and

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.