Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need a better way to manage parent class child class relationships #1176

Closed
eccforgit opened this issue Jun 24, 2021 · 2 comments
Closed

Need a better way to manage parent class child class relationships #1176

eccforgit opened this issue Jun 24, 2021 · 2 comments

Comments

@eccforgit
Copy link

eccforgit commented Jun 24, 2021

It would be nice to have a feature such that

Mock<ParentClass> can be substituted for Mock<DerivedClass> Similar to the the way that ParentClass itself could be substituted for DerivedClass. That way you can carry the mock with you in the abstract version (say in a list of Mock<ParentClass> es that contains multiple Mock<DerivedClass> types.

Another option here would be to create a "Get"Mock(Object) where you pass in the mock object and get back the mock instance. Actually both of these would be great features, and would allow users to better test there interface hierarchy.

@stakx
Copy link
Contributor

stakx commented Jun 24, 2021

I'm having trouble understanding your request. Could you please elaborate?

@stakx
Copy link
Contributor

stakx commented Jun 30, 2021

Ah, I saw that your post was malformatted and some important bits weren't rendered. Fixed the formatting, now I think I understand what you're asking for.

IIRC the IMock<> interface was added with the intent to support co-/contravariance (never sure which one). It doesn't seem like that ever went anywhere TBH, compared to Mock<>, IMock<> looks far too incomplete to actually be useful.

I'm not sure why you'd need a List<Mock<>> in the first place. Can you give an example where such a list would actuslly be useful?

Another option here would be to create a "Get"Mock(Object) where you pass in the mock object and get back the mock instance.

This method already exists, it's called Mock.Get<>(obj).

So in closing I think it's easier and more realistic to have a List<ParentClass> and put parentClassMock.Objects and derivedClassMock.Objects in there, and if you need to get back the mock, use Mock.Get on those list items.

@stakx stakx closed this as completed Jun 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants