Exemplo n.º 1
0
        public async Task ShouldReturnNotFound_WhenIdIdNotFound()
        {
            // Arrange
            var command = new UpdatePerson.Command().Valid(Guid.NewGuid());

            // Act
            var result = await Client.PutAsJsonAsync($"api/v1/person/{command.Id}", command);

            // Assert
            result.StatusCode.Should().Be(StatusCodes.Status404NotFound);
        }
Exemplo n.º 2
0
        public async Task ShouldReturnBadRequest_WhenAgeIsMissing()
        {
            // Arrange
            var command = new UpdatePerson.Command().Invalid(Guid.NewGuid());

            // Act
            var result = await Client.PutAsJsonAsync($"api/v1/person/{command.Id}", command);

            // Assert
            result.StatusCode.Should().Be(StatusCodes.Status400BadRequest);
        }
Exemplo n.º 3
0
        public async Task <ActionResult <UpdatePerson.Result> > Post(Guid id,
                                                                     [FromBody]
                                                                     UpdatePerson.Command command)
        {
            if (id != command.Id)
            {
                return(BadRequest("Ids not matching"));
            }

            var result = await _mediator.Send(command);

            return(result);
        }
Exemplo n.º 4
0
        public async Task ShouldReturnUpdatedPerson_WhenCommandIsValid()
        {
            // Arrange
            var person = await Context.SeedPersonAsync();

            var command = new UpdatePerson.Command().Valid(person.Id);

            // Act
            var result = await _uut.Handle(command, CancellationToken.None);

            // Assert
            result.Person.Should().BeEquivalentTo(command);
        }
Exemplo n.º 5
0
        public async Task ShouldReturnOk_WhenRequestIsValid()
        {
            // Arrange
            var person  = (await Mediator.Send(new CreatePerson.Command().Valid())).Person;
            var command = new UpdatePerson.Command().Valid(person.Id);

            // Act
            var result = await Client.PutAsJsonAsync($"api/v1/person/{command.Id}", command);

            var content = await result.Content.ReadAsAsync <UpdatePerson.Result>();

            // Assert
            result.StatusCode.Should().Be(StatusCodes.Status200OK);
            content.Person.Should().BeEquivalentTo(command);
        }
 public static UpdatePerson.Command Valid(this UpdatePerson.Command command, Guid id)
 {
     return(new UpdatePerson.Command {
         Id = id, Name = "John Doe", Age = 42
     });
 }