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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:33:06+00:00 2026-05-27T02:33:06+00:00

I want to check if the users password has been changed, what is the

  • 0

I want to check if the users password has been changed, what is the best way to write this test? Is my code in need of refactoring because it is wrong?

Inside the code password.ResetUserPassword – I find out which user is requesting a password change, if they can change, and generating an email if needs to be… Do I need to pass in a User objects to this method? This logic is called by my controller (or backend if needs to be)

    [Test]
    public void Test_If_New_Password_Is_Generated_For_User()
    {
        var repo = new ReadOnlySession();
        var update = new UpdateSession();

        var passwordService = new UserPasswordService();
        var password = new AccountProfileProcessor(repo, update, passwordService);

        password.ResetUserPassword("companyid", "jon.smithers", null);

        Assert.Pass();

    }

//The method that I am calling

_passwordService is a service that handles generating a new key for the user

    public void ResetUserPassword(string identifier, string loginid, string passwordreseturl)
    {
        //get user object
        var currentUser = _readOnlySession.All<User>()
            .Where(x => x.Login == loginid)
            .SingleOrDefault(); //any other logic to get user resides here...

        if (currentUser == null)
            throw new UserNotFoundException();

        _passwordService.ResetPassword(currentUser.User, identifier, loginid);

        //persist data
        _updateSession.Update(currentUser.User);

        //send out email with the url as a link inside the email
    }
  • 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-27T02:33:07+00:00Added an answer on May 27, 2026 at 2:33 am

    Something like the following would work. (I had to make a few assumptions about your classes, and I’m still not sure what type currentUser.User is.)

    The trick with mocking and decoupling is to make all of your service dependencies interfaces.

    You’ll need another interface dependency (with associated mock and verification) for the mail sending. You might want to put all of these in a separate test fixture, arrange in setup, then verify each service call in a separate test method.

    To me this method is doing too much – it has multiple responsibilities. The painful test setup and multiple verifications are code smells. Consider breaking it into smaller methods (probably still called from the existing method) and then testing those independently. GetUser(loginId) (or throw) would be the first method I’d extract. Moving some of these methods onto the services (such as the repository) would make this easier to test.

    Clarification – You mention in the comments that you want to check if the PasswordKey is different. That’s the responsibility of the concrete UserPasswordService. You’ll need to test that independently.

    // Arrange
    
    const string TestLogin = "jon.smithers";
    User testUser = new User { Login = TestLogin };
    var testUsers = new List<User> { testUser };
    
    var mockUpdate = new Mock<IUpdateSession>();
    
    var mockRepo = new Mock<IReadOnlySession>();
    mockRepo.Setup(x => x.All<User>()).Returns(testUsers);
    
    var mockPasswordService = new Mock<IUserPasswordService>();
    
    var password = new AccountProfileProcessor(
        mockRepo.Object, mockUpdate.Object, mockPasswordService.Object);
    
    // Act
    
    password.ResetUserPassword("companyid", TestLogin, null);
    
    // Assert
    
    mockPasswordService.Verify(
        x => x.ResetPassword(
            It.IsAny<string>(), It.IsAny<string>(), TestLogin));
    
    mockUpdate.Verify(x => x.Update(testUser));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this script that collects data from users and I want to check
I want to put the user password check to never expire. When I create
I want to check password strength of password entered by user in Asp.Net page.
I want to check the strength of the password entered by user during registration.
I want to check users' subscribed dates for certain period. And send mail to
i want to check users' input value when he input his name, if his
I want to check if my users are fans of my facebook page. I
I know this has been asked before but I can't find it so... Say
Possible Duplicate: PUT vs POST in REST I know this has been discussed a
I want to write a Person class that has their details, including a username

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.