public async Task Valid_command_passes_validation() { var sp = new ServiceProviderBuilder().BuildServiceProvider(ConfigureServices); await CreateCampaign(sp, 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() }); 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, 10, 00), EndDateTime = new NodaTime.LocalDateTime(2019, 10, 15, 15, 00), CampaignID = 1 }; // act var result = await engine.Execute(command); Assert.True(result.IsSuccess); } }
public async Task TrainingMustBelongToExistingCampaign() { var sp = new ServiceProviderBuilder().BuildServiceProvider(ConfigureServices); await CreateCampaign(sp, 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() }); 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, 10, 00), EndDateTime = new NodaTime.LocalDateTime(2019, 10, 15, 15, 00), CampaignID = 2137 }; var result = await engine.Execute(command); Assert.True(result.IsFailure); var error = Assert.IsType <Error.ResourceNotFound>(result.Error); Assert.Equal($"Campaign with ID={command.CampaignID} not found", error.Message); } }
public async Task If_scheduled_training_contains_a_note__that_note_cannot_be_empty() { var sp = new ServiceProviderBuilder().BuildServiceProvider(ConfigureServices); await CreateCampaign(sp, 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() }); 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, 10, 00), EndDateTime = new NodaTime.LocalDateTime(2019, 10, 15, 15, 00), CampaignID = 1, Notes = " " }; var result = await engine.Execute(command); Assert.True(result.IsFailure); var error = Assert.IsType <Error.DomainError>(result.Error); Assert.Equal(ErrorMessages.NoteCannotBeEmpty, error.Message); } }
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 TrainingCommandMustSpecifyCampaign() { var sp = new ServiceProviderBuilder().BuildServiceProvider(ConfigureServices); await CreateCampaign(sp, 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() }); 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, 10, 00), EndDateTime = new NodaTime.LocalDateTime(2019, 10, 15, 15, 00), }; var result = await engine.Execute(command); Assert.True(result.IsFailure); var error = Assert.IsType <Error.ValidationFailed>(result.Error); var failure = error.Failures.Should().ContainSingle().Subject; failure.PropertyName.Should().Be(nameof(ScheduleTraining.Command.CampaignID)); failure.Errors.Should().ContainSingle() .Which.Should().Be("'Campaign ID' must not be empty."); } }
public async Task TrainingMustHaveAddressStartEndDateAndCoordinator() { var sp = new ServiceProviderBuilder().BuildServiceProvider(ConfigureServices); await CreateCampaign(sp, 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() }); using (var scope = sp.CreateScope()) { var engine = scope.ServiceProvider.GetRequiredService <Szlem.SharedKernel.ISzlemEngine>(); var command = new ScheduleTraining.Command { CampaignID = 1 }; // act var result = await engine.Execute(command); Assert.False(result.IsSuccess); var error = Assert.IsType <Error.ValidationFailed>(result.Error); Assert.True(error.Failures.ContainsProperty(nameof(ScheduleTraining.Command.StartDateTime))); Assert.True(error.Failures.ContainsProperty(nameof(ScheduleTraining.Command.EndDateTime))); Assert.True(error.Failures.ContainsProperty(nameof(ScheduleTraining.Command.City))); Assert.True(error.Failures.ContainsProperty(nameof(ScheduleTraining.Command.Address))); } }
public async Task Training_must_begin_and_end_on_the_same_day() { var sp = new ServiceProviderBuilder().BuildServiceProvider(ConfigureServices); await CreateCampaign(sp, 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() }); 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, 10, 00), EndDateTime = new NodaTime.LocalDateTime(2019, 10, 16, 15, 00), CampaignID = 1 }; // act var result = await engine.Execute(command); Assert.False(result.IsSuccess); var error = Assert.IsType <Error.ValidationFailed>(result.Error); Assert.Collection(error.Failures, first => { Assert.Equal(nameof(command.StartDateTime), first.PropertyName); Assert.Single(first.Errors, ErrorMessages.Training_must_begin_and_end_on_the_same_day); }, second => { Assert.Equal(nameof(command.EndDateTime), second.PropertyName); Assert.Single(second.Errors, ErrorMessages.Training_must_begin_and_end_on_the_same_day); } ); } }
public async Task ScheduleTraining_command_produces_a_scheduled_training() { var sp = new ServiceProviderBuilder().BuildServiceProvider(ConfigureServices); await CreateCampaign(sp, 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() }); 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, 10, 00), EndDateTime = new NodaTime.LocalDateTime(2019, 10, 15, 15, 00), CampaignID = 1, Notes = "notatka testowa" }; // act var result = await engine.Execute(command); Assert.True(result.IsSuccess); Assert.Equal(1, result.Value.ID); } // assert using (var scope = sp.CreateScope()) { var mediator = scope.ServiceProvider.GetRequiredService <IMediator>(); var result = await mediator.Send(new Recruitment.Trainings.Details.Query() { TrainingId = 1 }); Assert.True(result.HasValue); var training = result.Value; Assert.Equal(new NodaTime.LocalDateTime(2019, 10, 15, 10, 00).InMainTimezone().ToOffsetDateTime(), training.Start); Assert.Equal(new NodaTime.LocalDateTime(2019, 10, 15, 15, 00).InMainTimezone().ToOffsetDateTime(), training.End); Assert.Equal("Watykan", training.City); Assert.Equal("Papieska 21/37", training.Address); Assert.Equal(trainerID, training.CoordinatorId); Assert.Equal("Jan Paweł II", training.CoordinatorName); var note = Assert.Single(training.Notes); Assert.Equal("notatka testowa", note.Content); Assert.Equal(new NodaTime.LocalDate(2019, 08, 01), note.Timestamp.Date); Assert.Equal("Jan Paweł II", note.AuthorName); } }
public async Task TrainingCannotBeAddedAfterCampaignStart() { var clock = NodaTime.Testing.FakeClock.FromUtc(2019, 08, 30); var sp = new ServiceProviderBuilder().BuildServiceProvider(services => { ConfigureServices(services); //services.Remove<NodaTime.IClock>(); services.AddSingleton <NodaTime.IClock>(clock); }); await CreateCampaign(sp, 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() }); using (var scope = sp.CreateScope()) { clock.AdvanceDays(3); var engine = scope.ServiceProvider.GetRequiredService <Szlem.SharedKernel.ISzlemEngine>(); var command = new ScheduleTraining.Command { City = "Watykan", Address = "Papieska 21/37", StartDateTime = new NodaTime.LocalDateTime(2019, 09, 15, 10, 00), EndDateTime = new NodaTime.LocalDateTime(2019, 09, 15, 15, 00), CampaignID = 1 }; var result = await engine.Execute(command); Assert.True(result.IsFailure); var error = Assert.IsType <Error.DomainError>(result.Error); Assert.Equal(ErrorMessages.CannotScheduleTrainingAfterCampaignStart, error.Message); } }
public async Task <IActionResult> ScheduleTraining(ScheduleTraining.Command command) { var result = await _engine.Execute(command); return(result.MatchToActionResult(v => Created(Routes.v1.RecruitmentCampaigns.DetailsFor(v.ID), null))); }