Skip to content
This repository has been archived by the owner on Jun 30, 2023. It is now read-only.

Add support for protected members #51

Open
kzu opened this issue Oct 29, 2020 · 3 comments
Open

Add support for protected members #51

kzu opened this issue Oct 29, 2020 · 3 comments

Comments

@kzu
Copy link
Member

kzu commented Oct 29, 2020

In v4:

mock.Protected().Setup("SendAsync", ...)

We should offer more compile-time safety in v5 for protected members, possibly with completion providers + analyzers

@stakx
Copy link
Member

stakx commented Oct 29, 2020

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

@kzu
Copy link
Member Author

kzu commented Jan 10, 2023

Heya @stakx, I'm resuming work on v5 :). Perhaps it should leverage source generators to automatically create that T for you? 🤔

@stakx
Copy link
Member

stakx commented Jan 10, 2023

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants