public async Task Patch_ThrowsValidationException_ReturnsBadRequestResult() { var mock = AutoMock.GetLoose(); var artist = new ArtistDetailsDto(); mock.Mock <IArtistService>().Setup(x => x.UpdateArtistAsync(1, artist)).Throws <ValidationException>(); mock.Mock <IArtistService>().Setup(x => x.DetailsAsync(1)).Returns(Task.FromResult(artist)); var controller = mock.Create <ArtistController>(); var result = await controller.Patch(1, new JsonPatchDocument <ArtistDetailsDto>()); Assert.IsType <BadRequestObjectResult>(result); }
public async Task Post_AddsArtist() { var mock = AutoMock.GetLoose(); var artist = new ArtistDetailsDto() { FirstName = "Adam", LastName = "Test" }; var controller = mock.Create <ArtistController>(); var result = await controller.Post(artist); Assert.IsType <CreatedResult>(result); mock.Mock <IArtistService>().Verify(x => x.AddArtistAsync(artist)); }
public async Task Put_UpdatesArtist() { var mock = AutoMock.GetLoose(); var artist = new ArtistDetailsDto() { FirstName = "Adam", LastName = "Test" }; var controller = mock.Create <ArtistController>(); var result = await controller.Put(1, artist); Assert.IsType <CreatedResult>(result); mock.Mock <IArtistService>().Verify(x => x.UpdateArtistAsync(1, artist), Times.Once); }
public async Task <ActionResult> Post([FromBody] ArtistDetailsDto artist) { try { await _artistService.AddArtistAsync(artist).ConfigureAwait(true); } catch (ValidationException) { return(ValidationProblem()); } return(Created(nameof(Get), null)); }
public async Task Post_InvalidArtist_ReturnsBadRequestResult() { var mock = AutoMock.GetLoose(); var artist = new ArtistDetailsDto() { FirstName = "", LastName = "Test" }; var controller = mock.Create <ArtistController>(); mock.Mock <IArtistService>().Setup(x => x.AddArtistAsync(artist)).Throws <ValidationException>(); var result = await controller.Post(artist); Assert.IsType <BadRequestObjectResult>(result); }
public async Task Put_ArtistNotFound_ReturnsNotFoundResult() { var mock = AutoMock.GetLoose(); var artist = new ArtistDetailsDto() { FirstName = "Adam", LastName = "Test" }; mock.Mock <IArtistService>().Setup(x => x.UpdateArtistAsync(1, artist)).Throws <NullReferenceException>(); var controller = mock.Create <ArtistController>(); var result = await controller.Put(1, artist); Assert.IsType <NotFoundResult>(result); }
public async Task Patch_ValidCall() { var mock = AutoMock.GetLoose(); var artist = new ArtistDetailsDto(); var patch = mock.Create <JsonPatchDocument <ArtistDetailsDto> >(); mock.Mock <IArtistService>().Setup(x => x.DetailsAsync(1)).Returns(Task.FromResult(artist)); var controller = mock.Create <ArtistController>(); var result = await controller.Patch(1, patch); mock.Mock <IArtistService>().Verify(x => x.UpdateArtistAsync(1, artist), Times.Once); Assert.IsType <CreatedResult>(result); }
public async Task GetArtist_ProperId_ReturnsArtist() { var mock = AutoMock.GetLoose(); var artist = new ArtistDetailsDto() { FirstName = "Adam", LastName = "Test" }; mock.Mock <IArtistService>().Setup(x => x.DetailsAsync(1)).Returns(Task.FromResult(artist)); var controller = mock.Create <ArtistController>(); var result = await controller.GetArtist(1); var resultArtist = Assert.IsType <ArtistDetailsDto>(result.Value); Assert.Equal(artist.FirstName, resultArtist.FirstName); Assert.Equal(artist.LastName, resultArtist.LastName); }
public async Task <ActionResult> Put(int id, [FromBody] ArtistDetailsDto artist) { try { await _artistService.UpdateArtistAsync(id, artist).ConfigureAwait(true); } catch (NullReferenceException) { return(NotFound()); } catch (ValidationException ex) { return(ValidationProblem(new ValidationProblemDetails() { Detail = ex.Message })); } return(Created(nameof(GetArtist), id)); }
public static Artist CreateArtist(string displayname, string firstname, string lastname, ArtistDetailsDto artistDetailsDto) { Artist artist = new Artist(displayname, firstname, lastname); artist.CreateArtistDetails(artistDetailsDto.StageName); return(artist); }