// Primer ejemplo
        static void FirtExample()
        {
            var authorService = new AuthorService();
            var albumService  = new AlbumService();
            var songService   = new SongService();

            var album = new Album
            {
                Title  = "The Trooper",
                Author = new Author
                {
                    Name = "Iron Maiden"
                }
            };

            albumService.Add(album);

            songService.Add(new Song
            {
                Description = "Es una canción escrita por el bajista Steve Harris publicado el 20 de junio de 1983",
                Title       = "The Trooper",
                Duration    = TimeSpan.FromSeconds(250),
                AlbumId     = album.Id
            });
        }
        // Validar restricción
        static void SecondExample()
        {
            var songService = new SongService();

            songService.Add(new Song
            {
                Description = "The Unforgiven es el nombre que se le da a las tres canciones (power ballad) homónimas de thrash metal, que han sido incluidas en los álbumes Metallica.",
                Title       = "The unforgiven",
                Duration    = TimeSpan.FromSeconds(250),
                AlbumId     = 2
            });

            songService.Add(new Song
            {
                Description = "Don't Tread on Me es la sexta canción del quinto álbum de Metallica, titulado Metallica, aunque también puede ser conocido como The Black Album.",
                Title       = "Don't Tread on Me",
                Duration    = TimeSpan.FromSeconds(250),
                AlbumId     = 2
            });
        }
        // Métodos crud
        static void ThirdExample()
        {
            var songService = new SongService();

            var newEntry = new Song
            {
                Description = "Excelente canción de Metallica",
                Title       = "Nothing Else Matter",
                Duration    = TimeSpan.FromSeconds(350),
                AlbumId     = 2
            };

            songService.Add(newEntry);

            newEntry.Title = "One";
            songService.Update(newEntry);

            songService.Delete(newEntry.Id);
        }
        public void AddSongTest()
        {
            Mock <ISongRepository>  songRepositoryMock  = new Mock <ISongRepository>();
            Mock <IAlbumRepository> albumRepositoryMock = new Mock <IAlbumRepository>();

            songRepositoryMock.Setup(s => s.Save(It.IsAny <Song>())).Callback <Song>(s => songs.Add(s)).Returns <Song>(s => s);
            albumRepositoryMock.Setup(a => a.FindOne(1)).Returns(new Album {
                Id = 1, Name = "TestAlbum"
            });

            ISongService songService = new SongService(songRepositoryMock.Object, albumRepositoryMock.Object);

            Song song = new Song {
                Id = 1, Album = new Album {
                    Id = 1
                }, Title = "TestSong"
            };

            song = songService.Add(song);
            Assert.AreEqual(song.Album.Name, "TestAlbum");
        }
Beispiel #5
0
        public async Task AddItemExecute(VideoInformation o)
        {
            try
            {
                if (o == null)
                {
                    return;
                }

                await ExecuteBusyAction(async() =>
                {
                    var song = new Song(o, UserService.Get().Id);
                    await SongService.Add(song);

                    await CloseExecute();
                });
            }
            catch (System.Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }