Add support for protected members
Opened this issue · 3 comments
In v4:
mock.Protected().Setup("SendAsync", ...)
We should offer more compile-time safety in v5 for protected members, possibly with completion providers + analyzers
Just for completeness' sake, @kzu have you seen .Protected().As<T>()
that we added in v4 a while ago? Quick demo in this post.
Defining a parallel interface just for tests of course isn't very nice if you have to manually do it & keep in sync with the protected members, but I imagine you could easily automate that using code fixes (like you have done for typed delegates needed for by-ref parameters).
Heya @stakx, I'm resuming work on v5 :). Perhaps it should leverage source generators to automatically create that T for you? 🤔
Oh, that would be neat. The big issue with Moq 4's .Protected().As<TProtectedMembers>()
is just that, one needs to write an extra type just for testing. Would be great if that could be automated away.