public override async Task <bool> AlbumAddAsync(Album album) { // Map album to db model DBModels.Album dbAlbum = autoMapper.Map <DBModels.Album>(album); // Add new album to database int recordsChanged; try { recordsChanged = await repository.AlbumAddAsync(dbAlbum); } catch { recordsChanged = 0; } return(recordsChanged > 0); }
public override async Task <bool> AlbumUpdateAsync(Album album) { // Map album to db model DBModels.Album dbAlbum = autoMapper.Map <DBModels.Album>(album); // Update album int recordsChanged; try { recordsChanged = await repository.AlbumUpdateAsync(dbAlbum); } catch { recordsChanged = 0; } return(recordsChanged > -1); }
public async Task AlbumGetByIDAsync_ReturnsItem() { DBModels.Album dbAlbum = new DBModels.Album { ArtistID = 1, AlbumID = 1 }; Mock <MusicDemoRepository> mockRepo = new Mock <MusicDemoRepository>(null); mockRepo.Setup(m => m.AlbumGetByIDAsync(It.IsAny <int>(), It.IsAny <int>())).ReturnsAsync(dbAlbum); DBBackendProvider backend = new DBBackendProvider(autoMapper, mockRepo.Object); Album album = await backend.AlbumGetByIDAsync(1, 1); Assert.IsNotNull(album); Assert.AreEqual(1, album.ArtistID); Assert.AreEqual(1, album.AlbumID); }