public void ShouldReturnEmptyListWhenGetMediaByAlbumFoundNoRecords() { _mediaRepository = new Mock<IMediaRepository>(); _mediaRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Media, bool>>>(), true)) .Returns(new List<Media>()); _albumRepository = new Mock<IAlbumRepository>(); _imageHelper = new Mock<IImageHelper>(); _configurationHelper = new Mock<IConfigurationHelper>(); _fileHelper = new Mock<IFileHelper>(); _mediaLogic = new MediaLogic(_mediaRepository.Object, _albumRepository.Object, _imageHelper.Object, _configurationHelper.Object, _fileHelper.Object); var result = _mediaLogic.GetByAlbum(1); Assert.NotNull(result); Assert.AreEqual(0, result.Count); }
public void ShouldThrowExceptionWhenGetMediaByAlbumFails() { _mediaRepository = new Mock<IMediaRepository>(); _mediaRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Media, bool>>>(), true)) .Throws(new Exception()); _albumRepository = new Mock<IAlbumRepository>(); _imageHelper = new Mock<IImageHelper>(); _configurationHelper = new Mock<IConfigurationHelper>(); _fileHelper = new Mock<IFileHelper>(); _mediaLogic = new MediaLogic(_mediaRepository.Object, _albumRepository.Object, _imageHelper.Object, _configurationHelper.Object, _fileHelper.Object); Assert.Throws<BlogException>(() => _mediaLogic.GetByAlbum(1)); }
public void ShouldGetMediaByAlbum() { var media = _media.Where(a => a.AlbumId == 1).ToList(); _mediaRepository = new Mock<IMediaRepository>(); _mediaRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Media, bool>>>(), true)) .Returns(media); _albumRepository = new Mock<IAlbumRepository>(); _imageHelper = new Mock<IImageHelper>(); _configurationHelper = new Mock<IConfigurationHelper>(); _fileHelper = new Mock<IFileHelper>(); _mediaLogic = new MediaLogic(_mediaRepository.Object, _albumRepository.Object, _imageHelper.Object, _configurationHelper.Object, _fileHelper.Object); var result = _mediaLogic.GetByAlbum(1); Assert.AreEqual(2, result.Count); Assert.AreEqual(1, result[0].AlbumId); Assert.AreEqual(1, result[1].AlbumId); }