예제 #1
0
        public async void AddTreatmentSession_ValidInputViolatingBusinessRules_ShouldReturnErrorResult()
        {
            // Arrange
            var input = new TreatmentSessionInput()
            {
                TreatmentReferenceId  = Treatments.First().ReferenceId,
                PatientReferenceId    = Patient.ReferenceId,
                DentalTeamReferenceId = DentalTeam.ReferenceId,
                Start  = DateTimeOffset.UtcNow,
                Status = "Requested"
            };

            input = input
                    with
            {
                End = input.Start.Value.AddHours(1)
            };

            // Act
            await Sut.Send(input, default);

            var result = await Sut.Send(input, default);

            // Assert
            var allValidationMessages = ServiceProvider.GetRequiredService <IStringLocalizer <TreatmentSessionBusinessValidator> >()
                                        .GetAllStrings()
                                        .Select(ls => ls.Value);
            var allUniqueValidationMessages = new HashSet <string>(allValidationMessages);

            result.Errors
            .Cast <IValidationError>()
            .SelectMany(ve => ve.Errors)
            .Should()
            .OnlyContain(errMsg => allUniqueValidationMessages.Contains(errMsg));
        }
예제 #2
0
        public async void AddTreatmentSession_ValidInput_ShouldReturnSuccessfullMessage()
        {
            // Arrange
            var input = new TreatmentSessionInput()
            {
                TreatmentReferenceId  = Treatments.First().ReferenceId,
                PatientReferenceId    = Patient.ReferenceId,
                DentalTeamReferenceId = DentalTeam.ReferenceId,
                Start  = DateTimeOffset.UtcNow,
                Status = "Requested"
            };

            input = input
                    with
            {
                End = input.Start.Value.AddHours(1)
            };

            // Act
            var result = await Sut.Send(input, default);

            var messageOutput = result.Value;

            // Assert
            messageOutput.Message.Should().BeEquivalentTo("Treatment Session successfully created.");
        }
        public async Task <IResult <IMessageOutput> > Handle(TreatmentSessionInput input, CancellationToken cancellationToken)
        {
            var validationResult = Validator.Validate(input);

            if (validationResult.Errors.Count > 0)
            {
                return(new Result <IMessageOutput>(validationResult.Errors));
            }

            var patient = await PatientRepository.SingleOrDefaultAsync(p => p.ReferenceId == input.PatientReferenceId, cancellationToken);

            var dentalTeam = await DentalTeamRepository.SingleOrDefaultAsync(dt => dt.ReferenceId == input.DentalTeamReferenceId, cancellationToken);

            var treatment = await TreatmentRepository.SingleOrDefaultAsync(t => t.ReferenceId == input.TreatmentReferenceId, cancellationToken);

            var treatmentSession = new TreatmentSession()
            {
                PatientId    = patient.Id,
                DentalTeamId = dentalTeam.Id,
                TreatmentId  = treatment.Id,
                Start        = input.Start.Value,
                End          = input.End.Value
            };

            await TreatmentSessionRepository.AddAsync(treatmentSession, cancellationToken);

            await UoW.SaveAsync(cancellationToken);

            return(new Result <IMessageOutput>(
                       value: new MessageOutput("Treatment Session successfully created."),
                       type: ResultType.Created
                       ));
        }
예제 #4
0
        public async void AddTreatmentSession_InvalidInput_ShouldReturnErrorResult()
        {
            // Arrange
            var input = new TreatmentSessionInput();

            // Act
            var result = await Sut.Send(input, default);

            // Assert
            var allValidationMessages = ServiceProvider.GetRequiredService <IStringLocalizer <TreatmentSessionValidator> >()
                                        .GetAllStrings()
                                        .Union(ServiceProvider.GetRequiredService <IStringLocalizer <PeriodValidator> >().GetAllStrings())
                                        .Select(ls => ls.Value);
            var allUniqueValidationMessages = new HashSet <string>(allValidationMessages);

            result.Errors
            .Cast <IValidationError>()
            .SelectMany(ve => ve.Errors)
            .Should()
            .OnlyContain(errMsg => allUniqueValidationMessages.Contains(errMsg));
        }
예제 #5
0
        public async Task <IActionResult> PutAsync(TreatmentSessionInput input)
        {
            var result = await UpdateTreatmentSessionCommand.Value.ExecuteAsync(input);

            return(PresentResult(result));
        }
예제 #6
0
        public async Task <IActionResult> PostAsync(TreatmentSessionInput input, CancellationToken cancellationToken = default)
        {
            var result = await Mediator.Value.Send(input, cancellationToken);

            return(PresentResult(result));
        }