Example #1
0
        public void GolfClubMembershipApplicationService_RequestClubMembership_ClubNotCreated_ErrorThrown()
        {
            Mock <IAggregateRepository <GolfClubAggregate> > golfClubRepository = new Mock <IAggregateRepository <GolfClubAggregate> >();

            golfClubRepository.Setup(g => g.GetLatestVersion(It.IsAny <Guid>(), CancellationToken.None))
            .ReturnsAsync(GolfClubTestData.GetEmptyGolfClubAggregate());

            Mock <IAggregateRepository <PlayerAggregate> > playerRepository = new Mock <IAggregateRepository <PlayerAggregate> >();

            playerRepository.Setup(p => p.GetLatestVersion(It.IsAny <Guid>(), CancellationToken.None))
            .ReturnsAsync(PlayerTestData.GetRegisteredPlayerAggregate());

            Mock <IAggregateRepository <GolfClubMembershipAggregate> > golfClubMembershipRepository = new Mock <IAggregateRepository <GolfClubMembershipAggregate> >();

            golfClubMembershipRepository.Setup(g => g.GetLatestVersion(It.IsAny <Guid>(), CancellationToken.None)).ReturnsAsync(GolfClubMembershipTestData.GetCreatedGolfClubMembershipAggregate());

            GolfClubMembershipApplicationService service = new GolfClubMembershipApplicationService(golfClubRepository.Object,
                                                                                                    playerRepository.Object,
                                                                                                    golfClubMembershipRepository.Object);

            Should.Throw <InvalidDataException>(async() => await service.RequestClubMembership(GolfClubMembershipTestData.PlayerId, GolfClubMembershipTestData.AggregateId,
                                                                                               CancellationToken.None));

            golfClubMembershipRepository.Verify(
                x => x.SaveChanges(It.IsAny <GolfClubMembershipAggregate>(), CancellationToken.None), Times.Never);
        }
        public void GolfClubAggregate_AddTournamentDivision_ClubNotCreated_ErrorThrown()
        {
            GolfClubAggregate aggregate = GolfClubTestData.GetEmptyGolfClubAggregate();
            TournamentDivisionDataTransferObject tournamentDivision = GolfClubTestData.GetTournamentDivision1();

            Should.Throw <InvalidOperationException>(() => { aggregate.AddTournamentDivision(tournamentDivision); });
        }
        public void GolfClubAggregate_AddMeasuredCourse_ClubNotCreated_ErrorThrown()
        {
            GolfClubAggregate aggregate = GolfClubTestData.GetEmptyGolfClubAggregate();

            MeasuredCourseDataTransferObject measuredCourseDataTransferObject = GolfClubTestData.GetMeasuredCourseToAdd();

            Should.Throw <InvalidOperationException>(() => { aggregate.AddMeasuredCourse(measuredCourseDataTransferObject); });
        }
        public void GolfClubAggregate_CreateMatchSecretarySecurityUser_InvalidData_ErrorThrown()
        {
            GolfClubAggregate aggregate = GolfClubTestData.GetEmptyGolfClubAggregate();

            Should.Throw <ArgumentNullException>(() => { aggregate.CreateMatchSecretarySecurityUser(Guid.Empty); });
        }
        public void GolfClubAggregate_CreateMatchSecretarySecurityUser_ClubNotCreated_ErrorThrown()
        {
            GolfClubAggregate aggregate = GolfClubTestData.GetEmptyGolfClubAggregate();

            Should.Throw <InvalidOperationException>(() => { aggregate.CreateMatchSecretarySecurityUser(GolfClubTestData.MatchSecretarySecurityUserId); });
        }
        public void GolfClubCommandHandler_HandleCommand_CreateGolfClubCommand_CommandHandled()
        {
            Mock <IAggregateRepository <GolfClubAggregate> > repository = new Mock <IAggregateRepository <GolfClubAggregate> >();

            repository.Setup(r => r.GetLatestVersion(It.IsAny <Guid>(), CancellationToken.None)).ReturnsAsync(GolfClubTestData.GetEmptyGolfClubAggregate());
            Mock <ISecurityService> oAuth2SecurityService = new Mock <ISecurityService>();

            oAuth2SecurityService
            .Setup(o => o.RegisterUser(It.IsAny <RegisterUserRequest>(), CancellationToken.None))
            .ReturnsAsync(GolfClubTestData.GetRegisterUserResponse());
            Mock <IGolfClubMembershipApplicationService> golfClubMembershipApplicationService = new Mock <IGolfClubMembershipApplicationService>();

            GolfClubCommandHandler handler = new GolfClubCommandHandler(repository.Object, oAuth2SecurityService.Object,
                                                                        golfClubMembershipApplicationService.Object);

            CreateGolfClubCommand command = GolfClubTestData.GetCreateGolfClubCommand();

            Should.NotThrow(async() => { await handler.Handle(command, CancellationToken.None); });
        }