Example #1
0
        public IActionResult GetMediaById(int id)
        {
            var currentMedia = _mediaRepository.GetById(id);

            if (currentMedia == null)
            {
                return(NotFound());
            }
            else
            {
                return(Ok(_mediaRepository.GetById(id)));
            }
        }
        public void MediaRepository_GetById_ThrowsExceptionWhenIdNotFound()
        {
            //arrange
            IMediaRepo mediaRepo = GetInMemoryMediaRepository();

            //act
            mediaRepo.Add(media);

            //assert
            Assert.ThrowsAny <ArgumentNullException>(() => mediaRepo.GetById(2));
        }
        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);
        }