public void When_add_tracks_success()
        {
            var httpWebRequest = MockedHttpWebRequest
                                    .Create()
                                    .SuccessTracksResponse()
                                    .Build();

            var httpWebBuilder = new HttpWebBuilder(httpWebRequest);
            var deezer = new HttpDeezer(httpWebBuilder);

            var tracks = deezer.AddTracks(1, "accessToken", "12345", new[] { "123", "456" });
            Assert.IsTrue(tracks.Success);
        }
        public void When_add_playlist_with_null_response()
        {
            var httpWebRequest = MockedHttpWebRequest
                                    .Create()
                                    .NullResponse()
                                    .Build();

            var httpWebBuilder = new HttpWebBuilder(httpWebRequest);
            var deezer = new HttpDeezer(httpWebBuilder);

            var playlist = deezer.AddPlaylist(56789, "accessToken", "MagicPlaylist");
            Assert.IsNull(playlist);
        }
        public void When_add_playlist_success()
        {
            var httpWebRequest = MockedHttpWebRequest
                                    .Create()
                                    .SuccessPlaylistResponse()
                                    .Build();

            var httpWebBuilder = new HttpWebBuilder(httpWebRequest);
            var deezer = new HttpDeezer(httpWebBuilder);

            var playlist = deezer.AddPlaylist(56789, "accessToken", "MagicPlaylist");
            Assert.AreEqual("12345", playlist.Id);
            Assert.AreEqual("https://www.deezer.com/playlist/12345", playlist.PlaylistUrl);
        }
        public void When_add_tracks_invalid_playlist_id()
        {
            var httpWebRequest = MockedHttpWebRequest
                                    .Create()
                                    .ErrorTracksInvalidPlaylistIdResponse()
                                    .Build();

            var httpWebBuilder = new HttpWebBuilder(httpWebRequest);
            var deezer = new HttpDeezer(httpWebBuilder);

            var tracks = deezer.AddTracks(1, "accessToken", "12345", new[] { "123", "456" });

            Assert.IsTrue(tracks.HasError);
            Assert.AreEqual("DataException", tracks.Error.Type);
            Assert.AreEqual("no data", tracks.Error.Message);
            Assert.AreEqual(800, tracks.Error.Code);
        }
        public void When_add_playlist_with_invalid_response()
        {
            var httpWebRequest = MockedHttpWebRequest
                                    .Create()
                                    .ErrorPlaylistResponse()
                                    .Build();

            var httpWebBuilder = new HttpWebBuilder(httpWebRequest);
            var deezer = new HttpDeezer(httpWebBuilder);

            var playlist = deezer.AddPlaylist(56789, "accessToken", "MagicPlaylist");

            Assert.IsTrue(playlist.HasError);
            Assert.AreEqual("ParameterException", playlist.Error.Type);
            Assert.AreEqual("Wrong parameter: playlistid", playlist.Error.Message);
            Assert.AreEqual(500, playlist.Error.Code);
        }
Exemple #6
0
 public HttpDeezer(HttpWebBuilder httpWebBuilder)
 {
     _httpWebBuilder = httpWebBuilder;
 }
        private HttpDeezer BuildSuccessHttpDeezer()
        {
            var httpWebRequest = MockedHttpWebRequest
                                    .Create()
                                    .SuccessPlaylistResponse()
                                    .SuccessTracksResponse()
                                    .Build();

            var httpWebBuilder = new HttpWebBuilder(httpWebRequest);

            return new HttpDeezer(httpWebBuilder);
        }
        public void When_post_playlist_with_error_tracks_must_be_failed()
        {
            var httpWebRequest = MockedHttpWebRequest
                                    .Create()
                                    .SuccessPlaylistResponse()
                                    .ErrorTracksInvalidTrackIdResponse()
                                    .Build();

            var httpWebBuilder = new HttpWebBuilder(httpWebRequest);
            var httpDeezer = new HttpDeezer(httpWebBuilder);
            var mockedMagicPlaylistGateway = MockedMagicPlaylistGateway
                                                .Create()
                                                .CanAddPlaylist(true);

            var browser = new Browser(cfg =>
            {
                cfg.Module<HomeModule>();
                cfg.Dependency(BuildSuccessRadioGateway());
                cfg.Dependency(mockedMagicPlaylistGateway.Build());
                cfg.Dependency(httpDeezer);
            });

            var response = browser.Post("/playlist", (with) => {
                with.HttpRequest();
                with.FormValue("id", "1");
                with.FormValue("accessToken", "abcde");
                with.FormValue("firstname", "Nicolas");
                with.FormValue("lastname", "Delfour");
                with.FormValue("email", "*****@*****.**");
                with.FormValue("gender", "M");
                with.FormValue("name", "Nico");
                with.FormValue("country", "FR");
                with.FormValue("lang", "FR");
                with.FormValue("birthday", "1980-02-25");
            });

            var logTable = mockedMagicPlaylistGateway._logTable;
            var error = logTable.SingleOrDefault();

            Assert.AreEqual(1, logTable.Count);
            Assert.IsNotNull(error);
            Assert.AreEqual("MagicPlaylistException", error.errorType);
            Assert.AreEqual("DeezerTracks error:[ParameterException][Wrong parameter: songs][500]", error.message);
            Assert.IsNotEmpty(error.stackTrace);
            Assert.AreEqual(1, mockedMagicPlaylistGateway._userTable.Count);

            Assert.AreEqual(HttpStatusCode.InternalServerError, response.StatusCode);
            Assert.AreEqual("application/json; charset=utf-8", response.ContentType);
            Assert.AreEqual("{\"success\":false}", response.Body.AsString());
        }
        public void When_add_tracks_invalid_tracks_id()
        {
            var httpWebRequest = MockedHttpWebRequest
                                    .Create()
                                    .ErrorTracksInvalidTrackIdResponse()
                                    .Build();

            var httpWebBuilder = new HttpWebBuilder(httpWebRequest);
            var deezer = new HttpDeezer(httpWebBuilder);

            var tracks = deezer.AddTracks(1, "accessToken", "12345", new[] { "123", "456" });

            Assert.IsTrue(tracks.HasError);
            Assert.AreEqual("ParameterException", tracks.Error.Type);
            Assert.AreEqual("Wrong parameter: songs", tracks.Error.Message);
            Assert.AreEqual(500, tracks.Error.Code);
        }
        public void When_add_tracks_with_null_response()
        {
            var httpWebRequest = MockedHttpWebRequest
                                    .Create()
                                    .NullResponse()
                                    .Build();

            var httpWebBuilder = new HttpWebBuilder(httpWebRequest);
            var deezer = new HttpDeezer(httpWebBuilder);

            var tracks = deezer.AddTracks(1, "accessToken", "12345", new[] { "123", "456" });
            Assert.IsNull(tracks);
        }