public IActionResult CreateMedia([FromBody] Media media) { _mediaRepository.Add(media); var newMedia = _mediaRepository.GetByTitle(media.MediaName); return(CreatedAtAction(nameof(GetMediaById), new { id = newMedia.MediaId }, newMedia)); }
public void MediaRepository_GetByUserName_ThrowsExceptionWhenUserNameNotFound() { //arrange IMediaRepo mediaRepo = GetInMemoryMediaRepository(); //act mediaRepo.Add(media); //assert Assert.ThrowsAny <ArgumentNullException>(() => mediaRepo.GetByTitle("NotExistingTitle")); }
public void MediaRepository_GetById_ThrowsExceptionWhenIdNotFound() { //arrange IMediaRepo mediaRepo = GetInMemoryMediaRepository(); //act mediaRepo.Add(media); //assert Assert.ThrowsAny <ArgumentNullException>(() => mediaRepo.GetById(2)); }
public void MediaRepository_Update_ThrowsExceptionWhenUserIdNotFound() { //arrange IMediaRepo mediaRepo = GetInMemoryMediaRepository(); //act mediaRepo.Add(media); Media saveMedia = mediaRepo.GetByTitle(media.MediaName); saveMedia.MediaId = 0; //assert Assert.ThrowsAny <ArgumentNullException>(() => mediaRepo.Update(saveMedia)); }
public void MediaRepository_Update_UpdatesMedia() { //arrange IMediaRepo mediaRepo = GetInMemoryMediaRepository(); //act mediaRepo.Add(media); Media saveMedia = mediaRepo.GetByTitle(media.MediaName); saveMedia.Composer = "update composer"; mediaRepo.Update(saveMedia); Media updateMedia = mediaRepo.GetByTitle(media.MediaName); //assert Assert.Equal("update composer", updateMedia.Composer); }
public void MediaRepository_GetById_GetsMedia() { //arrange IMediaRepo mediaRepo = GetInMemoryMediaRepository(); //act mediaRepo.Add(media); Media saveMedia = mediaRepo.GetById(1); //Assert Assert.Equal(1, saveMedia.MediaId); Assert.Equal("test media name", saveMedia.MediaName); Assert.Equal("test composer", saveMedia.Composer); Assert.Equal("hello, this is a test description", saveMedia.Description); Assert.Equal(9, saveMedia.Rating); Assert.Equal("https://upload.wikimedia.org/wikipedia/en/8/8a/The_Avengers_%282012_film%29_poster.jpg", saveMedia.MediaUrl); Assert.True(saveMedia.Approved); }
public bool Add(Media data) { return(mediaRepo.Add(data)); }