public void EditPublisher_ValidMethodParameter_True() { //assign Publisher existedEntity = new Publisher() { Id = 1, Name = "Ubisoft" }; EditPublisherDto newPublisher = new EditPublisherDto() { Id = 1, Name = "Sega" }; publisherRepositoryMoq.Setup((p) => p.GetSingleAsync(It.IsAny <Expression <Func <Publisher, bool> > >())) .Returns(Task.FromResult(existedEntity)); mapperMoq.Setup(p => p.Map(newPublisher, existedEntity)) .Returns(new Publisher() { Id = 1, Name = "Sega" }); //act service.EditPublisher(newPublisher); //assign unitofworkMoq.Verify(p => p.CommitAsync(), Times.Once); publisherRepositoryMoq.Verify(p => p.Update(It.IsAny <Publisher>()), Times.Once); }
public async Task <IActionResult> Put(int id, [FromBody] PublisherCreateModel value) { EditPublisherDto editedPubliisher = new EditPublisherDto() { Id = id, Name = value.Name, }; await publisherService.EditPublisher(editedPubliisher); return(StatusCode((int)HttpStatusCode.OK, "Publisher was updated")); }
public async Task EditPublisher(EditPublisherDto genreDto) { using (unitOfWork) { var publisher = await unitOfWork.PublisherRepository.GetSingleAsync(p => p.Id == genreDto.Id); if (publisher == null) { throw new ArgumentException("Invalid publisher Id"); } publisher = mapper.Map(genreDto, publisher); unitOfWork.PublisherRepository.Update(publisher); await unitOfWork.CommitAsync(); } }
public void EditPublisher_EntityWithInvalidID_ThrowsArgumentException() { //assign Publisher returnedNUllEntity = null; EditPublisherDto newPublisher = new EditPublisherDto() { Id = 1, Name = "Sega" }; publisherRepositoryMoq.Setup((p) => p.GetSingleAsync(It.IsAny <Expression <Func <Publisher, bool> > >())) .Returns(Task.FromResult(returnedNUllEntity)); //act Assert.ThrowsAsync <ArgumentException>(async() => { await service.EditPublisher(newPublisher); }); //assign unitofworkMoq.Verify(p => p.CommitAsync(), Times.Never); publisherRepositoryMoq.Verify(p => p.Update(It.IsAny <Publisher>()), Times.Never); }