Exemplo n.º 1
0
        public void UseRepositoryWhenRadioSongWithDeezerSongIdIsParsed()
        {
            // arrange
            var songId    = SongId.Parse("001");
            var radioName = "djam";
            var title     = "title";
            var artist    = "artist";

            var mockedRadioSongRepository = RadioSongRepositoryBuilder.Create();
            var radioSongRepository       = mockedRadioSongRepository.Build();
            var deezerApi = DeezerApiBuilder
                            .Create()
                            .SetSong(new DeezerSong(songId, title, artist))
                            .Build();
            var radioSongHandler = new RadioSongHandler(radioSongRepository, deezerApi);

            // act
            var radioSongParsed = new RadioSongWithDeezerSongIdParsed(radioName, songId);

            radioSongHandler.Handle(radioSongParsed);
            // assert
            var(actualSongId, actualName, actualTitle, actualArtist) = mockedRadioSongRepository.RadioSongs.First();
            Assert.AreEqual(songId, actualSongId);
            Assert.AreEqual(radioName, actualName);
            Assert.AreEqual(title, actualTitle);
            Assert.AreEqual(artist, actualArtist);
        }
Exemplo n.º 2
0
        public void ReturnDeezerSongIdsWhenPassLength()
        {
            // arrange
            var deezerSong = new List <DeezerSong>
            {
                new DeezerSong(SongId.Parse("101"), "title1", "artist1"),
                new DeezerSong(SongId.Parse("102"), "title2", "artist2"),
                new DeezerSong(SongId.Parse("103"), "title3", "artist3")
            };
            var songEngine = SongEngineBuilder
                             .Create()
                             .SetRandomisedSongs(deezerSong).Build();
            // act
            var actual = songEngine.GetRandomisedSongs(3);

            // assert
            Assert.AreEqual(3, actual.Count());
            Assert.AreEqual(SongId.Parse("101"), actual.ElementAt(0).Id);
            Assert.AreEqual(SongId.Parse("102"), actual.ElementAt(1).Id);
            Assert.AreEqual(SongId.Parse("103"), actual.ElementAt(2).Id);
            Assert.AreEqual("title1", actual.ElementAt(0).Title);
            Assert.AreEqual("title2", actual.ElementAt(1).Title);
            Assert.AreEqual("title3", actual.ElementAt(2).Title);
            Assert.AreEqual("artist1", actual.ElementAt(0).Artist);
            Assert.AreEqual("artist2", actual.ElementAt(1).Artist);
            Assert.AreEqual("artist3", actual.ElementAt(2).Artist);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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")));
        }
Exemplo n.º 5
0
        public void GetSongFromDeezerWhenSongExists()
        {
            // arrange
            var    songId      = SongId.Parse("001");
            string title       = "title";
            string artist      = "artist";
            var    accessToken = "accessToken";

            var deezerService = DeezerApiBuilder
                                .Create()
                                .SetSong(new DeezerSong(songId, title, artist))
                                .Build();
            // act
            var actual = deezerService.GetSong(accessToken, title, artist);

            // assert
            Assert.AreEqual(songId, actual.Id);
            Assert.AreEqual(title, actual.Title);
            Assert.AreEqual(artist, actual.Artist);
        }
Exemplo n.º 6
0
        public IEnumerable <DeezerSong> GetSongsByPlaylistId(string accessToken, PlaylistId playlistId)
        {
            var uri = String.Format(Endpoints.GetSongsByPlaylist, playlistId.Value, accessToken);

            TrackDeezer GetT(string url)
            {
                Thread.Sleep(2000);
                return(_request.Get(url, JsonConvert.DeserializeObject <TrackDeezer>));
            }

            var trackItemDeezer = new List <TrackItemDeezer>();

            while (!string.IsNullOrEmpty(uri))
            {
                var trackDeezer = GetT(uri);
                trackItemDeezer.AddRange(trackDeezer.Tracks);
                uri = trackDeezer.Next;
            }

            return(trackItemDeezer.Select(x => new DeezerSong(SongId.Parse(x.Id), x.Title, x.Artist.Name)));
        }
Exemplo n.º 7
0
 public IEnumerable <Song> GetRandomSongs(int size)
 {
     using (var cnx = _provider.Create())
     {
         var commandText = $"select songid, title, artist from radiosong order by random() limit {size}";
         cnx.Open();
         using (var command = cnx.CreateCommand())
         {
             command.CommandText = commandText;
             using (var reader = command.ExecuteReader())
             {
                 while (reader.Read())
                 {
                     var songId = SongId.Parse(reader[0].ToString());
                     var title  = reader[1].ToString();
                     var artist = reader[2].ToString();
                     yield return(new Song(songId, title, artist));
                 }
             }
         }
     }
 }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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);
        }