Why am I getting an Exception with the message “Invalid setup on a non-virtual (overridable in VB) member…”?

Moq cannot mock non-virtual methods and sealed classes. While running a test using mock object, MOQ actually creates an in-memory proxy type which inherits from your “XmlCupboardAccess” and overrides the behaviors that you have set up in the “SetUp” method. And as you know in C#, you can override something only if it is marked … Read more

Verify a method call using Moq

You’re checking the wrong method. Moq requires that you Setup (and then optionally Verify) the method in the dependency class. You should be doing something more like this: In other words, you are verifying that calling MyClass#MyMethod, your class will definitely call SomeClass#DoSomething once in that process. Note that you don’t need the Times argument; I was just demonstrating its … Read more