public async Task ShouldReturnEmptyReportForEachMemberIfNoPullRequests() { const int expectedTeamMembersCount = 6; var members = Builder <TeamMemberViewModel> .CreateListOfSize(expectedTeamMembersCount) .Build(); var profile = Builder <ProfileViewModel> .CreateNew() .With(p => p.Members = members.Select(m => m.Id).ToArray()) .With(p => p.Repositories = new Guid[0]) .Build(); SetupGetProfile(profile); SetupGetTeamMember(members); SetupGetPullRequests(Enumerable.Empty <PullRequestViewModel>()); await InvokeAndVerify <PullRequestsReport>(Command, (report, reportId) => { report.Should().NotBeNull(); report.Id.Should().Be(reportId); report.IndividualReports.Should().HaveCount(expectedTeamMembersCount); report.IndividualReports.Should().OnlyContain(r => r.IsEmpty); }); DataSourceMock.VerifyAll(); RepositoryMock.Verify(); }
public void ShouldThrowExceptionIfProfileNotFound() { SetupGetProfile(null); Handler.Awaiting(h => h.Handle(Command)) .Should().Throw <ArgumentException>(); DataSourceMock.Verify(); }
public async Task ShouldCorrectlyCalculateMetricsForEachMember() { const int expectedTeamMembersCount = 2; var start = DateTime.Now.AddDays(-7); var end = DateTime.Now; var members = Builder <TeamMemberViewModel> .CreateListOfSize(4) .Build(); var memberIds = members.Take(2).Select(m => m.Id).ToArray(); var additionalMemberIds = members.TakeLast(2).Select(m => m.Id).ToArray(); var repositories = new[] { Guid.NewGuid(), Guid.NewGuid() }; var profile = Builder <ProfileViewModel> .CreateNew() .With(p => p.Members = memberIds) .With(p => p.Repositories = repositories) .Build(); var pullRequests = GetPullRequests(start, end, memberIds, repositories) .Union(GetPullRequests(start, end, memberIds, new[] { Guid.NewGuid(), Guid.NewGuid() })) .Union(GetPullRequests(start, end, additionalMemberIds, repositories)) .ToArray(); SetupGetProfile(profile); SetupGetTeamMember(members); SetupGetPullRequests(pullRequests); var command = new GeneratePullRequestsReport { Profile = Guid.NewGuid(), Start = start, End = end }; await InvokeAndVerify <PullRequestsReport>(command, (report, reportId) => { report.Should().NotBeNull(); report.IndividualReports.Should().HaveCount(expectedTeamMembersCount); var firstMemberReport = report.IndividualReports.First(); var secondMemberReport = report.IndividualReports.Last(); firstMemberReport.Created.Should().Be(7); firstMemberReport.Active.Should().Be(4); firstMemberReport.Completed.Should().Be(3); firstMemberReport.Abandoned.Should().Be(2); firstMemberReport.TotalIterations.Should().Be(9); firstMemberReport.TotalComments.Should().Be(18); secondMemberReport.Created.Should().Be(7); secondMemberReport.Active.Should().Be(5); secondMemberReport.Completed.Should().Be(6); secondMemberReport.Abandoned.Should().Be(1); secondMemberReport.TotalIterations.Should().Be(12); secondMemberReport.TotalComments.Should().Be(24); }); DataSourceMock.VerifyAll(); RepositoryMock.Verify(); }
protected override GenerateAggregatedWorkitemsETAReportHandler InitializeHandler() { var realDataSource = new VstsDataSource(RepositoryMock.Object, Mapper, Mock.Of <ILogger <VstsDataSource> >()); DataSourceMock.Setup(d => d.GetActiveDuration(It.IsAny <WorkItemViewModel>(), It.IsAny <IEnumerable <TeamMemberViewModel> >())) .Returns <WorkItemViewModel, IEnumerable <TeamMemberViewModel> >((w, t) => realDataSource.GetActiveDuration(w, t)); DataSourceMock.Setup(d => d.GetETAValues(It.IsAny <WorkItemViewModel>())) .Returns <WorkItemViewModel>(w => realDataSource.GetETAValues(w)); _classificationContextMock = new Mock <IWorkItemClassificationContext>(MockBehavior.Strict); return(new GenerateAggregatedWorkitemsETAReportHandler( DataSourceProviderMock.Object, _classificationContextMock.Object, RepositoryMock.Object, GetLoggerMock <GenerateAggregatedWorkitemsETAReportHandler>())); }
public async Task ShouldReturnEmptyReportForEachMemberIfNoWorkItems() { var profile = Builder <ProfileViewModel> .CreateNew() .With(p => p.Members, new Guid[0]) .Build(); SetupGetProfile(profile); DataSourceMock.Setup(d => d.GetWorkItemsFor(It.IsAny <Guid>())) .ReturnsAsync(Enumerable.Empty <WorkItemViewModel>()) .Verifiable(); await InvokeAndVerify <AggregatedWorkitemsETAReport>(Command, (report, reportId) => { report.IndividualReports.Should().BeEmpty(); }); }
public async Task ShouldHandlePullRequestCompletedInFuture() { var start = DateTime.Now.AddDays(-11); var end = DateTime.Now; var member = Builder <TeamMemberViewModel> .CreateNew() .Build(); var memberIds = new[] { member.Id }; var repositories = new[] { Guid.NewGuid() }; var profile = Builder <ProfileViewModel> .CreateNew() .With(p => p.Members = new[] { member.Id }) .With(p => p.Repositories = repositories) .Build(); var pullRequest = GetCompletedPullRequest(member.Id, repositories[0], end.AddHours(5), end.AddHours(5), createdInThePast: true); SetupGetProfile(profile); SetupGetTeamMember(new[] { member }); SetupGetPullRequests(new[] { pullRequest }); var command = new GeneratePullRequestsReport { Profile = Guid.NewGuid(), Start = start, End = end }; await InvokeAndVerify <PullRequestsReport>(command, (report, reportId) => { report.Should().NotBeNull(); var firstMemberReport = report.IndividualReports.First(); firstMemberReport.Created.Should().Be(1); firstMemberReport.Active.Should().Be(0); firstMemberReport.Completed.Should().Be(0); firstMemberReport.Abandoned.Should().Be(0); firstMemberReport.TotalIterations.Should().Be(1); firstMemberReport.TotalComments.Should().Be(2); firstMemberReport.AveragePRLifespan.Should().Be(TimeSpan.Zero); }); DataSourceMock.VerifyAll(); RepositoryMock.Verify(); }
private void SetupGetPullRequests(IEnumerable <PullRequestViewModel> allPullRequests) { DataSourceMock.Setup(d => d.GetPullRequests(It.IsAny <Expression <Func <PullRequestViewModel, bool> > >())) .Returns <Expression <Func <PullRequestViewModel, bool> > >(e => Task.FromResult(allPullRequests.Where(e.Compile()))); }
protected void SetupGetWorkitems(Guid memberId, IEnumerable <WorkItemViewModel> workitems) { DataSourceMock.Setup(d => d.GetWorkItemsFor(memberId)) .ReturnsAsync(workitems) .Verifiable(); }
protected void SetupGetTeamMember(IEnumerable <TeamMemberViewModel> members) { DataSourceMock.Setup(d => d.GetTeamMember(It.IsAny <Guid>())) .Returns <Guid>(id => Task.FromResult(members.Single(m => m.Id == id))) .Verifiable(); }
protected void SetupGetProfile(ProfileViewModel profile) { DataSourceMock.Setup(d => d.GetProfile(It.IsAny <Guid>())) .ReturnsAsync(profile) .Verifiable(); }