Exemplo n.º 1
0
        public async Task <ActionResult <NoteDto> > PutAsync(string id, NoteDto noteDto)
        {
            var command = new PostPutNote.Command(noteDto, id);
            var result  = await _mediator.Send(command);

            return(CreatedAtAction(nameof(GetByIdAsync), new { result.Id }, result));
        }
Exemplo n.º 2
0
        public async Task PutPatient()
        {
            // Arrange
            var command = new PostPutNote.Command(_note);
            var sut     = new PostPutNote.Handler(_noteService);

            // Act
            var response = await sut.Handle(command, new CancellationToken());

            // Assert
            response.Id.Should().Be("99");
        }
        public async Task PostAsync_ShouldAddEntity()
        {
            // Arrange
            var noteDto = new NoteDto {
                Id = "Unit Test"
            };

            _mediator.Send(Arg.Any <PostPutNote.Command>()).Returns(noteDto);

            // Act
            var command      = new PostPutNote.Command(noteDto);
            var actionResult = await _sut.PostAsync(new NoteDto());

            // Assert
            if (actionResult.Result is CreatedAtActionResult result)
            {
                result.StatusCode.Should().Be(201);
                if (result.Value is NoteDto value)
                {
                    value.Id.Should().Be("Unit Test");
                }
            }
        }
        public async Task PutAsync_ShouldUpdateEntity()
        {
            // Arrange
            var noteDto = new NoteDto {
                Id = "99"
            };

            _mediator.Send(Arg.Any <PostPutNote.Command>()).Returns(noteDto);

            // Act
            var command      = new PostPutNote.Command(noteDto);
            var actionResult = await _sut.PutAsync("99", noteDto);

            // Assert
            if (actionResult.Result is OkObjectResult result)
            {
                result.StatusCode.Should().Be(200);
                if (result.Value is NoteDto value)
                {
                    value.Id.Should().Be("99");
                }
            }
        }