public async Task CanOrderResultsBy_Timestamp()
        {
            var campaignRepo = Mock.Of <ICampaignRepository>(mock =>
                                                             mock.GetAll() == Task.FromResult <IReadOnlyCollection <Impl.Entities.Campaign> >(Array.Empty <Impl.Entities.Campaign>()), MockBehavior.Strict);

            var enrollment1 = CreateEmptyReadModel();

            enrollment1.Timestamp = clock.GetCurrentInstant().Minus(Duration.FromDays(2));
            var enrollment2 = CreateEmptyReadModel();

            enrollment2.Timestamp = clock.GetCurrentInstant().Minus(Duration.FromDays(1));
            var enrollment3 = CreateEmptyReadModel();

            enrollment3.Timestamp = clock.GetCurrentInstant().Minus(Duration.FromDays(4));
            var enrollment4 = CreateEmptyReadModel();

            enrollment4.Timestamp = clock.GetCurrentInstant().Minus(Duration.FromDays(3));

            var repo    = new EnrollmentRepoStub(enrollment1, enrollment2, enrollment3, enrollment4);
            var handler = new GetSubmissionsQueryHandler(repo, campaignRepo, clock);

            var results = await handler.Handle(new GetSubmissions.Query()
            {
                SortBy = GetSubmissions.SortBy.Timestamp
            }, CancellationToken.None);

            results.IsOrderedBy(x => x.Timestamp, OffsetDateTime.Comparer.Local).Should().BeTrue();
        }
        public async Task CanOrderResultsBy_LastName()
        {
            var campaignRepo = Mock.Of <ICampaignRepository>(mock =>
                                                             mock.GetAll() == Task.FromResult <IReadOnlyCollection <Impl.Entities.Campaign> >(Array.Empty <Impl.Entities.Campaign>()), MockBehavior.Strict);

            var enrollment1 = CreateEmptyReadModel();

            enrollment1.LastName = "b";
            var enrollment2 = CreateEmptyReadModel();

            enrollment2.LastName = "a";
            var enrollment3 = CreateEmptyReadModel();

            enrollment3.LastName = "d";
            var enrollment4 = CreateEmptyReadModel();

            enrollment4.LastName = "c";

            var repo    = new EnrollmentRepoStub(enrollment1, enrollment2, enrollment3, enrollment4);
            var handler = new GetSubmissionsQueryHandler(repo, campaignRepo, clock);

            var results = await handler.Handle(new GetSubmissions.Query()
            {
                SortBy = GetSubmissions.SortBy.LastName
            }, CancellationToken.None);

            results.IsOrderedBy(x => x.LastName).Should().BeTrue();
        }
        public async Task When_queried_with_flag_HasResigned_set_to_false__results_contains_enrollments_with_temporary_resignations_with_past_ResumeDate()
        {
            // Arrange
            var newCampaign = new Impl.Entities.Campaign(now.Minus(aWeek), now.Plus(aWeek), editionId: 1);

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

            var repo = new EnrollmentRepository();
            await repo.Insert(new EnrollmentReadModel()
            {
                Id       = EnrollmentAggregate.EnrollmentId.New,
                Campaign = new EnrollmentReadModel.CampaignSummary()
                {
                    Id = 1
                },
                PreferredTrainings       = Array.Empty <EnrollmentReadModel.TrainingSummary>(),
                PreferredLecturingCities = Array.Empty <string>(),
                HasResignedTemporarily   = true,
                ResumeDate = now.Minus(aDay).Date
            });

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

            // Act
            var results = await queryHandler.Handle(new Recruitment.Enrollments.GetSubmissions.Query()
            {
                HasResigned = false
            }, CancellationToken.None);

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

            Assert.False(summary.HasResignedTemporarily);
            Assert.Null(summary.ResumeDate);
        }
        public async Task When_recruitment_form_from_past_recruitment_campaign_is_submitted__its_summary_has_flag_IsNewSubmission_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 EnrollmentRepository();
            await repo.Insert(new EnrollmentReadModel()
            {
                Id       = EnrollmentAggregate.EnrollmentId.New,
                Campaign = new EnrollmentReadModel.CampaignSummary()
                {
                    Id = 1
                },
                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 == 1);
            Assert.True(summary.IsOldSubmission);
        }