This unit test "passes" when run without generating exceptions:
[ContractClassFor(typeof(IX))]
class IXContract
{
[ContractInvariantMethod]
void Invariant() { }
}
[ContractClass(typeof(IXContract))]
public interface IX { event EventHandler b; }
/// <summary>
/// Summary description for UnitTest1
/// </summary>
[TestClass]
public class UnitTest1
{
public void MyTest()
{
var a = new Mock<IX>();
a.Raise(x => x.b += null);
}
}
I'm not entirely sure what's going on and how you're compiling (or transcribing) the above, but I don't think you can have "ContractClassFor" attribute decorating an interface, and you certainly can't have the implementation "{ ... }" in an interface. You also need to make your interface IX public to mock it (or else internal with InternalsVisibleTo() castle proxy in your properties).
Hopefully this helps, but feel free to update your post with new code if this doesn't lead you toward what you're looking to do.