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

Added covariant IMock<out T> interface to Mock<T> #44

Merged
merged 2 commits into from
May 27, 2013
Merged

Conversation

tkellogg
Copy link
Collaborator

I wanted to be able to write test utilities for setting up more complicated
object interactions. I wanted to make a method with this signature:

void Method<T>(Mock<IService<T>> serviceMock);

that could recieve an object of type Mock<IFooService> as a parameter (where
IFooService extends IService<Foo>). Since only interfaces and delegates
can be covariant, the raw Mock<T> won't work. This pull request lets me use
this method:

void Method<T>(IMock<IService<T>> serviceMock);

The IMock<T> interface exposes only the members where we can still make
IMock<T> covariant (i.e. nothing that has T in the parameter list).

tkellogg added 2 commits April 10, 2013 11:13
Moq.csproj had them conditionally resoved but that part was commented out
from Moq.Tests.csproj. As a result, you could compile but not run tests
in .NET 4.0. Since 4.0 is critical for the feature I'm implementing, I had
to fix this.
I wanted to be able to write test utilities for setting up more complicated
object interactions. I wanted to make a method with this signature:

    void Method<T>(Mock<IService<T>> serviceMock);

that could recieve an object of type `Mock<IFooService>` as a parameter (where
`IFooService` extends `IService<Foo>`). Since only interfaces and delegates
can be covariant, the raw `Mock<T>` won't work. This pull request lets me use
this method:

    void Method<T>(IMock<IService<T>> serviceMock);

The `IMock<T>` interface exposes only the members where we can still make
`IMock<T>` covariant (i.e. nothing that has `T` in the parameter list).
kzu added a commit that referenced this pull request May 27, 2013
Added covariant IMock<out T> interface to Mock<T>
@kzu kzu merged commit bbdf5d7 into devlooped:dev May 27, 2013
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

Successfully merging this pull request may close these issues.

None yet

2 participants