public Album AddNewAlbum(Album album) { using (var scope = new TransactionScope()) { if (!DoesArtistExist(album.Artist)) { album.Artist.Id = _artistRepository.CreateArtist(album.Artist); } if (!DoesGenreExist(album.Genre)) { album.Genre.Id = _genreRepository.CreateGenre(album.Genre); } if (!album.TracksCountValid()) return null; var id = _albumRepository.CreateAlbum(album); album.Id = id; scope.Complete(); return album; } }
public int CreateAlbum(Album album) { var insert = @"INSERT INTO dbo.Album VALUES(Name,Year,ArtistId,GenreId) VALUES (@albumName,@year,@artistId,@genreId); SELECT CAST(SCOPE_IDENTITY() as int;"; var albumId = _database.ExecuteScalar<int>(insert, new { albumName = album.AlbumName, year = album.ReleaseYear, artistId = album.Artist.Id, genreId = album.Genre.Id }); foreach (var t in album.Tracks) { CreateTrack(albumId, t); } return albumId; }
public void AddNewAlbumInvalidArtistValidGenreTest() { var album = new Album { AlbumName = "Terrapin Station", Artist = new Artist { ArtistName = "Grateful Dead" }, Genre = new Genre { GenreName = "Rock" }, ReleaseYear = 1977, Tracks = new List<Track>() { new Track {Name = "Estimated Prophet", Number = 1, Length = 5}, new Track {Name = "Dancin' in the Streets", Number = 2, Length = 3}, new Track {Name = "Passenger", Number = 3, Length = 2}, new Track {Name = "Samson and Delilah", Number = 4, Length = 3}, new Track {Name = "Sunrise", Number = 5, Length = 3}, new Track {Name = "Terrapin Station Park 1", Number = 6, Length = 16}, } }; _artistRepository.Setup(f => f.GetArtistByName(It.IsAny<string>())).Returns(new Artist { ArtistName = "Grateful Dead" }); _genreRepository.Setup(f => f.GetGenreByName(It.IsAny<string>())).Throws<Exception>(); _genreRepository.Setup(f => f.CreateGenre(It.IsAny<Genre>())).Returns(98); _albumRepository.Setup(f => f.CreateAlbum(album)).Returns(1); var res = _albumService.AddNewAlbum(album); Assert.NotNull(res); Assert.AreEqual(1,res.Id); Assert.NotNull(res.Genre); Assert.AreEqual(98,res.Genre.Id); }
public void AddNewAlbumValidArtistValidGenreNoTracksTest() { var album = new Album { AlbumName = "Terrapin Station", Artist = new Artist { ArtistName = "Grateful Dead" }, Genre = new Genre { GenreName = "Rock" }, ReleaseYear = 1977, Tracks = new List<Track>() { } }; _artistRepository.Setup(f => f.GetArtistByName(It.IsAny<string>())).Returns(new Artist { ArtistName = "Grateful Dead" }); _genreRepository.Setup(f => f.GetGenreByName(It.IsAny<string>())).Returns(new Genre { GenreName = "Rock" }); _albumRepository.Setup(f => f.CreateAlbum(album)).Returns(1); var res = _albumService.AddNewAlbum(album); Assert.Null(res); }
public Album GetAlbumByName(string name) { var sql = _baseAlbumQuery + " WHERE album.Name=@albumName"; var res = _database.Query(sql, new {albumName = name}).Single(); var album = new Album() { AlbumName = res.AlbumName, ReleaseYear = res.ReleaseYear, Genre = new Genre {GenreName = res.GenreName}, Artist = new Artist {ArtistName = res.ArtistName}, Tracks = GetTracksForAlbum(res.Id) }; return album; }
public IEnumerable <Song> GetAll() { var album1 = new Album { Artist = "Rahman", Name = "Achcham Yenbadhu Madamaiyada", Year = 2016, CoverImage = "Achcham-Enbathu-Madamaiyada.jpg", Language = "Tamil" }; var album2 = new Album { Artist = "Rahman", Name = "Alaipayuthey", Year = 2000, CoverImage = "AlaipayutheyAlbumArt.jpg", Language = "Tamil" }; var album3 = new Album { Artist = "Anirudh Ravichander", Name = "Darbar", Year = 2020, CoverImage = "DarbarAlbumArt.png", Language = "Tamil" }; var song1 = new Song { Id = 1, Title = "Idhu Naal", Singers = "Aditya Rao, Jonita Gandhi", Length = new TimeSpan(0, 3, 29), FileName = "IdhuNaal.mp3", Album = album1 }; var song2 = new Song { Id = 2, Title = "Rasaali", Singers = "Sathya Prakash, Shasha Tirupati", Length = new TimeSpan(0, 5, 38), FileName = "Rasaali.mp3", Album = album1 }; var song3 = new Song { Id = 3, Title = "Alaipayuthey Kanna", Singers = "Kalyani Menon, Harini & Neyveli", Length = new TimeSpan(0, 3, 41), FileName = "Alaipayuthey-Kanna.mp3", Album = album2 }; var song4 = new Song { Id = 4, Title = "Pachchai Nirame", Singers = "Hariharan & Clinton", Length = new TimeSpan(0, 5, 58), FileName = "Pachchai-Nirame.mp3", Album = album2 }; var song5 = new Song { Id = 5, Title = "Endrendrum Punnagai", Singers = "Praveen, Shankar, Clinton & Srinivas", Length = new TimeSpan(0, 3, 57), FileName = "Endrendrum-Punnagai.mp3", Album = album2 }; var song6 = new Song { Id = 6, Title = "Thalaivar Theme", Singers = "Anirudh Ravichander", Length = new TimeSpan(0, 0, 43), FileName = "ThalaivarThemeSong.mp3", Album = album3 }; var song7 = new Song { Id = 7, Title = "Chumma Kizhi", Singers = "S. P. Balasubrahmanyam & Anirudh Ravichander", Length = new TimeSpan(0, 3, 50), FileName = "ChummaKizhi.mp3", Album = album3 }; var song8 = new Song { Id = 8, Title = "Thani Vazhi", Singers = "Rap By Yogi B, Anirudh Ravichander & Shakthisree", Length = new TimeSpan(0, 3, 27), FileName = "ThaniVazhi.mp3", Album = album3 }; return(new List <Song> { song1, song2, song3, song4, song5, song6, song7, song8 }); }