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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:14:05+00:00 2026-05-23T03:14:05+00:00

So assume I am mocking the following class: public class ClassAParams { public int

  • 0

So assume I am mocking the following class:

public class ClassAParams
{
    public int RequestedId { get; set; }
    public string SomeValue { get; set; }
}

public class ClassA
{
    public void ExecuteAction(ClassAParams executeParams) {}
}

Now say I have another class (let’s call it ClassB) that I am creating a unit testing for, and I want to make sure that when ClassB.Execute() is called, that ClassB calls ClassA.ExecuteAction() but I want to make sure that the parameter it calls that method with has a ClassAParams.RequestedId value of 1.

Normally, I would handle this by doing myMock.Verify(x => x.ExecuteAction(new ClassAParams { RequestedId = 1, SomeValue = "something" }));

The problem is, I do not want to check the value of the SomeValue parameter, or any other ClassAParams properties in this unit test. The other properties will be checked in other unit tests, but having to verify that it’s called with the correct properties in every unit test (even when I don’t care in the scope of a specific unit tests) will make unit maintenance annoying.

Is there any way to use Moq to verify that the structure that gets passed into a mocked method only has certain properties as a specific value, and ignore the rest?

  • 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-23T03:14:06+00:00Added an answer on May 23, 2026 at 3:14 am

    An overload exists for mock.Verify which allows you to test something. Here is an example that should work for your test.

    classA.Verify(
        a => a.ExecuteAction(
            It.Is<ClassAParams>(p => p.RequestedId == 12)
        )
    );
    

    Which means “For any ClassAParams passed as argument, verify RequestId equals 12″.

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

Sidebar

Related Questions

Assume i have a class: public class Products { public string ID { get;
Assume the following method: public synchronized void a(){ try{ System.out.println(a); return; }finally{ System.out.println(a, finally);
Assume I have a C# class like this: [XmlRoot(floors)] public class FloorCollection { [XmlElement(floor)]
Assume I have the following string: Hellotoevryone<img height=115 width=150 alt= src=/Content/Edt/image/b4976875-8dfb-444c-8b32-cc b47b2d81e0.jpg />Iamsogladtoseeall. This
Assume this model class : public class Car extends Vehicle implements Visitable { .....
Assume the following layout: <span class=container> <video class=video> <source ... /> </video> <div class=controls>
Assume I have the following: <input type=text> <div id=listofstuff> <div class=anitem> <span class=item name>Dog</span>
Assume I have a class like this: public class Foo { public Bar RequiredProperty
Assume I have the following string constants: const string constString1 = Const String 1;
Assume that I have two entities as follows: class Blog { public Blog() {

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.