public async Task GivenUserIdIsNotAuthorizedUser_ReturnUnauthorizedStatusCode() { var client = await _factory.GetAuthenticatedClientAsync("Moderator"); var command = new UpdatePetCommand { Name = "Wau", Age = 5, Gender = Domain.Enums.Gender.Male, Weight = 0.2, Height = 0.3, IsSterilized = true, Description = "Something about", PhotoCode = "", CategoryId = 1, UserId = 4 }; var content = ClientUtilities.GetRequestContent(command); var validPetId = 1; var response = await client.PutAsync($"/api/pets/{validPetId}", content); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); }
public void Shoud_have_error_when_name_is_empty() { var validator = new UpdatePetCommandValidator(); var model = new UpdatePetCommand(string.Empty, Guid.NewGuid()); validator.Validate(model).IsValid.Should().BeFalse(); }
public async Task ShouldUpdate_A_Pet() { var name = "Vader"; var request = new UpdatePetCommand(name, Guid.NewGuid()); var mapper = PetShopMappingConfiguration.GetPetShopMappings(); var mockRepository = new Mock <IPetRepository>(); mockRepository.Setup(p => p.Update(It.Is <Pet>(c => c.Name == name))); var handler = new UpdatePetCommandHandler(mapper, mockRepository.Object); var result = await handler.Handle(request, CancellationToken.None); result.Message.Should().BeEquivalentTo("Pet Updated"); mockRepository.Verify(m => m.Update(It.IsAny <Pet>()), Times.Once()); }
public async Task <ActionResult> Update(int id, [FromBody] UpdatePetCommand command) { try { if (command.Id == 0) { command.Id = id; } await Mediator.Send(command); return(Ok()); } catch (UnauthorizedException ex) { return(Unauthorized(ex.Message)); } catch (NotFoundException ex) { return(NotFound(ex.Message)); } }