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

  • Home
  • SEARCH
  • 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 8230013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:59:30+00:00 2026-06-07T16:59:30+00:00

I have a save() method, not really sure how to test. below is my

  • 0

I have a save() method, not really sure how to test. below is my code.

public interface IRepository<T>
{
    T Get(int id);
    void Save(T item);
    void Delete(int id);
}

save method doesn’t return any values back, I cannot compare the value. however, I already have 4 users, after adding another one, I only check the total number of users, is it enough to test it?

[Test]
public void Add_a_new_smoothie_user_should_return_total_5_users()
{
    // Arrange

    var totalUsers = _users.Count();

    _mockUserRepository.Setup(s => s.Save(It.IsAny<User>()))
        .Callback((User user) => _users.Add(user));

    var newUser = new User
                      {
                          Id = 3,
                          Email = "newuser@test.com",
                          Password = "1234567".Hash(),
                          Firstname = "",
                          Lastname = "",

                          CreatedDate = DateTime.Now,
                          LastLogin = DateTime.Now,

                          AccountType = AccountType.Smoothie,
                          DisplayName = "",
                          Avatar = "",
                          ThirdPartyId = "",
                          Status = Status.Approved,
                          Ip = "127.0.0.1"
                      };

    // Act

    _mockUserRepository.Object.Save(newUser);

    // Assert

    Assert.AreEqual(5, _users.Count());
    Assert.AreEqual(1, _users.Count() - totalUsers);
}
  • 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-07T16:59:32+00:00Added an answer on June 7, 2026 at 4:59 pm

    You are mocking the part of the functionality you are trying to test. These tests will prove nothing, any other than Add() method of the data type you are holding the users. In the end it doesn’t give any ideas if your repository is working.

    You should try to implement a Database Sandbox for testing your repository functionality.

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

Sidebar

Related Questions

I have problem with ObjectContext.SaveChanges method: public void Save(Action<object, object> action) { EventAggregator.GetEvent<EntityServiceRequestingEvent>().Publish(true); var
I have a Save() method that saved rows using a Linq2Sql DataContext. private void
We have repositories which have a Save method. They also throw a Created event
I have the following method to save an Object to a file: // Save
I have the following method that is supposed to be a generic Save to
I have a small issue with a method that should save the text contained
I have re-factored one of the method as shown below ,personally I think it
I am experiencing this problem for few hours now and really not sure how
I have not really worked with datasets before. I use a lot of LINQ
Been working on some code streamlining and have realised that it would be really

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.