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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:34:01+00:00 2026-05-17T20:34:01+00:00

I have set a test using Moq 3.0. I need to test a method

  • 0

I have set a test using Moq 3.0. I need to test a method that will change some value in that database. I am using ASP.NET MVC so I want to test my controller.

I setup this

 // Generate an implementer of IProductsRepository at runtime using Moq
 var mockTareasRepos = new Mock<IRepository>();
 mockTareasRepos.Setup(x => x.ExecutedTask).Returns(tasks.AsQueryable());
 return mockTareasRepos.Object;

I need to add a new method that get a taskId and change the value of a field in a list of tasks. Suppose that the value I need to change is StartTime that is a datetime, I need to set the value to null and I need to set that retrys value plus one.

this is the task Class

public class {
     int taskId {get;set;}
     DateTime StartTime  {get;set;}
     int retrys {get;set;}
}

How I do that?

 mockTareasRepos.Setup(x => x.SetToExecuteTask(It.IsAny<int>()))

I hope you understand what I need, My English is not so good.

  • 1 1 Answer
  • 1 View
  • 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-17T20:34:01+00:00Added an answer on May 17, 2026 at 8:34 pm

    If I understood it correcly, you want to test that after calling your Controller’s method, your database value should be updated. Your mocking your repository because you don’t want to setup a test database, right? So, your test should be something like this:

    mockTareasRepos.Setup(...) //Do the setup you need.
    var controller = new YourController(mockTareasRepos);
    controller.YourMethod();
    mockTareasRepos.Verify(x => x.YourRepositoryUpdateMethod(It.IsAny<Task>, Times.Once())); 
    

    The last line will verify if your controller called the ‘YourRepositoryUpdateMethod’ method once. By doing this, your testing that your controller method calls the Repository interface to update your database.

    I hope it helps. If this is not what your looking for, please, give us more information.

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

Sidebar

Related Questions

I'm using MoQ to test some controllers I have. I'm not able to set
I'm using Google Test Framework to set some unit tests. I have got three
I have a set of Happstack.State MACID methods that I want to test using
We have an ASP.NET website set up using Active Directory as the Membership Provider.
I have a private method that should return true.I m using Nunit and MOQ
I have a VS2010 unit test project set to using SpecFlow 1.8.1 and mstest.
I have a set of test accounts that are going to be created but
HI, I want to have set configuration settings for a unit test project that
I have a LDIF file that consists of a set of test users and
I have a PowerShell module called Test.psm1. I want to set a value on

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.