You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Existing mock creation overloads for constructors that take parameters has some limitations:
Compiler can't check whether the constructor actually exists. Issues/regressions are detected during runtime rather than leveraging code editor capacity
Editor features such as Finding references... to a constructor is missing calls to the constructor made by these mocks
When refactoring code, we end up missing those references... and introduce errors (back to first bullet point)
I think it would be relatively simple to add new overloads to Mock and MockRepository that take an Expression<Func<T>> as a parameter. Something like:
var mock1 = new Mock<SomeType>(() => new SomeType("foo"));
var mock2 = repository.Create(() => new SomeType("foo"));
If you think it's a good idea I could submit a PR. What do you think?
The text was updated successfully, but these errors were encountered:
Hi @frblondin, that idea would be in line with one of Moq's declared goals (promoting correct code through static typing), so I don't have any objection to adding the new overloads that you're suggesting. Feel free to submit a PR.
add new overloads to Mock and MockRepository that take an Expression<Func<T>> as a parameter
The overload should go in Mock<T>, not in Mock (as I'm sure you realise).
There has to be a possibility to optionally specify a MockBehavior; either via an optional parameter, or an additional overload. Ideally, the parameter order will be based on that of existing constructors / methods.
(@frblondin, I have assigned this issue to you and a future version milestone, just to help me track this issue more easily. But don't let that put any pressure on you.)
Existing mock creation overloads for constructors that take parameters has some limitations:
I think it would be relatively simple to add new overloads to
Mock
andMockRepository
that take anExpression<Func<T>>
as a parameter. Something like:If you think it's a good idea I could submit a PR. What do you think?
The text was updated successfully, but these errors were encountered: