public void Playlist_ID_can_be_parsed_from_a_URL_string(string playlistUrl, string expectedPlaylistId)
    {
        // Act
        var parsed = PlaylistId.Parse(playlistUrl);

        // Assert
        parsed.Value.Should().Be(expectedPlaylistId);
    }
    public void Playlist_ID_can_be_parsed_from_an_ID_string(string playlistId)
    {
        // Act
        var parsed = PlaylistId.Parse(playlistId);

        // Assert
        parsed.Value.Should().Be(playlistId);
    }
Beispiel #3
0
        public void DeletePlaylistDeezer()
        {
            var playlistId  = PlaylistId.Parse("100");
            var accessToken = "accessToken";

            var deezerService = DeezerApiBuilder.Create();

            deezerService.Build().DeletePlaylist(accessToken, playlistId);

            Assert.AreEqual(1, deezerService.PlaylistDeleted);
        }
        /// <summary>
        /// Asynchronously searches YouTube for the specified <paramref name="searchQuery"/>.
        /// </summary>
        /// <param name="searchQuery">The video, playlist, or channel to search for.</param>
        /// <returns>An <see cref="IReadOnlyList{T}"/> of <see cref="IVideo"/>'s matching the user's specified <paramref name="searchQuery"/>.</returns>
        public static async ValueTask <IReadOnlyList <IVideo> > SearchAsync(string searchQuery)
        {
            if (PlaylistId.TryParse(searchQuery).HasValue)
            {
                return(await Youtube.Client.Playlists.GetVideosAsync(PlaylistId.Parse(searchQuery)).CollectAsync(200));
            }
            else if (ChannelId.TryParse(searchQuery).HasValue)
            {
                return(await Youtube.Client.Channels.GetUploadsAsync(ChannelId.Parse(searchQuery)).CollectAsync(200));
            }

            return(await Youtube.Client.Search.GetVideosAsync(searchQuery).CollectAsync(200));
        }
Beispiel #5
0
        public PlaylistId CreatePlaylist(string accessToken, UserId userId, string playlistName)
        {
            return(_request.Post(string.Format(Endpoints.CreatePlaylist, userId.Value, playlistName, accessToken), response =>
            {
                if (!JObject
                    .Parse(response)
                    .TryGetValue("id", StringComparison.InvariantCultureIgnoreCase, out var playlistId))
                {
                    return PlaylistId.Empty;
                }

                return PlaylistId.Parse(playlistId.ToString());
            }));
        }
Beispiel #6
0
        public void CreatePlaylistDeezer()
        {
            var userId       = UserId.Parse("12345");
            var playlistId   = PlaylistId.Parse("100");
            var playlistName = "playlistName";
            var accessToken  = "accessToken";

            var deezerService = DeezerApiBuilder.Create();

            var actualPlaylistId = deezerService
                                   .SetCreatePlaylist(playlistId)
                                   .Build()
                                   .CreatePlaylist(accessToken, userId, playlistName);

            Assert.AreEqual(actualPlaylistId, actualPlaylistId);
        }
Beispiel #7
0
        public void AddSongsToPlaylistDeezer()
        {
            var playlistId  = PlaylistId.Parse("100");
            var accessToken = "accessToken";
            var songIds     = new []
            {
                SongId.Parse("001"),
                SongId.Parse("002"),
                SongId.Parse("003")
            };

            var deezerService = DeezerApiBuilder.Create();

            deezerService.Build().AddSongsToPlaylist(accessToken, playlistId, songIds);

            Assert.AreEqual(3, deezerService.SongsAdded);
        }
Beispiel #8
0
        public void RaiseMessageWhenAddPlaylistToUser()
        {
            var stream         = new MemoryEventStream();
            var deezerApi      = DeezerApiBuilder.Create().SetCreatePlaylist(PlaylistId.Parse("100")).Build();
            var songRepository = SongRepositoryBuilder.Create()
                                 .SetRandomSongs(1, new[] { new Song(SongId.Parse("100"), "title", "artist") }).Build();
            var playlistRepository = PlaylistRepositoryBuilder.Create().Build();

            stream.Add(new UserCreated(Identity.Parse("*****@*****.**", "dublow", "12345", "accessToken")));

            var publisher = new EventBus(stream);

            var user = new User(stream, publisher, deezerApi, songRepository, playlistRepository, 1);

            user.AddPlaylist("playlistName");

            Assert.IsTrue(stream.GetEvents().Contains(new PlaylistAdded(UserId.Parse("12345"), PlaylistId.Parse("100"), "playlistName")));
        }
Beispiel #9
0
        public void GetPlaylistsByUserIdWithUserId()
        {
            // arrange
            var playlistId  = PlaylistId.Parse("100");
            var userId      = UserId.Parse("12345");
            var accessToken = "accessToken";

            var deezerService = DeezerApiBuilder
                                .Create()
                                .SetPlaylistIdsByUserId(new[] { playlistId })
                                .Build();
            // act
            var actual = deezerService.GetPlaylistIdsByUserId(accessToken, userId, s => true);

            // assert
            Assert.AreEqual(1, actual.Count());
            Assert.AreEqual(playlistId, actual.First());
        }
        public void UseRepositoryWhenPlaylistIsDeleted()
        {
            // arrange
            var userId       = UserId.Parse("12345");
            var playlistId   = PlaylistId.Parse("100");
            var playlistName = "playlistName";

            var mockedPlaylistRepository = PlaylistRepositoryBuilder.Create();

            mockedPlaylistRepository.Playlists.Add((userId, playlistId, playlistName));
            var playlistRepository = mockedPlaylistRepository.Build();
            var playlistHandler    = new PlaylistHandler(playlistRepository);

            // act
            playlistHandler.Handle(new PlaylistDeleted(userId, playlistId, playlistName));
            // assert
            Assert.AreEqual(0, mockedPlaylistRepository.Playlists.Count);
        }
Beispiel #11
0
        public void NoRaiseMessageWhenAddExistingPlaylistToUser()
        {
            var stream             = new MemoryEventStream();
            var deezerApi          = DeezerApiBuilder.Create().Build();
            var songRepository     = SongRepositoryBuilder.Create().Build();
            var playlistRepository = PlaylistRepositoryBuilder.Create().Build();

            stream.Add(new UserCreated(Identity.Parse("*****@*****.**", "dublow", "12345", "accessToken")));
            stream.Add(new PlaylistAdded(UserId.Parse("12345"), PlaylistId.Parse("100"), "playlistName"));

            var publisher = new EventBus(stream);

            var user = new User(stream, publisher, deezerApi, songRepository, playlistRepository, 1);

            user.AddPlaylist("playlistName");

            Assert.IsTrue(stream.GetEvents().Contains(new PlaylistAdded(UserId.Parse("12345"), PlaylistId.Parse("100"), "playlistName")));
            Assert.AreEqual(1, stream.GetEvents().OfType <PlaylistAdded>().Count());
        }
        public void UseRepositoryWhenPlaylistIsAdded()
        {
            // arrange
            var userId       = UserId.Parse("12345");
            var playlistId   = PlaylistId.Parse("100");
            var playlistName = "playlistName";

            var mockedPlaylistRepository = PlaylistRepositoryBuilder.Create();
            var playlistRepository       = mockedPlaylistRepository.Build();
            var playlistHandler          = new PlaylistHandler(playlistRepository);

            // act
            playlistHandler.Handle(new PlaylistAdded(userId, playlistId, playlistName));
            // assert
            var(actualUserId, actualPlaylisId, actualPlaylistName) = mockedPlaylistRepository.Playlists.First();
            Assert.AreEqual(userId, actualUserId);
            Assert.AreEqual(playlistId, actualPlaylisId);
            Assert.AreEqual(playlistName, actualPlaylistName);
        }
Beispiel #13
0
        public void GetSongsByPlaylistIdWithPlaylistId()
        {
            // arrange
            var playlistId  = PlaylistId.Parse("100");
            var songId      = SongId.Parse("001");
            var title       = "title";
            var artist      = "artist";
            var accessToken = "accessToken";

            var deezerService = DeezerApiBuilder
                                .Create()
                                .SetSongsByPlaylistId(new [] { new DeezerSong(songId, title, artist) })
                                .Build();
            // act
            var actual = deezerService.GetSongsByPlaylistId(accessToken, playlistId);

            // assert
            Assert.AreEqual(1, actual.Count());
            Assert.AreEqual(songId, actual.First().Id);
            Assert.AreEqual(title, actual.First().Title);
            Assert.AreEqual(artist, actual.First().Artist);
        }
Beispiel #14
0
        public void UseRepositoryWhenSongIsAdded()
        {
            // arrange
            var userId     = UserId.Parse("12345");
            var playlistId = PlaylistId.Parse("100");
            var songId     = SongId.Parse("001");
            var title      = "title";
            var artist     = "artist";

            var mockedSongRepository = SongRepositoryBuilder.Create();
            var songRepository       = mockedSongRepository.Build();
            var songHandler          = new SongHandler(songRepository);

            // act
            songHandler.Handle(new SongAdded(userId, playlistId, songId, title, artist));
            // assert
            var(actualUserId, actualPlaylistId, actualSongId, actualTitle, actualArtist) = mockedSongRepository.Songs.First();
            Assert.AreEqual(userId, actualUserId);
            Assert.AreEqual(playlistId, actualPlaylistId);
            Assert.AreEqual(songId, actualSongId);
            Assert.AreEqual(title, actualTitle);
            Assert.AreEqual(artist, actualArtist);
        }
 public void Playlist_ID_cannot_be_parsed_from_an_invalid_string(string playlistIdOrUrl)
 {
     // Act & assert
     Assert.Throws <ArgumentException>(() => PlaylistId.Parse(playlistIdOrUrl));
 }
Beispiel #16
0
        public IEnumerable <PlaylistId> GetPlaylistIdsByUserId(string accessToken, UserId userId, Predicate <string> filterTitle)
        {
            var uri = string.Format(Endpoints.GetPlaylists, userId.Value, accessToken);

            PlaylistDeezer GetP(string url)
            {
                return(_request.Get(url, JsonConvert.DeserializeObject <PlaylistDeezer>));
            }

            var playlistIds = new List <PlaylistId>();

            while (!string.IsNullOrEmpty(uri))
            {
                var playlistDeezer = GetP(uri);
                playlistIds.AddRange(playlistDeezer.Playlists.Where(x => filterTitle(x.Title)).Select(x => PlaylistId.Parse(x.Id)));
                uri = playlistDeezer.Next;
            }

            return(playlistIds);
        }