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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:08:32+00:00 2026-06-08T21:08:32+00:00

I am developing Moq tests for various entities. I can setup create and delete

  • 0

I am developing Moq tests for various entities. I can setup create and delete tests fine, but not update – the entity in the repository does not change. I know this is due to the PersistAll doing nothing (probably due to a setup I am missing).

This is a sample of an insert persist setup (I am looking for an Update version):

agg.Setup(a => a.InsertOnPersist<Thingy>(model)).Callback(() => mockThingies.Add(model));

In addition, I also have this to link the List to being the repository:

agg.Setup(a => a.GetObjectStore<Artist>()).Returns(mockThingies.AsQueryable());

This is a sample of an update test I have:

 public List<Thingy> mockThingies; //this is our repository
 [TestInitialize]
 public void SetupTests()
 {
    mockThingies= new List<Thingy>();
    Thingy someThingy = new Thingy();
    someThingy.Name = "MyName";
    someThingy.ID = 1;
    mockThingies.Add(someThingy);
  }

    [TestMethod]
    public void CanEditExistingThingy()
    {
        Mock<BusinessExceptionBroadcaster> beb = new Mock<BusinessExceptionBroadcaster>();
        Mock<IValidationEngine> valid = new Mock<IValidationEngine>();
        Mock<IAggregate> agg = new Mock<IAggregate>();
        agg.Setup(a => a.GetObjectStore<Thingy>()).Returns(mockThingies.AsQueryable());
        ThingyRepository repo = new ThingyRepository (agg.Object);
        ThingyService service = new ThingyService (repo, beb.Object, valid.Object);
        Thingy newThingy = new Thingy();
        newThingy.ID = 1; //same as old
        newThingy.Name = "newname"; //new name
        Assert.AreNotEqual(newThingy.Name,mockThingies[0].Name); 
        Assert.IsTrue(service.Update(newThingy));
        Assert.AreEqual(newThingy.Name, mockThingies[0].Name); //FAILS HERE
    }

This is the code to update:

    public bool Update(Thingy entity)
    {  
            Thingy existingThingy= _Thingy.FirstOrDefault(t=>t.ID == entity.ID);
            if (existingThingy != null)
            {
                _Thingy.PersistAll();
                return true;
            }
            else
            {
               //unimportant
            }
        }
        return false;
    }
  • 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-08T21:08:33+00:00Added an answer on June 8, 2026 at 9:08 pm

    Don’t worry about testing whether the update call actually updates something. You’ll just want to verify that your service calls the appropriate method on the repo to perform the update and persist. Testing the actual update is a little outside the scope of this one test.

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

Sidebar

Related Questions

Developing a project in Django with my IDE setup as Eclipse with PyDev. The
Developing search utility to search a file entire computer system, works fine on windows
I am developing tests for an application. There's a method that has a params
Developing an interface generic I wished to declare a constructor in an interface but
Developing mobile apps is a challenging job. Customers want to be present not only
Developing a .NET WinForms application: how can I check if the window is in
Developing a brand new schema/app which uses hibernate to create tables from pojo's. My
Developing iOS5 based cocoa app, below peice of comparison works fine if localization is
When developing a desktop application in .NET, is it possible to not require the
Developing an app that people pay a monthly subscription to use. They can pay

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.