public void CallSongModifyServiceMethodUpdateSongOnce_WhenInvoked()
        {
            // Arrange
            var songService       = new Mock <ISongService>();
            var userService       = new Mock <IUserService>();
            var artistService     = new Mock <IArtistService>();
            var albumService      = new Mock <IAlbumService>();
            var genreService      = new Mock <IGenreService>();
            var songModifyService = new Mock <ISongModifyService>();

            songModifyService.Setup(x => x.UpdateSong(
                                        It.IsAny <Guid>(),
                                        It.IsAny <string>(),
                                        It.IsAny <string>(),
                                        It.IsAny <string>(),
                                        It.IsAny <int?>(),
                                        It.IsAny <ICollection <string> >(),
                                        It.IsAny <string>(),
                                        It.IsAny <string>(),
                                        It.IsAny <string>()));

            var sut = new SongController(
                songService.Object,
                userService.Object,
                artistService.Object,
                albumService.Object,
                genreService.Object,
                songModifyService.Object);

            var model = new SongViewModel()
            {
                Id       = Guid.NewGuid(),
                Title    = "Title",
                Artist   = "Artist",
                Album    = "Album",
                Duration = 5,
                Genres   = new List <string>()
                {
                    "Genre"
                },
                Lyrics   = "Lyrics",
                VideoUrl = "VideoUrl",
                CoverUrl = "CoverUrl"
            };

            // Act
            sut.EditSong(model);

            // Assert
            songModifyService.Verify(x => x.UpdateSong(
                                         It.IsAny <Guid>(),
                                         It.IsAny <string>(),
                                         It.IsAny <string>(),
                                         It.IsAny <string>(),
                                         It.IsAny <int?>(),
                                         It.IsAny <ICollection <string> >(),
                                         It.IsAny <string>(),
                                         It.IsAny <string>(),
                                         It.IsAny <string>()), Times.Once);
        }
示例#2
0
        public void CallAlbumServiceMethodGetAlbumsOnce_WhenInvoked()
        {
            // Arrange
            var songService       = new Mock <ISongService>();
            var userService       = new Mock <IUserService>();
            var artistService     = new Mock <IArtistService>();
            var albumService      = new Mock <IAlbumService>();
            var genreService      = new Mock <IGenreService>();
            var songModifyService = new Mock <ISongModifyService>();

            var id     = Guid.NewGuid();
            var artist = new Artist()
            {
                Name = "Artist Name"
            };
            var album = new Album()
            {
                Title = "Album Title"
            };

            var songCollection = new List <Song>()
            {
                new Song()
                {
                    Id       = id,
                    Title    = "Song Title",
                    Album    = album,
                    Artist   = artist,
                    Duration = 5,
                    Genres   = new List <Genre>()
                    {
                        new Genre()
                        {
                            Name = "Genre Name"
                        }
                    },
                    Lyrics   = "Some Lyrics",
                    VideoUrl = "VideoUrl"
                }
            };

            var artistCollection = new List <Artist>()
            {
                artist
            };

            var albumCollection = new List <Album>()
            {
                album
            };

            albumService.Setup(x => x.GetAlbums()).Returns(() => albumCollection.AsQueryable());
            artistService.Setup(x => x.GetArtists()).Returns(() => artistCollection.AsQueryable());
            songService.Setup(x => x.GetSongs()).Returns(() => songCollection.AsQueryable());
            userService.Setup(x => x.AddFavoriteSong(It.IsAny <Song>(), It.IsAny <string>()));

            var sut = new SongController(
                songService.Object,
                userService.Object,
                artistService.Object,
                albumService.Object,
                genreService.Object,
                songModifyService.Object);

            // Act
            sut.EditSong(id);

            // Assert
            albumService.Verify(x => x.GetAlbums(), Times.Once);
        }