public async Task If_school_signed_permanent_agreement__result_has_HasSignedPermanentAgreement() { Guid schoolId; 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 RecordAgreementSigned.Command() { SchoolId = schoolId, Duration = RecordAgreementSigned.AgreementDuration.Permanent, ScannedDocument = new byte[] { 0x00 }, ScannedDocumentContentType = "image/jpeg", ScannedDocumentExtension = ".jpg" }; 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", HasSignedPermanentAgreement = true }, options => options.Excluding(x => x.Events).Excluding(x => x.ContactData)); } }
public async Task <Result <Guid, Error> > Handle(RecordAgreementSigned.Command request, CancellationToken cancellationToken) { var user = await _userAccessor.GetUser(); var today = _clock.GetTodayDate(); var result = await _aggregateStore.Update <SchoolAggregate, SchoolId, Result <Guid, Error> >( SchoolId.With(request.SchoolId), CommandId.New, (aggregate) => aggregate.RecordAgreementSigned(request, user, today), cancellationToken); return(result.Unwrap()); }
public Result <Guid, Error> RecordAgreementSigned(RecordAgreementSigned.Command command, ApplicationUser recordingUser, LocalDate today) { Guard.Against.Null(command, nameof(command)); Guard.Against.Null(recordingUser, nameof(recordingUser)); ValidateIdMatchOrThrow(command.SchoolId); var agreementId = Guid.NewGuid(); return(Validate(new RecordAgreementSigned.Validator(), command) .Ensure( _ => this.IsNew == false, new Error.ResourceNotFound(Messages.School_not_found)) .Ensure( _ => command.AgreementEndDate == null || command.AgreementEndDate > today, new Error.DomainError(RecordAgreementSigned_Messages.AgreementEndDate_must_be_in_the_future)) .TapIf( command.AgreementEndDate.HasValue == false, () => Emit(new PermanentAgreementSigned( id: agreementId, scannedDocument: command.ScannedDocument, scannedDocumentExtension: command.ScannedDocumentExtension, scannedDocumentContentType: command.ScannedDocumentContentType, recordingUserId: recordingUser.Id, additionalNotes: command.AdditionalNotes)) ) .TapIf( command.AgreementEndDate.HasValue, () => Emit(new FixedTermAgreementSigned( id: agreementId, scannedDocument: command.ScannedDocument, scannedDocumentExtension: command.ScannedDocumentExtension, scannedDocumentContentType: command.ScannedDocumentContentType, agreementEndDate: command.AgreementEndDate ?? throw new InvalidOperationException($"{command.AgreementEndDate} has no value"), recordingUserId: recordingUser.Id, additionalNotes: command.AdditionalNotes)) ) .Map(_ => agreementId)); }
public async Task <IActionResult> RecordAgreementSigned(RecordAgreementSigned.Command command) { var result = await _engine.Execute(command); return(result.MatchToActionResult(success => Ok(success))); }