public async Task PostPatient() { // Arrange var command = new PostPatient.Command(_patient); var sut = new PostPatient.Handler(_patientService); // Act var response = await sut.Handle(command, new CancellationToken()); // Assert response.Id.Should().Be(99); }
public async Task PostAsync_ShouldAddEntity(bool body) { // Arrange var patientDto = new PatientDto { Id = 99 }; _mediator.Send(Arg.Any <PostPatient.Command>()).Returns(patientDto); // Act var command = new PostPatient.Command(patientDto); var actionResult = body ? await _sut.PostAsync(command) : await _sut.PostBodyAsync(command); // Assert if (actionResult.Result is CreatedAtActionResult result) { result.StatusCode.Should().Be(201); if (result.Value is PatientDto value) { value.Id.Should().Be(99); } } }
public async Task <ActionResult <PatientDto> > PostBodyAsync([FromBody] PostPatient.Command command) { var result = await _mediator.Send(command); return(CreatedAtAction(nameof(GetByIdAsync), new { result.Id }, result)); }