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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:42:06+00:00 2026-05-25T17:42:06+00:00

I am trying to learn Moq but it is proving somewhat difficult. If I

  • 0

I am trying to learn Moq but it is proving somewhat difficult.

If I want to implement some basic tests using nUnit and Moq for the account controller in a new MVC3 project, how would I go about it?

Im used to the entity framework. but not building interfaces for it.

edit:
I understand the theory of it all and the need to do it, but implementing it is confusing me

I have been using Entity Code generator (dbContext) to generate code I can use for interfaces

  • 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-25T17:42:06+00:00Added an answer on May 25, 2026 at 5:42 pm

    Ok, here is a good test: When you register a new user, you want to make sure that he will be automatically signed in the site, so he doest not need to type his username and password again.

    The test would be something like this:

    public void AutomaticallySignedInAfterRegistering()
    {
        var membershipService = new Mock<IMembershipService>();
        var formsService = new Mock<IFormsAuthenticationService>();
        RegisterModel newUser = new RegisterModel();
        newUser.UserName = "John"
        newUser.Email = "john@somewhere.com"
        newUser.Password = "p@ss";
        newUser.ConfirmPassword = "p@ss";
    
        membershipService.Setup(x => x.CreateUser("John", "p@ss", "john@somewhere.com")).Returns(MembershipCreateStatus.Success);
    
        AccountController controller = new AccountController();
        controller.FormsService = formsService.Object;
        controller.MembershipService = membershipService.Object;
    
        controller.Register(newUser);
    
        formsService.Verify(x => x.SignIn("John", false), Times.Once());
    } 
    

    The key here is the Verify method. It works just like an Assert. In this case you are verifing that the method SignIn was called exactly once. This is an example of how to use mocks to check if the Account Controller is working as expected.

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

Sidebar

Related Questions

I am trying to learn TDD/BDD using NUnit and Moq. The design that I
I am trying to learn and implement TDD specifically using Moq and I have
While trying to learn c++, I tried to implement class representing very basic trie.
I am trying to learn some of the basic and advanced features of visual
Trying to learn some jquery to implement an autosave feature and need some assistance.
I am somewhat new to jQuery but have been having fun trying learn about
Im trying to learn javascript and, having some basic programming experience already (from C++),
Im trying to learn OOP but I need to see some real case scenarios
Trying to learn a bit of CSS and I want a horizontal navbar and
I was trying learn lex and yacc using the oreilly book. I tried following

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.