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

Can not mock the method with several overloads. #839

Closed
TsuyoshiUshio opened this issue Jun 2, 2019 · 1 comment
Closed

Can not mock the method with several overloads. #839

TsuyoshiUshio opened this issue Jun 2, 2019 · 1 comment

Comments

@TsuyoshiUshio
Copy link

Hello,

I'm encounter the issue that I can't mock a method.

It has a abstract class with these methods.

public virtual Task<List<GitPullRequestCommentThread>> GetThreadsAsync(Guid project, string repositoryId, int pullRequestId, int? iteration = null, int? baseIteration = null, object userState = null, CancellationToken cancellationToken = default);
public virtual Task<List<GitPullRequestCommentThread>> GetThreadsAsync(Guid project, Guid repositoryId, int pullRequestId, int? iteration = null, int? baseIteration = null, object userState = null, CancellationToken cancellationToken = default);
public virtual Task<List<GitPullRequestCommentThread>> GetThreadsAsync(string repositoryId, int pullRequestId, int? iteration = null, int? baseIteration = null, object userState = null, CancellationToken cancellationToken = default);
public virtual Task<List<GitPullRequestCommentThread>> GetThreadsAsync(string project, string repositoryId, int pullRequestId, int? iteration = null, int? baseIteration = null, object userState = null, CancellationToken cancellationToken = default);
public virtual Task<List<GitPullRequestCommentThread>> GetThreadsAsync(Guid repositoryId, int pullRequestId, int? iteration = null, int? baseIteration = null, object userState = null, CancellationToken cancellationToken = default);
public virtual Task<List<GitPullRequestCommentThread>> GetThreadsAsync(string project, Guid repositoryId, int pullRequestId, int? iteration = null, int? baseIteration = null, object userState = null, CancellationToken cancellationToken = default);

I want to mock third one. So I create a mock setup like this.

var clientMock = new Mock<GitHttpClientBase>().Setup(p =>
            p.GetThreadsAsync(RepositoryId, 53, It.IsAny<int?>, It.IsAny<int?>, It.IsAny<object>, It.IsAny<CancellationToken>())).ReturnsAsync(new List<GitPullRequestCommentThread>());

It cases these errors. It looks the compiler misunderstand the target orverload. Am I wrong? Any workaround here?

Severity	Code	Description	Project	File	Line	Suppression State
Error	CS1503	Argument 2: cannot convert from 'int' to 'string'	APISpike	C:\Users\tsushi\source\repos\PullRequestBot\APISpike\Program.cs	62	Active
Severity	Code	Description	Project	File	Line	Suppression State
Error	CS1503	Argument 3: cannot convert from 'method group' to 'int'	APISpike	C:\Users\tsushi\source\repos\PullRequestBot\APISpike\Program.cs	62	Active
Severity	Code	Description	Project	File	Line	Suppression State
Error	CS1503	Argument 4: cannot convert from 'method group' to 'int?'	APISpike	C:\Users\tsushi\source\repos\PullRequestBot\APISpike\Program.cs	62	Active
Severity	Code	Description	Project	File	Line	Suppression State
Error	CS1503	Argument 5: cannot convert from 'method group' to 'int?'	APISpike	C:\Users\tsushi\source\repos\PullRequestBot\APISpike\Program.cs	62	Active
@TsuyoshiUshio
Copy link
Author

Sorry, It was my mistook. I forget It.IsAny<int?>() I mean ().

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

No branches or pull requests

1 participant