public void Candidate_must_be_registered_to_resign() { // Arrange var id = EnrollmentAggregate.EnrollmentId.New; var enrollment = new EnrollmentAggregate(id); var recordingCoordinator = new ApplicationUser() { Id = Guid.NewGuid() }; var command = new RecordResignation.Command() { EnrollmentId = id.GetGuid(), CommunicationChannel = CommunicationChannel.OutgoingEmail, ResignationReason = "brak powodu", AdditionalNotes = "brak notatek", ResignationType = RecordResignation.ResignationType.Permanent }; // Act var result = enrollment.RecordResignation(command, recordingCoordinator, NodaTime.SystemClock.Instance.GetCurrentInstant()); // Assert Assert.True(result.IsFailure); var error = Assert.IsType <Error.ResourceNotFound>(result.Error); Assert.Equal(CommonErrorMessages.CandidateNotFound, error.Message); }
public async Task If_school_resigned_permanently__result_has_flag_HasResignedPermanently() { Guid schoolId; var now = NodaTime.SystemClock.Instance.GetZonedDateTime(); var sp = new ServiceProviderBuilder().BuildServiceProvider(ConfigureServices); using (var scope = sp.CreateScope()) { var engine = scope.ServiceProvider.GetRequiredService <ISzlemEngine>(); var command = new RegisterSchool.Command() { Name = "I Liceum Ogólnokształcące", City = "Gdańsk", Address = "Wały Piastowskie 6", ContactData = new[] { new ContactData() { Name = "sekretariat", EmailAddress = EmailAddress.Parse("*****@*****.**"), PhoneNumber = PhoneNumber.Parse("58 301-67-34") }, } }; var result = await engine.Execute(command); result.IsSuccess.Should().BeTrue(); schoolId = result.Value; } using (var scope = sp.CreateScope()) { var engine = scope.ServiceProvider.GetRequiredService <ISzlemEngine>(); var command = new RecordResignation.Command() { SchoolId = schoolId }; var result = await engine.Execute(command); result.IsSuccess.Should().BeTrue(); } using (var scope = sp.CreateScope()) { var engine = scope.ServiceProvider.GetRequiredService <ISzlemEngine>(); var result = await engine.Query(new GetDetails.Query() { SchoolId = schoolId }); result.IsSuccess.Should().BeTrue(); var school = result.Value; school.Should().BeEquivalentTo(new GetDetails.SchoolDetails() { Id = schoolId, Name = "I Liceum Ogólnokształcące", Address = "Wały Piastowskie 6", City = "Gdańsk", HasResignedPermanently = true }, options => options.Excluding(x => x.Events).Excluding(x => x.ContactData)); } }
public async Task <Result <Nothing, Error> > Handle(RecordResignation.Command request, CancellationToken cancellationToken) { var user = await _userAccessor.GetUser(); var now = _clock.GetTodayDate(); var result = await _aggregateStore.Update <SchoolAggregate, SchoolId, Result <Nothing, Error> >( SchoolId.With(request.SchoolId), CommandId.New, (aggregate) => aggregate.RecordResignation(request, user, now), cancellationToken); return(result.Unwrap()); }
public async Task <Result <Nothing, Error> > Handle(RecordResignation.Command request, CancellationToken cancellationToken) { var user = await _userAccessor.GetUser(); var authResult = await _authService.AuthorizeAsync(await _userAccessor.GetClaimsPrincipal(), EnrollmentId.With(request.EnrollmentId), AuthorizationPolicies.OwningCandidateOrCoordinator); if (authResult.Succeeded == false) { return(Result.Failure <Nothing, Error>(new Error.AuthorizationFailed())); } var result = await _aggregateStore.Update <EnrollmentAggregate, EnrollmentId, Result <Nothing, Error> >( EnrollmentId.With(request.EnrollmentId), CommandId.New, (aggregate) => aggregate.RecordResignation(request, user, _clock.GetCurrentInstant()), cancellationToken); return(result.Unwrap()); }
public Result <Nothing, Error> RecordResignation(RecordResignation.Command command, ApplicationUser recordingUser, LocalDate now) { Guard.Against.Null(command, nameof(command)); Guard.Against.Null(recordingUser, nameof(recordingUser)); ValidateIdMatchOrThrow(command.SchoolId); return(Validate(new RecordResignation.Validator(), command) .Ensure( _ => this.IsNew == false, new Error.ResourceNotFound(Messages.School_not_found)) .Ensure( _ => command.PotentialNextContactDate == null || command.PotentialNextContactDate > now, new Error.DomainError(RecordResignation_Messages.PotentialNextContactDate_must_be_later_than_today)) .Tap( () => Emit(new SchoolResignedFromCooperation( recordingUserId: recordingUser.Id, potentialNextContactDate: command.PotentialNextContactDate, additionalNotes: command.AdditionalNotes ?? string.Empty)) )); }
public Result <Nothing, Error> RecordResignation(RecordResignation.Command command, ApplicationUser recordingCoordinator, Instant now) { Guard.Against.Null(command, nameof(command)); Guard.Against.Null(recordingCoordinator, nameof(recordingCoordinator)); ValidateIdMatchOrThrow(command.EnrollmentId); return (Validate(new RecordResignation.Validator(), command) .Ensure( _ => this.IsNew == false, new Error.ResourceNotFound(CommonErrorMessages.CandidateNotFound)) .Ensure( _ => { if (command.ResignationType == Recruitment.Enrollments.RecordResignation.ResignationType.Temporary && command.ResumeDate.HasValue) { return command.ResumeDate.Value >= now.InMainTimezone().Date; } else { return true; } }, new Error.DomainError(RecordResignation_Messages.ResumeDateCannotBeEarlierThanToday)) .TapIf( command.ResignationType == Recruitment.Enrollments.RecordResignation.ResignationType.Permanent, () => Emit(new CandidateResignedPermanently( recordingCoordinatorID: recordingCoordinator.Id, communicationChannel: command.CommunicationChannel, resignationReason: command.ResignationReason ?? string.Empty, additionalNotes: command.AdditionalNotes ?? string.Empty))) .TapIf( command.ResignationType == Recruitment.Enrollments.RecordResignation.ResignationType.Temporary, () => Emit(new CandidateResignedTemporarily( recordingCoordinatorID: recordingCoordinator.Id, communicationChannel: command.CommunicationChannel, resignationReason: command.ResignationReason ?? string.Empty, additionalNotes: command.AdditionalNotes ?? string.Empty, resumeDate: command.ResumeDate)))); }
public async Task <IActionResult> RecordResignation(RecordResignation.Command command) { var result = await _engine.Execute(command); return(result.MatchToActionResult(success => Ok())); }