Moq verify with object parameter

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)));

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)