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

            campaign.GetType().GetProperty(nameof(campaign.Id)).SetValue(campaign, id);
            return(campaign);
        }
        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);
        }
        public async Task When_recruitment_form_from_latest_recruitment_campaign_is_submitted__its_summary_has_flag_IsCurrentSubmission_set_to_true()
        {
            // Arrange
            var oldCampaign = new Impl.Entities.Campaign(now.Minus(Duration.FromDays(30)), now.Minus(Duration.FromDays(25)), editionId: 1);

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

            var newCampaign = new Impl.Entities.Campaign(now.Minus(aWeek), now.Plus(aWeek), editionId: 1);

            newCampaign.GetType().GetProperty(nameof(newCampaign.Id)).SetValue(newCampaign, 2);

            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);
            newCampaign.ScheduleTraining(training);
            var campaignRepo = Mock.Of <ICampaignRepository>(mock =>
                                                             mock.GetById(1) == Task.FromResult(oldCampaign) &&
                                                             mock.GetById(2) == Task.FromResult(newCampaign) &&
                                                             mock.GetAll() == Task.FromResult(new[] { oldCampaign, newCampaign } as IReadOnlyCollection <Impl.Entities.Campaign>), MockBehavior.Strict);

            var repo = new EnrollmentRepoStub(new EnrollmentReadModel()
            {
                Id       = EnrollmentAggregate.EnrollmentId.New,
                Campaign = new EnrollmentReadModel.CampaignSummary()
                {
                    Id = 2
                },
                PreferredTrainings       = Array.Empty <EnrollmentReadModel.TrainingSummary>(),
                PreferredLecturingCities = Array.Empty <string>()
            });

            var queryHandler = new GetSubmissionsQueryHandler(repo, campaignRepo, clock);

            // Act
            var result = await queryHandler.Handle(new Recruitment.Enrollments.GetSubmissions.Query(), CancellationToken.None);

            // Assert
            var summary = Assert.Single(result);

            Assert.True(summary.Campaign.ID == 2);
            Assert.True(summary.IsCurrentSubmission);
        }