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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:55:08+00:00 2026-06-07T21:55:08+00:00

Here is a method that returns a view model with user information: public ActionResult

  • 0

Here is a method that returns a view model with user information:

    public ActionResult EditUserInfo(string userName)
    {
        try
        {
            var user = Membership.GetUser(userName);
            var model = new UserEditorViewModel
                            {
                                UserName = userName,
                                EmailAddress = user.Email
                            };
            return View(model);
        }
        catch
        {
            return View("Error");
        }
    }

How can I unit test it using Moles framework? There is a method MMembership.CreateUserStringString() but I couldn’t figure out how to implement it to fake user identity.

  • 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-07T21:55:10+00:00Added an answer on June 7, 2026 at 9:55 pm

    Ok, so I’ve found a solution. I had to add moles assembly for System.Web.ApplicationServices to be able to mock MembershipUser. The final test method loks like this:

        [TestMethod, HostType("Moles")]
        public void EditUserInfoTest()
        {  
            var testUserName = "TestUser";
            var controller = new UserEditorController();
            using (MolesContext.Create())
            {
                var user = new MMembershipUser
                {
                    UserNameGet = () => "TestUser",
                    EmailGet = () => "test@test.test"
                };        
                MMembership.GetUserString = (userName) =>
                {
                    Assert.AreEqual(testUserName, userName);
                    return user;
                };
                var result = (ViewResult)controller.Edit(testUserName);                
                Assert.AreNotEqual("Error", result.ViewName);
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

here's the method: public static int chooseStrat () { String[] strats = new String[1]
Here is the question: write a method that swaps two variables. These two variables
Just a quick newbie question here. I have a method that calculates a value
The method in question that I want to use is gem and sourced here
I call addNotify() method in class that I posted here. The problem is, that
Here's the behavior I'm looking for: User selects a record from an index view,
I'm trying to create a method that return either true or false. Here is
Here's my model, what it does is pulls a particular post from a user.
I've got a few controllers here at work that contain methods I can use
Sort of a methods/best practices question here that I am sure has been addressed,

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.