コード例 #1
0
        public async Task GetHomeworks_MemberIdIsValid_ShouldReturnHomeworks()
        {
            // arrange
            var memberId = _fixture.Create <int>();

            var githubAccount = _fixture.Build <GitHubAccount>()
                                .Without(x => x.Member)
                                .With(x => x.MemberId, memberId)
                                .Create();

            var approvedPullRequests = _fixture.Build <PullRequest>()
                                       .With(x => x.GithubAccountId, githubAccount.GithubAccountId)
                                       .With(x => x.IsApproved, true)
                                       .CreateMany()
                                       .ToArray();

            var pullRequests = _fixture.Build <PullRequest>()
                               .With(x => x.GithubAccountId, githubAccount.GithubAccountId)
                               .With(x => x.IsApproved, false)
                               .CreateMany()
                               .Union(approvedPullRequests)
                               .ToArray();

            _membersRepositoryMock
            .Setup(x => x.GetGitHubAccount(memberId))
            .ReturnsAsync(githubAccount);

            _githubApiClientMock
            .Setup(x => x.GetPullRequests(githubAccount.GithubAccountId))
            .ReturnsAsync(pullRequests);

            // act
            var homeworks = await _service.GetHomeworks(memberId);

            // assert
            homeworks.Should().NotBeEmpty()
            .And.HaveCount(pullRequests.Length)
            .And.Match <MemberHomework[]>(x => x.Count(p => p.IsApproved) == approvedPullRequests.Length);

            _membersRepositoryMock.Verify(x => x.GetGitHubAccount(memberId), Times.Once);
            _githubApiClientMock.Verify(x => x.GetPullRequests(githubAccount.GithubAccountId), Times.Once);
        }