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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:05:58+00:00 2026-06-14T19:05:58+00:00

I am trying to verify a parameter that is a class. The code being

  • 0

I am trying to verify a parameter that is a class. The code being tested is fine. The bug is in the test.

I have tried two methods, both of which have failed.

Here are my attempts:

1:

this.MockImageResizeFilter.Verify(m => m.Filter(this.UploadedFileData, new ImageFilterOptions()
    {
        Width = 256,
        Height = 256,
    }));

This always fails, even though an object passed as the second parameter has equal properties. The first parameter is verified fine.

2:

this.MockImageResizeFilter.Setup(m => m.Filter(It.IsAny<byte[]>(), It.IsAny<ImageFilterOptions>()))
    .Callback<byte[], ImageFilterOptions>((data, options) =>
        {
            Assert.AreEqual(this.UploadedFileData, data, "data");
            Assert.AreEqual(filterOptions.Width, options.Width, "Width");
            Assert.AreEqual(filterOptions.Height, options.Height, "Height");
        }
    );

This always passes, even when it should fail. The Asserts in the callback do fail, but the exception is not passed to the outer context, and thus the test always passes.

Can you help me find what I am doing wrong?

  • 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-14T19:05:58+00:00Added an answer on June 14, 2026 at 7:05 pm

    The first attempt is closer to what you want to achieve.

    The reason it fails is that Moq (probably) uses Object.Equals under the cover to test if the ImageFilterOptions parameter that the method was called with is the same instance as the one you supplied in the call to Verify.

    It is impossible for them to be the same instance, because in Verify you create a new ImageFilterOptions().

    Instead of performing the parameter check this way, you could use Moq’s It.Is syntax to provide an expression that verifies the parameter was the expected one.

    In your case, you want to check that the parameter is of type ImageFilterOptions and that both the Width and the Height are set to 256. The expression that allows you to do that is:

    It.Is<ImageFilterOptions>(p => p.Width == 256 && p.Height == 256)
    

    So, your call to Verify could look like this:

    this.MockImageResizeFilter.Verify(m => m.Filter(
                this.UploadedFileData,
                It.Is<ImageFilterOptions>(p => p.Width == 256 && p.Height == 256)));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that inherits from an abstract base class. I am trying
While trying to verify to myself, that C# Equals for IEnumerables is a reference
I'm trying to create a UnitTest to verify that an object has been deleted.
I'm trying to get it to verify that it has the same item in
I'm trying to use mock to verify that an index property has been set.
I'm currently trying to make a class that can register strings as identifiers and
I have one piece of Cocoa code I wrote that takes in an XML
I have a bug I've been trying to track down for a few weeks
I have an array of a large structure that I am trying to output
I'm trying to verify a file that was signed by hashing with SHA-1 and

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.