-
-
Notifications
You must be signed in to change notification settings - Fork 794
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
Mock.Of async expression #139
Comments
No idea if I read you question right but:
|
Right, but with synchronous methods you can wrap everything up in [Test]
public void Test()
{
var mock= Mock.Of<INotifyPropertyChanged>(x => x.Get() == propertyChanged);
var actual = mock.Get();
Assert.AreSame(propertyChanged, actual);
}
public interface IFuu
{
INotifyPropertyChanged Get();
}
|
This worked for me:
I suppose if you replace |
I haven't thought much about this, but my gut feeling is that Mock.Of<IFoo>(async foo => await foo.GetAsync() == 42) Unfortunately, today's C# compiler cannot convert What we're left with is the ability to work directly with Mock.Of<IFoo>(foo => foo.GetAsync() == Task.FromResult(42)) The gains here are pretty small. IMHO it is probably better to accept the fact that LINQ to Mocks will likely never be as feature-complete / powerful as the older fluent API ( |
Closing this for now, since there's nothing really that can be done. There's simply no way with today's .NET compilers to transform an async lambda to an expression tree. |
Maybe I'm doing it wrong but there doesn't seem to be a way to use the "Linq to Mocks" syntax for mocking async methods. Is it possible? If not, what would it take to make it possible?
The text was updated successfully, but these errors were encountered: