public void TournamentCommandHandler_HandleCommand_CreateTournamentCommand_CommandHandled() { Mock <IAggregateRepository <GolfClubAggregate> > golfClubRepository = new Mock <IAggregateRepository <GolfClubAggregate> >(); golfClubRepository.Setup(c => c.GetLatestVersion(It.IsAny <Guid>(), It.IsAny <CancellationToken>())) .ReturnsAsync(GolfClubTestData.GetGolfClubAggregateWithMeasuredCourse()); Mock <IAggregateRepository <TournamentAggregate> > tournamentRepository = new Mock <IAggregateRepository <TournamentAggregate> >(); tournamentRepository.Setup(t => t.GetLatestVersion(It.IsAny <Guid>(), It.IsAny <CancellationToken>())) .ReturnsAsync(TournamentTestData.GetEmptyTournamentAggregate); Mock <ITournamentApplicationService> tournamentApplicationService = new Mock <ITournamentApplicationService>(); TournamentCommandHandler handler = new TournamentCommandHandler(golfClubRepository.Object, tournamentRepository.Object, tournamentApplicationService.Object); CreateTournamentCommand command = TournamentTestData.GetCreateTournamentCommand(); Should.NotThrow(async() => { await handler.Handle(command, CancellationToken.None); }); }
public void TournamentCommandHandler_HandleCommand_CreateTournamentCommand_ClubNotFound_ErrorThrown() { // test added as part of bug #29 fixes Mock <IAggregateRepository <GolfClubAggregate> > golfClubRepository = new Mock <IAggregateRepository <GolfClubAggregate> >(); golfClubRepository.Setup(c => c.GetLatestVersion(It.IsAny <Guid>(), It.IsAny <CancellationToken>())).ReturnsAsync(GolfClubTestData.GetEmptyGolfClubAggregate); Mock <IAggregateRepository <TournamentAggregate> > tournamentRepository = new Mock <IAggregateRepository <TournamentAggregate> >(); tournamentRepository.Setup(t => t.GetLatestVersion(It.IsAny <Guid>(), It.IsAny <CancellationToken>())) .ReturnsAsync(TournamentTestData.GetEmptyTournamentAggregate); Mock <ITournamentApplicationService> tournamentApplicationService = new Mock <ITournamentApplicationService>(); TournamentCommandHandler handler = new TournamentCommandHandler(golfClubRepository.Object, tournamentRepository.Object, tournamentApplicationService.Object); CreateTournamentCommand command = TournamentTestData.GetCreateTournamentCommand(); Should.Throw <NotFoundException>(async() => { await handler.Handle(command, CancellationToken.None); }); }