Beispiel #1
0
        public async Task GolfClubMembershipApplicationService_RequestClubMembership_PlayerNotCreated_ErrorThrown()
        {
            Mock <IAggregateRepository <GolfClubAggregate> > golfClubRepository = new Mock <IAggregateRepository <GolfClubAggregate> >();

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

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

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

            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_AddMeasuredCourse_MeasuredCourseWithHolesAdded()
        {
            GolfClubAggregate aggregate = GolfClubTestData.GetCreatedGolfClubAggregate();

            MeasuredCourseDataTransferObject measuredCourseDataTransferObject = GolfClubTestData.GetMeasuredCourseToAdd();

            aggregate.AddMeasuredCourse(measuredCourseDataTransferObject);

            MeasuredCourseDataTransferObject measuredCourse = aggregate.GetMeasuredCourse(measuredCourseDataTransferObject.MeasuredCourseId);

            measuredCourse.ShouldNotBeNull();
            measuredCourse.Name.ShouldBe(measuredCourseDataTransferObject.Name);
            measuredCourse.StandardScratchScore.ShouldBe(measuredCourseDataTransferObject.StandardScratchScore);
            measuredCourse.TeeColour.ShouldBe(measuredCourseDataTransferObject.TeeColour);
            measuredCourse.Holes.Count.ShouldBe(measuredCourseDataTransferObject.Holes.Count);

            IOrderedEnumerable <HoleDataTransferObject> resultHoles = measuredCourse.Holes.OrderBy(m => m.HoleNumber);

            foreach (HoleDataTransferObject holeDataTransferObject in resultHoles)
            {
                HoleDataTransferObject orignalHole = measuredCourseDataTransferObject.Holes.Single(h => h.HoleNumber == holeDataTransferObject.HoleNumber);

                holeDataTransferObject.HoleNumber.ShouldBe(orignalHole.HoleNumber);
                holeDataTransferObject.LengthInMeters.ShouldBe(orignalHole.LengthInMeters);
                holeDataTransferObject.LengthInYards.ShouldBe(orignalHole.LengthInYards);
                holeDataTransferObject.Par.ShouldBe(orignalHole.Par);
                holeDataTransferObject.StrokeIndex.ShouldBe(orignalHole.StrokeIndex);
            }
        }
Beispiel #3
0
        public async Task GolfClubMembershipApplicationService_RequestClubMembership_MembershipRequestProcessed()
        {
            Mock <IAggregateRepository <GolfClubAggregate> > golfClubRepository = new Mock <IAggregateRepository <GolfClubAggregate> >();

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

            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);

            await service.RequestClubMembership(GolfClubMembershipTestData.PlayerId, GolfClubMembershipTestData.AggregateId,
                                                CancellationToken.None);

            golfClubMembershipRepository.Verify(
                x => x.SaveChanges(It.IsAny <GolfClubMembershipAggregate>(), CancellationToken.None), Times.Once);
        }
        public void GolfClubAggregate_AddMeasuredCourse_InvalidHoleData_MissingHoleNumber_ErrorThrown(Int32 holeNumber)
        {
            GolfClubAggregate aggregate = GolfClubTestData.GetCreatedGolfClubAggregate();

            MeasuredCourseDataTransferObject measuredCourseDataTransferObject = GolfClubTestData.GetMeasuredCourseToAddWithMissingHoles(holeNumber);

            Should.Throw <InvalidDataException>(() => { aggregate.AddMeasuredCourse(measuredCourseDataTransferObject); });
        }
        public void GolfClubAggregate_GetMeasuredCourses_NoCourses_ErrorThrown()
        {
            GolfClubAggregate aggregate = GolfClubTestData.GetCreatedGolfClubAggregate();

            MeasuredCourseDataTransferObject measuredCourseDataTransferObject = GolfClubTestData.GetMeasuredCourseToAdd();

            Should.Throw <NotFoundException>(() => { aggregate.GetMeasuredCourses(); });
        }
        public void GolfClubAggregate_AddMeasuredCourse_InvalidNumberOfHoles_ErrorThrown(Int32 numberHoles)
        {
            GolfClubAggregate aggregate = GolfClubTestData.GetCreatedGolfClubAggregate();

            MeasuredCourseDataTransferObject measuredCourseDataTransferObject = GolfClubTestData.GetMeasuredCourseToAdd(numberHoles);

            Should.Throw <InvalidDataException>(() => { aggregate.AddMeasuredCourse(measuredCourseDataTransferObject); });
        }
        public void GolfClubAggregate_CreateGolfClubAdministratorSecurityUser_GolfClubAdministratorSecurityUserCreated()
        {
            GolfClubAggregate aggregate = GolfClubTestData.GetCreatedGolfClubAggregate();

            aggregate.CreateGolfClubAdministratorSecurityUser(GolfClubTestData.GolfClubAdministratorSecurityUserId);

            aggregate.GolfClubAdministratorSecurityUserId.ShouldBe(GolfClubTestData.GolfClubAdministratorSecurityUserId);
            aggregate.HasAdminSecurityUserBeenCreated.ShouldBeTrue();
        }
        public void GolfClubAggregate_AddMeasuredCourse_DuplicateMeasuredCourse_ErrorThrown()
        {
            GolfClubAggregate aggregate = GolfClubTestData.GetCreatedGolfClubAggregate();

            MeasuredCourseDataTransferObject measuredCourseDataTransferObject = GolfClubTestData.GetMeasuredCourseToAdd();

            aggregate.AddMeasuredCourse(measuredCourseDataTransferObject);

            Should.Throw <InvalidOperationException>(() => { aggregate.AddMeasuredCourse(measuredCourseDataTransferObject); });
        }
        public void GolfClubAggregate_AddMeasuredCourse_InvalidHoleData_InvalidData_ErrorThrown(Int32 lengthInYards,
                                                                                                Int32 par)
        {
            GolfClubAggregate aggregate = GolfClubTestData.GetCreatedGolfClubAggregate();

            MeasuredCourseDataTransferObject measuredCourseDataTransferObject = GolfClubTestData.GetMeasuredCourseToAdd();

            measuredCourseDataTransferObject.Holes.First().LengthInYards = lengthInYards;
            measuredCourseDataTransferObject.Holes.First().Par           = par;
            Should.Throw <InvalidDataException>(() => { aggregate.AddMeasuredCourse(measuredCourseDataTransferObject); });
        }
        public void GolfClubAggregate_AddMeasuredCourse_InvalidCourseData_ErrorThrown(Boolean validMeasuredCourseId,
                                                                                      String name,
                                                                                      String teeColour,
                                                                                      Int32 standardScratchScore)
        {
            GolfClubAggregate aggregate = GolfClubTestData.GetCreatedGolfClubAggregate();

            MeasuredCourseDataTransferObject measuredCourseDataTransferObject = GolfClubTestData.GetMeasuredCourseToAdd();

            measuredCourseDataTransferObject.MeasuredCourseId     = validMeasuredCourseId ? GolfClubTestData.MeasuredCourseId : Guid.Empty;
            measuredCourseDataTransferObject.Name                 = name;
            measuredCourseDataTransferObject.TeeColour            = teeColour;
            measuredCourseDataTransferObject.StandardScratchScore = standardScratchScore;

            Should.Throw <ArgumentNullException>(() => { aggregate.AddMeasuredCourse(measuredCourseDataTransferObject); });
        }
        public void GolfClubAggregate_CreateMatchSecretarySecurityUser_MatchSecretaryUserAdded()
        {
            GolfClubAggregate aggregate = GolfClubTestData.GetCreatedGolfClubAggregate();

            Should.NotThrow(() => { aggregate.CreateMatchSecretarySecurityUser(GolfClubTestData.MatchSecretarySecurityUserId); });
        }
        public void GolfClubAggregate_CreateGolfClubAdministratorSecurityUser_InvalidData_ErrorThrown()
        {
            GolfClubAggregate aggregate = GolfClubTestData.GetCreatedGolfClubAggregate();

            Should.Throw <ArgumentNullException>(() => { aggregate.CreateGolfClubAdministratorSecurityUser(Guid.Empty); });
        }