Пример #1
0
        private static void TestSongService()
        {
            List <int> list = new List <int>();

            songService   = Container.Resolve <ISongService>();
            clientService = Container.Resolve <IClientService>();

            //Create
            songService.CreateSong(new SongDTO
            {
                Name       = "Hit The Floor",
                AlbumID    = albumID,
                CreatorID  = clientID,
                Duration   = new TimeSpan(0, 0, 3, 30),
                IsOfficial = true,
            });
            songService.CreateSong(new SongDTO
            {
                Name       = "4 Words",
                AlbumID    = albumID,
                CreatorID  = clientID,
                Duration   = new TimeSpan(0, 0, 3, 43),
                IsOfficial = true,
            });
            songService.CreateSong(new SongDTO
            {
                Name       = "All These Things I Hate",
                AlbumID    = albumID,
                CreatorID  = clientID2,
                Duration   = new TimeSpan(0, 0, 3, 45),
                IsOfficial = true,
            });


            //GetSongIdByName
            songID = songService.GetSongIdByName("Hit The Floor");
            int wordsID = songService.GetSongIdByName("4 Words");

            songID2 = songService.GetSongIdByName("All These Things I Hate");
            list.Add(songID);
            list.Add(wordsID);
            list.Add(songID2);
            Console.WriteLine(list.Count() == 3 ? "ClientService - GetSongIdByName - OK" : "ClientService - GetSongIdByName - FAIL");

            //GetSongById
            SongDTO floor  = songService.GetSong(songID);
            SongDTO words4 = songService.GetSong(wordsID);
            SongDTO hate   = songService.GetSong(songID2);

            Console.WriteLine(floor.Name == "Hit The Floor" ? "SongService - GetSongById - OK" : "SongService - GetSongById - FAIL");

            albumService = Container.Resolve <IAlbumService>();

            //AddSong
            songService.AddSong(floor);
            songService.AddSong(words4);
            songService.AddSong(hate);
            AlbumDTO album = albumService.GetAlbum(albumID);

            Console.WriteLine(album.SongIDs.Contains(songID) ?
                              "SongService - AddSong - OK" : "SongService - AddSong - FAIL");

            //GetAlbumOfSong
            AlbumDTO album2 = songService.GetAlbumOfSong(songID);

            Console.WriteLine(album2.ID == albumID ?
                              "SongService - GetAlbumOfSong - OK" : "SongService - GetAlbumOfSong - FAIL");

            //TestAlbumServisGetAllSongs
            Console.WriteLine(album.SongIDs.Count() == 3 ?
                              "AlbumService - TestAlbumServisGetAllSongs - OK" : "AlbumService - TestAlbumServisGetAllSongs - FAIL");

            ////ListAllSongs
            //var songs = songService.ListAllSongs(new SongFilter { AlbumID = albumID }, 1);
            //Console.WriteLine(songs.TotalResultCount == 3 ? "SongService - TestListAllSongs - OK" : "SongService - TestListAllSongs - FAIL");

            //ListAllSongss02
            var songs2 = songService.ListAllSongs();

            Console.WriteLine(songs2.Count() == 3 ? "SongService - ListAllSongss02 - OK" : "SongService - ListAllSongss02 - FAIL");

            //EditSong
            words4.Name = "Four Words";
            songService.EditSong(words4, albumID, words4.ReviewIDs);
            SongDTO words4FromDB = songService.GetSong(words4.ID);

            Console.WriteLine(words4FromDB.Name == "Four Words" ? "SongService - TestEditSong - OK" : "SongService - TestEditSong - FAIL");

            //DeleteSong
            songService.DeleteSong(wordsID);
            try {
                SongDTO wordsFromDB = songService.GetSong(wordsID);
                Console.WriteLine("SongService - TestDeleteSong - FAIL");
            }
            catch (NullReferenceException)
            {
                Console.WriteLine("SongService - TestDeleteSong - OK");
            }

            //GetCreator
            ClientDTO creator = genreService.GetCreator(floor.ID);

            Console.WriteLine(creator.ID == clientID ? "SongService - GetCreator - OK" : "SongService - GetCreator - FAIL");
        }