1
Database.Setup(x => x.Update(It.IsAny<Subscription>()))
                    .Callback<object>(sub => SavedSubscription = sub as Subscription);

This line works with PetaPoco. Because of project requirements, had to switch to Dapper (and also had to add DapperExtensions in order to have CRUD methods) so now I am getting this error:

An expression tree may not contain a call or invocation that uses optional arguments

Any ideas how to handle this?

Patrick Quirk
  • 23,334
  • 2
  • 57
  • 88
ilija veselica
  • 9,414
  • 39
  • 93
  • 147

1 Answers1

1

You can't use Moq to mock methods that have optional parameters (as Update does). See this question for more details, though you're stuck specifying all parameters to the Update method.

Note that this is a limitation inherent to the framework and not Moq; you can't pass a method with a default parameter to an Expression. Jon Skeet gives a good demonstration why here.

Community
  • 1
  • 1
Patrick Quirk
  • 23,334
  • 2
  • 57
  • 88