Reputation: 41
I've been using the ReturnsAsync
function from Moq with success for a bit, but have bumped into an issue with the following. I always just return null while I'm adding the parameters to my lambda expression...this time when I got them all added, I get the dreaded "Cannot convert lambda expression to type..." Is there anything obvious that I got wrong? The Setup
method resolves perfectly fine...just not ReturnsAsync
Is there a limit to how many parameters that can be defined? I've tried and noticed that it craps out after the 15th parameter...
var buildServiceMock = new Mock<IBuildService>();
buildServiceMock
.Setup(bsm => bsm.QueryBuildsAsync(
It.IsAny<BuildType>(),
It.IsAny<string>(),
It.IsAny<DateTime?>(),
It.IsAny<DateTime?>(),
It.IsAny<string>(),
It.IsAny<BuildReason?>(),
It.IsAny<BuildStatus?>(),
It.IsAny<BuildResult?>(),
It.IsAny<IEnumerable<string>>(),
It.IsAny<IEnumerable<string>>(),
It.IsAny<int?>(),
It.IsAny<int?>(),
It.IsAny<QueryDeletedOption?>(),
It.IsAny<BuildQueryOrder?>(),
It.IsAny<string>(),
It.IsAny<IEnumerable<int>>(),
It.IsAny<string>(),
It.IsAny<CancellationToken>()))
.ReturnsAsync((
BuildType buildType,
string buildNumber,
DateTime? minDateTime,
DateTime? maxDateTime,
string requestedFor,
BuildReason? reasonFilter,
BuildStatus? statusFilter,
BuildResult? resultFilter,
IEnumerable<string> tags,
IEnumerable<string> properties,
int? top,
int? maxBuildsPerDefinition,
QueryDeletedOption? deletedFilter,
BuildQueryOrder? queryOrder,
string branchName,
IEnumerable<int> buildIds,
string label,
CancellationToken cancellationToken) =>
{
return null;
});
Upvotes: 2
Views: 1090
Reputation: 41
What I've discovered is the root of my problem is this...
public static IReturnsResult<TMock> ReturnsAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TMock, TResult>(this IReturns<TMock, ValueTask<TResult>> mock, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TResult> valueFunction) where TMock : class;
ReturnsAsync at max will only allow for you to use up to 15 parameters in your lambda expression's signature.
However I only needed the one IEnumerable within my ReturnsAsync delegate method, so I'm good...I was mistaken in that I thought I had to specify a parameter for everyone parameter in the method being mocked up in the "Setup" call...now that I've found you do not need to do that, I'm good to go. :)
Upvotes: 2