コード例 #1
0
        public async Task If_candidate_resigned_permanently__AvailableCandidates_do_not_contain_that_candidate()
        {
            // Arrange
            var trainerId = Guid.NewGuid();

            (var campaignRepo, var trainingRepo, var trainerProvider) = BuildMocks(trainerId, 1, 1);
            var enrollmentId     = EnrollmentAggregate.EnrollmentId.New;
            var enrollmentRepo   = new EnrollmentRepository();
            var readStoreManager = new ReadStoreManager(enrollmentRepo, campaignRepo, trainingRepo);

            var events = new IDomainEvent[]
            {
                new DomainEvent <EnrollmentAggregate, EnrollmentAggregate.EnrollmentId, RecruitmentFormSubmitted>(
                    new RecruitmentFormSubmitted(clock.GetCurrentInstant().Minus(anHour), "Andrzej", "Strzelba", EmailAddress.Parse("*****@*****.**"), Consts.FakePhoneNumber, "jo", 1, "Wolne Miasto Gdańsk", new[] { "Gdańsk", "Wrzeszcz", "Oliwa" }, new[] { 1 }, true),
                    new Metadata(), clock.GetCurrentInstant().ToDateTimeOffset(), enrollmentId, 1),
                new DomainEvent <EnrollmentAggregate, EnrollmentAggregate.EnrollmentId, CandidateResignedPermanently>(
                    new CandidateResignedPermanently(trainerId, Recruitment.Enrollments.CommunicationChannel.IncomingApiRequest, string.Empty, string.Empty),
                    new Metadata(), clock.GetCurrentInstant().ToDateTimeOffset(), enrollmentId, 2)
            };
            await readStoreManager.UpdateReadStoresAsync(events, CancellationToken.None);

            // Act
            var handler = new DetailsHandler(clock, trainingRepo, trainerProvider, enrollmentRepo);
            var result  = await handler.Handle(new Details.Query()
            {
                TrainingId = 1
            }, CancellationToken.None);

            // Assert
            Assert.True(result.HasValue);
            Assert.Equal(TrainingTiming.Future, result.Value.Timing);
            var futureTraining = Assert.IsType <Details.FutureTrainingDetails>(result.Value);

            Assert.Empty(futureTraining.AvailableCandidates);
        }
コード例 #2
0
        public async Task If_candidate_was_not_reported_as_present_or_absent__he_is_not_contained_in_PresentCandidates()
        {
            // Arrange
            var trainerId = Guid.NewGuid();

            (var campaignRepo, var trainingRepo, var trainerProvider) = BuildMocks(trainerId, 1, 1);
            var enrollmentId     = EnrollmentAggregate.EnrollmentId.New;
            var enrollmentRepo   = new EnrollmentRepository();
            var readStoreManager = new ReadStoreManager(enrollmentRepo, campaignRepo, trainingRepo);

            var events = new IDomainEvent[]
            {
                new DomainEvent <EnrollmentAggregate, EnrollmentAggregate.EnrollmentId, RecruitmentFormSubmitted>(
                    new RecruitmentFormSubmitted(clock.GetCurrentInstant().Minus(anHour), "Andrzej", "Strzelba", EmailAddress.Parse("*****@*****.**"), Consts.FakePhoneNumber, "jo", 1, "Wolne Miasto Gdańsk", new[] { "Gdańsk", "Wrzeszcz", "Oliwa" }, new[] { 1 }, true),
                    new Metadata(), clock.GetCurrentInstant().ToDateTimeOffset(), enrollmentId, 1),
                new DomainEvent <EnrollmentAggregate, EnrollmentAggregate.EnrollmentId, CandidateAcceptedTrainingInvitation>(
                    new CandidateAcceptedTrainingInvitation(trainerId, Recruitment.Enrollments.CommunicationChannel.OutgoingPhone, 1, string.Empty),
                    new Metadata(), clock.GetCurrentInstant().ToDateTimeOffset(), enrollmentId, 2)
            };
            await readStoreManager.UpdateReadStoresAsync(events, CancellationToken.None);

            // Act
            var handler = new DetailsHandler(clock, trainingRepo, trainerProvider, enrollmentRepo);
            var result  = await handler.Handle(new Details.Query()
            {
                TrainingId = 1
            }, CancellationToken.None);

            // Assert
            Assert.True(result.HasValue);
            Assert.Equal(TrainingTiming.Past, result.Value.Timing);
            var pastTraining = Assert.IsType <Details.PastTrainingDetails>(result.Value);

            Assert.Empty(pastTraining.PresentCandidates);
        }
コード例 #3
0
        public async Task When_recruitment_form_is_submitted_repo_contains_its_readmodel()
        {
            // Arrange
            var repo     = new EnrollmentRepository();
            var campaign = new Impl.Entities.Campaign(now.Minus(aWeek), now.Plus(aWeek), editionId: 1);

            campaign.GetType().GetProperty(nameof(campaign.Id)).SetValue(campaign, 1);

            var training = new Impl.Entities.Training("Papieska 21/37", "Wadowice", now.Plus(2 * aWeek), now.Plus(2 * aWeek + anHour), Guid.NewGuid());

            training.GetType().GetProperty(nameof(training.ID)).SetValue(training, 1);
            campaign.ScheduleTraining(training);

            var campaignRepo = Mock.Of <ICampaignRepository>(mock => mock.GetById(1) == Task.FromResult(campaign), MockBehavior.Strict);
            var trainingRepo = Mock.Of <ITrainingRepository>(MockBehavior.Strict);

            var readStoreManager = new ReadStoreManager(repo, campaignRepo, trainingRepo);


            // Act
            var @event = new RecruitmentFormSubmitted(
                now.ToInstant(), "Andrzej", "Strzelba",
                EmailAddress.Parse("*****@*****.**"), PhoneNumber.Parse("505551888"),
                "no elo",
                campaignID: 1, region: "Wolne Miasto Gdańsk", preferredLecturingCities: new[] { "Rumia", "Reda", "Wejherowo" }, preferredTrainingIds: new[] { 1 },
                gdprConsentGiven: true);
            var domainEvent = new DomainEvent <EnrollmentAggregate, EnrollmentAggregate.EnrollmentId, RecruitmentFormSubmitted>(@event, new Metadata(), DateTimeOffset.Now, EnrollmentAggregate.EnrollmentId.New, 1);

            await readStoreManager.UpdateReadStoresAsync(new[] { domainEvent }, CancellationToken.None);

            // Assert
            var enrollment = Assert.Single(repo.Query());

            Assert.Equal("Andrzej Strzelba", enrollment.FullName);
            Assert.Equal(EmailAddress.Parse("*****@*****.**"), enrollment.Email);
            Assert.Equal(PhoneNumber.Parse("505551888"), enrollment.PhoneNumber);
            Assert.Equal("no elo", enrollment.AboutMe);
            Assert.Equal("Wolne Miasto Gdańsk", enrollment.Region);
            Assert.Equal(1, enrollment.Campaign.Id);
            Assert.Null(enrollment.ResumeDate);
            Assert.Collection(enrollment.PreferredLecturingCities,
                              first => Assert.Equal("Rumia", first),
                              second => Assert.Equal("Reda", second),
                              third => Assert.Equal("Wejherowo", third));
            var preferredTraining = Assert.Single(enrollment.PreferredTrainings);

            Assert.Equal("Wadowice", preferredTraining.City);
        }
コード例 #4
0
        public async Task When_training_invitation_is_refused__readmodel_does_not_contain_training_ID()
        {
            // Arrange
            var id   = EnrollmentAggregate.EnrollmentId.New;
            var repo = new EnrollmentRepository();

            var campaign = new Impl.Entities.Campaign(now.Minus(3 * aWeek), now.Minus(2 * aWeek), editionId: 1);

            campaign.GetType().GetProperty(nameof(campaign.Id)).SetValue(campaign, 1);
            var training = new Impl.Entities.Training("Papieska 21/37", "Wadowice", now.Minus(2 * aWeek + anHour), now.Minus(2 * aWeek), Guid.NewGuid());

            training.GetType().GetProperty(nameof(training.ID)).SetValue(training, 1);
            campaign.ScheduleTraining(training);
            var campaignRepo = Mock.Of <ICampaignRepository>(mock => mock.GetById(1) == Task.FromResult(campaign), MockBehavior.Strict);
            var trainingRepo = Mock.Of <ITrainingRepository>(mock => mock.GetById(1) == Task.FromResult(Maybe <Training> .From(training)), MockBehavior.Strict);

            await repo.Insert(new EnrollmentReadModel()
            {
                Id = id, SelectedTraining = new EnrollmentReadModel.TrainingSummary()
                {
                    ID = 1
                }
            });

            var readStoreManager = new ReadStoreManager(repo, campaignRepo, trainingRepo);

            // Act
            await readStoreManager.UpdateReadStoresAsync(new[] {
                new DomainEvent <EnrollmentAggregate, EnrollmentAggregate.EnrollmentId, CandidateRefusedTrainingInvitation>(
                    new CandidateRefusedTrainingInvitation(
                        Guid.NewGuid(),
                        Recruitment.Enrollments.CommunicationChannel.IncomingPhone,
                        string.Empty, string.Empty),
                    new Metadata(), DateTimeOffset.Now, id, 1),
            },
                                                         CancellationToken.None);

            // Assert
            var enrollment = Assert.Single(repo.Query());

            Assert.Equal(id, enrollment.Id);
            Assert.Null(enrollment.SelectedTraining);
        }
コード例 #5
0
        public async Task When_temporary_resignation_is_recorded_without_providing_end_date__readmodel_has_no_suspension_end_date()
        {
            // Arrange
            var id   = EnrollmentAggregate.EnrollmentId.New;
            var repo = new EnrollmentRepository();

            var campaign = new Impl.Entities.Campaign(now.Minus(3 * aWeek), now.Minus(2 * aWeek), editionId: 1);

            campaign.GetType().GetProperty(nameof(campaign.Id)).SetValue(campaign, 1);
            var training = new Impl.Entities.Training("Papieska 21/37", "Wadowice", now.Minus(2 * aWeek + anHour), now.Minus(2 * aWeek), Guid.NewGuid());

            training.GetType().GetProperty(nameof(training.ID)).SetValue(training, 1);
            campaign.ScheduleTraining(training);
            var campaignRepo = Mock.Of <ICampaignRepository>(mock => mock.GetById(1) == Task.FromResult(campaign), MockBehavior.Strict);
            var trainingRepo = Mock.Of <ITrainingRepository>(MockBehavior.Strict);

            await repo.Insert(new EnrollmentReadModel()
            {
                Id = id
            });

            var readStoreManager = new ReadStoreManager(repo, campaignRepo, trainingRepo);

            // Act
            await readStoreManager.UpdateReadStoresAsync(new[] {
                new DomainEvent <EnrollmentAggregate, EnrollmentAggregate.EnrollmentId, CandidateResignedTemporarily>(
                    new CandidateResignedTemporarily(
                        Guid.NewGuid(),
                        Recruitment.Enrollments.CommunicationChannel.IncomingPhone,
                        string.Empty, string.Empty,
                        resumeDate: null),
                    new Metadata(), DateTimeOffset.Now, id, 1),
            },
                                                         CancellationToken.None);

            // Assert
            var enrollment = Assert.Single(repo.Query());

            Assert.Equal(id, enrollment.Id);
            Assert.True(enrollment.HasResignedTemporarily);
            Assert.Null(enrollment.ResumeDate);
        }
コード例 #6
0
        public async Task When_candidate_obtains_lecturer_rights_Readmodel_has_flag_HasLecturerRigths_set_to_true()
        {
            // Arrange
            var id   = EnrollmentAggregate.EnrollmentId.New;
            var repo = new EnrollmentRepository();

            var campaign = new Impl.Entities.Campaign(now.Minus(3 * aWeek), now.Minus(2 * aWeek), editionId: 1);

            campaign.GetType().GetProperty(nameof(campaign.Id)).SetValue(campaign, 1);
            var training = new Impl.Entities.Training("Papieska 21/37", "Wadowice", now.Minus(2 * aWeek + anHour), now.Minus(2 * aWeek), Guid.NewGuid());

            training.GetType().GetProperty(nameof(training.ID)).SetValue(training, 1);
            campaign.ScheduleTraining(training);
            var campaignRepo = Mock.Of <ICampaignRepository>(mock => mock.GetById(1) == Task.FromResult(campaign), MockBehavior.Strict);
            var trainingRepo = Mock.Of <ITrainingRepository>(MockBehavior.Strict);

            await repo.Insert(new EnrollmentReadModel()
            {
                Id = id
            });

            var readStoreManager = new ReadStoreManager(repo, campaignRepo, trainingRepo);

            // Act
            await readStoreManager.UpdateReadStoresAsync(new[] {
                new DomainEvent <EnrollmentAggregate, EnrollmentAggregate.EnrollmentId, CandidateObtainedLecturerRights>(
                    new CandidateObtainedLecturerRights(Guid.NewGuid(), "zdobył uprawnienia"),
                    new Metadata(), DateTimeOffset.Now, id, 1),
            },
                                                         CancellationToken.None);

            // Assert
            var enrollment = Assert.Single(repo.Query());

            Assert.Equal(id, enrollment.Id);
            Assert.True(enrollment.HasLecturerRights);
        }