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
I will preface this by saying I think I may be doing something wrong.
If I have multple task objects returned from mocked async methods stored in the result of a linq query and I use the ".." spread operator, each item in the result gets set to null.
If I have multple task objects returned from "real" async methods stored in the result of a linq query and I use the ".." spread operator, each item is a valid task and is not null.
I assume it has something to do with the linq query and a delay in resolving the enumerable? But then why would it only behave this way when the method is mocked?
Steps to Reproduce
Here's an example unit test. Only the last assert "mockedMethodTasksSpread" fails.
Actually it's do to the behavior of the SetupSequence method, which I think is not a bug and working as expected.
Both [..enumerable] and .ToArray() immediately enumerate the sequence (triggering the evaluation of deferred queries).
This means when you're using the realMethodTasks, every time you enumerate it, whether explicitly (using .ToArray()) or implicitly [..enumerable], the enumerator enumerates over the IEnumerable<Task<string?>>.
The method MyRealMethodAsync(id!) is stateless and simply creates a new task each time it’s called.
For mockedMethodTasks, the mock is stateful, because SetupSequence maintains an internal sequence of return values.
When the mock is invoked for the first time, it returns "41", then "42", then "43", according to the LINQ query.
On the second enumeration:
Describe the Bug
I will preface this by saying I think I may be doing something wrong.
If I have multple task objects returned from mocked async methods stored in the result of a linq query and I use the ".." spread operator, each item in the result gets set to null.
If I have multple task objects returned from "real" async methods stored in the result of a linq query and I use the ".." spread operator, each item is a valid task and is not null.
I assume it has something to do with the linq query and a delay in resolving the enumerable? But then why would it only behave this way when the method is mocked?
Steps to Reproduce
Here's an example unit test. Only the last assert "mockedMethodTasksSpread" fails.
Expected Behavior
The assert mockedMethodTasksSpread should pass.
Exception with Stack Trace
Version Info
Here's most of my csproj with nuget versions:
Additional Info
None
The text was updated successfully, but these errors were encountered: