public async Task TrainingStartDateMustBeEarlierThanItsEndDate()
        {
            var sp = new ServiceProviderBuilder().BuildServiceProvider(ConfigureServices);
            var createCampaignCommand = new Create.Command()
            {
                Name          = "test",
                EditionID     = 1,
                StartDateTime = new NodaTime.LocalDateTime(2019, 09, 01, 12, 00).InMainTimezone().ToOffsetDateTime(),
                EndDateTime   = new NodaTime.LocalDateTime(2019, 09, 30, 12, 00).InMainTimezone().ToOffsetDateTime()
            };

            await CreateCampaign(sp, createCampaignCommand);

            using (var scope = sp.CreateScope())
            {
                var engine  = scope.ServiceProvider.GetRequiredService <Szlem.SharedKernel.ISzlemEngine>();
                var command = new ScheduleTraining.Command
                {
                    City          = "Watykan",
                    Address       = "Papieska 21/37",
                    StartDateTime = new NodaTime.LocalDateTime(2019, 10, 15, 15, 00),
                    EndDateTime   = new NodaTime.LocalDateTime(2019, 10, 15, 10, 00),
                    CampaignID    = 1
                };

                var result = await engine.Execute(command);

                Assert.True(result.IsFailure);
                var error = Assert.IsType <Error.ValidationFailed>(result.Error);
                AssertHelpers.SingleError(nameof(ScheduleTraining.Command.StartDateTime), ErrorMessages.StartDateTimeCannotBeGreaterThanEndDateTime, error.Failures);
            }
        }
        public async Task Command_must_specify_at_least_one_training()
        {
            var sp = new ServiceProviderBuilder().BuildServiceProvider(ConfigureServices);

            using (var scope = sp.CreateScope())
            {
                var engine  = scope.ServiceProvider.GetRequiredService <ISzlemEngine>();
                var command = new SubmitRecruitmentForm.Command()
                {
                    FirstName   = "Andrzej",
                    LastName    = "Strzelba",
                    Email       = EmailAddress.Parse("*****@*****.**"),
                    PhoneNumber = Consts.FakePhoneNumber,
                    AboutMe     = "ala ma kota",
                    Region      = "Wolne Miasto Gdańsk",
                    PreferredLecturingCities = new[] { "Wolne Miasto Gdańsk" },
                    PreferredTrainingIds     = Array.Empty <int>(),
                    GdprConsentGiven         = true
                };

                var result = await engine.Execute(command);

                Assert.True(result.IsFailure);
                var error = Assert.IsType <Error.ValidationFailed>(result.Error);
                AssertHelpers.SingleError(nameof(command.PreferredTrainingIds), SubmitRecruitmentForm_ErrorMessages.PreferredTrainingsMustBeSpecified, error.Failures);
            }
        }
        public async Task Command_MustContain_SubmissionDate_FirstName_LastName_EmailAddress_PhoneNumber_AboutMe()
        {
            var sp = new ServiceProviderBuilder().BuildServiceProvider(ConfigureServices);

            using (var scope = sp.CreateScope())
            {
                var engine  = scope.ServiceProvider.GetRequiredService <ISzlemEngine>();
                var command = new SubmitRecruitmentForm.Command()
                {
                    PreferredTrainingIds = new[] { 1 }, GdprConsentGiven = true
                };

                var result = await engine.Execute(command);

                Assert.True(result.IsFailure);
                var error = Assert.IsType <Error.ValidationFailed>(result.Error);
                Assert.Collection(error.Failures,
                                  error => AssertHelpers.SingleError(nameof(command.FirstName), SubmitRecruitmentForm_ErrorMessages.FirstNameIsRequired, error),
                                  error => AssertHelpers.SingleError(nameof(command.LastName), SubmitRecruitmentForm_ErrorMessages.LastNameIsRequired, error),
                                  error => AssertHelpers.SingleError(nameof(command.Email), SubmitRecruitmentForm_ErrorMessages.EmailIsRequired, error),
                                  error => AssertHelpers.SingleError(nameof(command.PhoneNumber), SubmitRecruitmentForm_ErrorMessages.PhoneNumberIsRequired, error),
                                  error => AssertHelpers.SingleError(nameof(command.AboutMe), SubmitRecruitmentForm_ErrorMessages.AboutMeIsRequired, error),
                                  error => AssertHelpers.SingleError(nameof(command.Region), SubmitRecruitmentForm_ErrorMessages.RegionIsRequired, error),
                                  error => AssertHelpers.SingleError(nameof(command.PreferredLecturingCities), SubmitRecruitmentForm_ErrorMessages.PreferredLecturingCities_must_be_specified, error)
                                  );
            }
        }
Exemple #4
0
        public void If_candidate_was_present_but_was_not_accepted_as_lecturer_then_command_must_contain_additional_notes()
        {
            // Arrange
            var id     = EnrollmentAggregate.EnrollmentId.New;
            var event1 = new DomainEvent <EnrollmentAggregate, EnrollmentAggregate.EnrollmentId, RecruitmentFormSubmitted>(
                new RecruitmentFormSubmitted(
                    NodaTime.SystemClock.Instance.GetCurrentInstant(),
                    "Andrzej", "Strzelba",
                    EmailAddress.Parse("*****@*****.**"), Consts.FakePhoneNumber,
                    "ala ma kota", 1, "Wolne Miasto Gdańsk", new[] { "Wadowice" }, new[] { 1 }, true),
                new Metadata(), DateTimeOffset.Now, id, 1
                );
            var event2 = new DomainEvent <EnrollmentAggregate, EnrollmentAggregate.EnrollmentId, CandidateAcceptedTrainingInvitation>(
                new CandidateAcceptedTrainingInvitation(Guid.NewGuid(), CommunicationChannel.OutgoingEmail, 1, string.Empty),
                new Metadata(), DateTimeOffset.Now, id, 2
                );
            var enrollment = new EnrollmentAggregate(id);

            enrollment.ApplyEvents(new IDomainEvent[] { event1, event2 });
            var recordingCoordinator = new ApplicationUser()
            {
                Id = Guid.NewGuid()
            };

            // Act
            var result = enrollment.RecordTrainingResults(new RecordTrainingResults.Command()
            {
                EnrollmentId    = id.GetGuid(),
                TrainingId      = 1,
                TrainingResult  = RecordTrainingResults.TrainingResult.PresentButNotAcceptedAsLecturer,
                AdditionalNotes = null
            },
                                                          recordingCoordinator,
                                                          new[] { BuildDefaultTraining() },
                                                          BuildDefaultTraining(),
                                                          NodaTime.SystemClock.Instance.GetCurrentInstant());

            // Assert
            Assert.False(result.IsSuccess);
            var error   = Assert.IsType <Error.ValidationFailed>(result.Error);
            var failure = Assert.Single(error.Failures);

            AssertHelpers.SingleError(
                nameof(RecordTrainingResults.Command.AdditionalNotes),
                RecordTrainingResults_Messages.IfCandidateWasNotAccepted_CommandMustContainExplanation,
                failure);
        }
        public async Task CampaignCannotStart_BeforeEditionStart()
        {
            var sp       = new ServiceProviderBuilder().BuildServiceProvider(ConfigureServices);
            var mediator = sp.GetRequiredService <IMediator>();
            var command  = new Create.Command()
            {
                Name          = "test",
                StartDateTime = new NodaTime.LocalDateTime(2019, 08, 15, 12, 00, 00).InMainTimezone().ToOffsetDateTime(),
                EndDateTime   = new NodaTime.LocalDateTime(2019, 10, 01, 12, 00, 00).InMainTimezone().ToOffsetDateTime(),
                EditionID     = 1
            };

            var result = await mediator.Send(command);

            Assert.False(result.IsSuccess);
            var error = Assert.IsType <Error.ValidationFailed>(result.Error);

            AssertHelpers.SingleError(nameof(command.StartDateTime), Create.ErrorMessages.CampaignCannotStartBeforeEditionStart, error.Failures);
        }