Example #1
0
        public void EnsureGetMixesThrowsExceptionForNullGroup()
        {
            MixGroup     nullGroup = null;
            IMusicClient client    = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.mixes));

            client.GetMixesAsync(nullGroup).Wait();
        }
 public void EnsureExceptionIsThrownIfNullProductAsync()
 {
     IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.product_parse_tests));
     Product nullProduct = null;
     var t = client.GetSimilarProductsAsync(nullProduct);
     t.Wait();
 }
        public void EnsureGetTopProductsForGenreThrowsExceptionForNullGenre()
        {
            IMusicClient client    = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.product_parse_tests));
            Genre        nullGenre = null;

            client.GetTopProductsForGenreAsync(nullGenre, Category.Album).Wait();
        }
        public void EnsureGetSimilarArtistsAsyncThrowsExceptionForNullArtist()
        {
            Artist       nullArtist = null;
            IMusicClient client     = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.artist_similar));

            client.GetSimilarArtistsAsync(nullArtist).Wait();
        }
Example #5
0
        public void EnsureGetAuthenticationUriIncludesVersion()
        {
            var client = new MusicClient("id");
            var uri    = client.GetAuthenticationUri(Scope.ReadUserPlayHistory);

            Assert.AreEqual("https://sapi.mixrad.io/1.x/authorize/?response_type=code&client_id=id&scope=read_userplayhistory", uri.ToString(), "Expected a matching uri");
        }
Example #6
0
		public ActivityViewModel (MusicClient client, AuthHelper authHelper)
		{
			this._mixRadioClient = client;
			this._authHelper = authHelper;
			this.Artists = new ObservableCollection<Artist> ();
			this.Tracks = new ObservableCollection<UserEvent> ();
		}
Example #7
0
        public async Task EnsureGetMixReturnsDetails()
        {
            IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.mix));
            Mix          result = await client.GetMixAsync("35953777");

            Assert.IsNotNull(result, "Expected a result");
        }
Example #8
0
        public async Task EnsureGetAuthenticationTokenAsyncReturnsATokenForValidCalls()
        {
            var client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.token_response));
            var result = await client.GetAuthenticationTokenAsync("secret", "code");

            Assert.IsNotNull(result, "Expected a result");
        }
Example #9
0
        public async Task EnsureGetMixThrowsForBadId()
        {
            IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(FakeResponse.NotFound()));
            Mix          result = await client.GetMixAsync("badid");

            Assert.IsNotNull(result, "Expected a result");
        }
        public void EnsureExceptionIsThrownIfNullProduct()
        {
            IMusicClient client      = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.product_parse_tests));
            Product      nullProduct = null;

            client.GetSimilarProductsAsync(nullProduct).Wait();
        }
        public void EnsureGetArtistProductsThrowsExceptionForNullArtist()
        {
            Artist       nullArtist = null;
            IMusicClient client     = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.search_artists));

            client.GetArtistProductsAsync(nullArtist).Wait();
        }
        public void EnsureGetArtistsAroundLocationReturnsArtistsForValidSearch()
        {
            IMusicClient client = new MusicClient("test", "test", "gb", new MockApiRequestHandler(Resources.search_artists));
            client.GetArtistsAroundLocation(
                (ListResponse<Artist> result) =>
                {
                    Assert.IsNotNull(result, "Expected a result");
                    Assert.IsNotNull(result.StatusCode, "Expected a status code");
                    Assert.IsTrue(result.StatusCode.HasValue, "Expected a status code");
                    Assert.AreEqual(HttpStatusCode.OK, result.StatusCode.Value, "Expected a 200 response");
                    Assert.IsNotNull(result.Result, "Expected a list of results");
                    Assert.IsNull(result.Error, "Expected no error");
                    Assert.Greater(result.Result.Count, 0, "Expected more than 0 results");

                    foreach (Artist artist in result.Result)
                    {
                        Assert.IsFalse(string.IsNullOrEmpty(artist.Id), "Expected Id to be populated");
                        Assert.IsFalse(string.IsNullOrEmpty(artist.Name), "Expected Name to be populated");
                        Assert.IsNotNull(artist.Genres, "Expected a genre list");
                        Assert.Greater(artist.Genres.Length, 0, "Expected more than 0 genres");
                    }
                },
                51.45534,
                -2.59239);
        }
Example #13
0
        public void EnsureGetTrackSampleUriThrowsExceptionForNullId()
        {
            string       nullId = null;
            IMusicClient client = new MusicClient("test", "gb", (IApiRequestHandler)null);

            client.GetTrackSampleUri(nullId);
        }
Example #14
0
 public ActivityViewModel(MusicClient client, AuthHelper authHelper)
 {
     this._mixRadioClient = client;
     this._authHelper     = authHelper;
     this.Artists         = new ObservableCollection <Artist> ();
     this.Tracks          = new ObservableCollection <UserEvent> ();
 }
Example #15
0
        public void EnsureGetProductThrowsExceptionForNullProductId()
        {
            string       nullId = null;
            IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.single_product));

            client.GetProductAsync(nullId).Wait();
        }
Example #16
0
 public void EnsureAuthTokenSetCorrectly()
 {
     var client = new MusicClient("test", "gb", new MockApiRequestHandler(FakeResponse.NotFound()));
     client.SetAuthenticationToken(AuthTokenTests.GetTestAuthToken());
     Assert.AreEqual(true, client.IsUserAuthenticated, "Expected an authenticated user");
     Assert.AreEqual(true, client.IsUserTokenActive, "Expected an authenticated user");
 }
        public void EnsureGetTopArtistsForGenreThrowsExceptionForNullGenre()
        {
            Genre        nullGenre = null;
            IMusicClient client    = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.top_artists_genre));

            client.GetTopArtistsForGenreAsync(nullGenre).Wait();
        }
Example #18
0
        public void EnsureGetNewReleasesForGenreThrowsExceptionForNullGenreId()
        {
            IMusicClient client      = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.product_parse_tests));
            string       nullGenreId = null;

            client.GetNewReleasesForGenreAsync(nullGenreId, Category.Album).Wait();
        }
 public async void EnsureAsyncGetTopProductsReturnsItems()
 {
     // Only test happy path, as the MusicClient tests cover the unhappy path
     IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.product_parse_tests));
     ListResponse<Product> result = await client.GetTopProductsAsync(Category.Album);
     Assert.Greater(result.Result.Count, 0, "Expected more than 0 results");
 }
        public async void EnsureAsyncGetGenresReturnsItems()
        {
            // Only test happy path, as the MusicClient tests cover the unhappy path
            IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.genres));

            ListResponse<Genre> result = await client.GetGenresAsync();
            Assert.Greater(result.Result.Count, 0, "Expected more than 0 results");
        }
Example #21
0
 public async Task EnsureRefreshAuthenticationTokenAsyncReturnsExistingTokenIfValid()
 {
     var client = new MusicClient("test", "gb", new MockApiRequestHandler(FakeResponse.NotFound()));
     var token = AuthTokenTests.GetTestAuthToken();
     client.SetAuthenticationToken(token);
     var result = await client.RefreshAuthenticationTokenAsync("secret");
     Assert.AreEqual(token.AccessToken, result.AccessToken, "Expected the same token");
 }
Example #22
0
 public Danmaku()
 {
     RoomId       = "roomid".GetConfig().ToInt32();
     TcpClient    = new TcpClient();
     HttpClient   = new HttpClientEx();
     MusicClient  = new MusicClient(HttpClient.BaseHttpClient);
     DefaultHosts = new string[] { "livecmt-2.bilibili.com", "livecmt-1.bilibili.com" };
 }
Example #23
0
 public async Task EnsureGetArtistProductsReturnsItems()
 {
     IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.search_artists));
     var t = await client.GetArtistProductsAsync("test", Category.Album);
     this.ValidateProductListResponse(t);
     t = await client.GetArtistProductsAsync("test");
     this.ValidateProductListResponse(t);
 }
Example #24
0
        public async Task EnsureInvalidApiCredentialsExceptionThrownWhenServerGives403ForItemMethods2()
        {
            MusicClient        client   = new MusicClient("badkey", "us", new MockApiRequestHandler(FakeResponse.Forbidden()));
            Response <Product> response = await client.GetProductAsync("test");

            Assert.IsNotNull(response.Error, "Expected an Error");
            Assert.AreEqual(typeof(InvalidApiCredentialsException), response.Error.GetType(), "Expected an InvalidApiCredentialsException");
        }
 public void EnsureAsyncGetProductsReturnsItems()
 {
     // Only test happy path, as the MusicClient tests cover the unhappy path
     IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.single_product));
     var task = client.GetProductAsync("test");
     task.Wait();
     this.ValidateProductResponse(task.Result);
 }
Example #26
0
        public void EnsureAuthTokenSetCorrectly()
        {
            var client = new MusicClient("test", "gb", new MockApiRequestHandler(FakeResponse.NotFound()));

            client.SetAuthenticationToken(AuthTokenTests.GetTestAuthToken());
            Assert.AreEqual(true, client.IsUserAuthenticated, "Expected an authenticated user");
            Assert.AreEqual(true, client.IsUserTokenActive, "Expected an authenticated user");
        }
Example #27
0
        public async Task EnsureInvalidContentTypeRaisesListResponseWithApiCallFailedException()
        {
            MusicClient client = new MusicClient("badkey", "us", new MockApiRequestHandler(FakeResponse.Success(Resources.search_all, null)));
            ListResponse <MusicItem> response = await client.SearchAsync("test");

            Assert.IsNotNull(response.Error, "Expected an Error");
            Assert.AreEqual(typeof(ApiCallFailedException), response.Error.GetType(), "Expected an ApiCallFailedException");
        }
Example #28
0
 public async Task FindTest3()
 {
     var client = new MusicClient("XboxMusicClientTests", "ThisWillBeChangedOften");
     var result = await client.Find("caparezza non me lo posso promettere");
     Assert.IsNotNull(result);
     Assert.IsNotNull(result.Error);
     Assert.IsNotNull(result.Error.Response);
     Assert.AreEqual("NotFound", result.Error.ErrorCode);
 }
        public async Task EnsureRequestIdComesBackInResponse()
        {
            IMusicClient          client    = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.search_suggestions));
            var                   requestId = Guid.NewGuid();
            ListResponse <Artist> result    = await client.SearchArtistsAsync("muse", requestId : requestId);

            Assert.IsNotNull(result, "Expected a result");
            Assert.AreEqual(requestId, result.RequestId);
        }
        public async Task EnsureRequestIdComesBackInResponse()
        {
            IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.search_suggestions));
            var requestId = Guid.NewGuid();
            ListResponse<string> result = await client.GetSearchSuggestionsAsync("green", requestId: requestId);

            Assert.IsNotNull(result, "Expected a result");
            Assert.AreEqual(requestId, result.RequestId);
        }
Example #31
0
 public App(IAuthPlatformSpecific platformSpecificAuth, string appVersion, IUriLauncher uriLauncher)
 {
     this.MixRadioClient    = new MusicClient(ApiKeys.ClientId);
     this.AuthHelper        = new AuthHelper(platformSpecificAuth, this.MixRadioClient);
     this.ActivityViewModel = new ActivityViewModel(this.MixRadioClient, this.AuthHelper);
     this.AppVersion        = appVersion;
     this.UriLauncher       = uriLauncher;
     this.MainPage          = new RootPage();
 }
Example #32
0
		public App(IAuthPlatformSpecific platformSpecificAuth, string appVersion, IUriLauncher uriLauncher)
        {
			this.MixRadioClient = new MusicClient (ApiKeys.ClientId);
			this.AuthHelper = new AuthHelper (platformSpecificAuth, this.MixRadioClient);
			this.ActivityViewModel = new ActivityViewModel (this.MixRadioClient, this.AuthHelper);
			this.AppVersion = appVersion;
			this.UriLauncher = uriLauncher;
			this.MainPage = new RootPage ();
        }
Example #33
0
        public async Task EnsureRefreshAuthenticationTokenAsyncThrowsForFailedCalls()
        {
            var client = new MusicClient("test", "gb", new MockApiRequestHandler(FakeResponse.InternalServerError()));
            var token  = AuthTokenTests.GetTestAuthToken();

            token.ExpiresUtc = DateTime.UtcNow.AddDays(-1);
            client.SetAuthenticationToken(token);
            var result = await client.RefreshAuthenticationTokenAsync("secret");
        }
Example #34
0
 public async Task FindTest2()
 {
     var client = new MusicClient("XboxMusicClientTests", "ThisWillBeChangedOften");
     var result = await client.Find("Daft Punk", getAlbums: false);
     Assert.IsNotNull(result);
     Assert.IsNull(result.Error);
     Assert.IsNotNull(result.Artists);
     Assert.IsNotNull(result.Tracks);
     Assert.IsNull(result.Albums);
 }
Example #35
0
 public async Task FindTest1Continued()
 {
     var client = new MusicClient("XboxMusicClientTests", "ThisWillBeChangedOften");
     var result = await client.Find("Daft Punk", _find1ContinuationToken);
     Assert.IsNotNull(result);
     Assert.IsNull(result.Error);
     Assert.IsNotNull(result.Albums);
     Assert.IsNull(result.Artists);
     Assert.IsNull(result.Tracks);
 }
Example #36
0
        public void EnsureQueryStringIsBuiltCorrectlyWithOptionalFeaturedArtistsParameter()
        {
            var handler = new MockApiRequestHandler(Resources.mixes);

            IMusicClient client = new MusicClient("test", "gb", handler);
            var          task   = client.GetMixesAsync("test", true);

            Assert.Greater(task.Result.Result.Count, 0, "Expected more than 0 results");
            Assert.IsTrue(handler.LastQueryString.Contains(new KeyValuePair <string, string>("view", "topftartists")));
        }
 public void EnsureGetArtistProductsReturnsItems()
 {
     IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.search_artists));
     var task = client.GetArtistProductsAsync(new Artist() { Id = "test" }, Category.Album);
     task.Wait();
     this.ValidateProductListResponse(task.Result);
     task = client.GetArtistProductsAsync("test");
     task.Wait();
     this.ValidateProductListResponse(task.Result);
 }
Example #38
0
        public async Task EnsureRefreshAuthenticationTokenAsyncReturnsExistingTokenIfValid()
        {
            var client = new MusicClient("test", "gb", new MockApiRequestHandler(FakeResponse.NotFound()));
            var token  = AuthTokenTests.GetTestAuthToken();

            client.SetAuthenticationToken(token);
            var result = await client.RefreshAuthenticationTokenAsync("secret");

            Assert.AreEqual(token.AccessToken, result.AccessToken, "Expected the same token");
        }
Example #39
0
        public async Task EnsureGetNewReleasesForGenreReturnsItems()
        {
            IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.product_parse_tests));

            this.ValidateNewReleasesResponse(await client.GetNewReleasesForGenreAsync(new Genre()
            {
                Id = "rock"
            }, Category.Album));
            this.ValidateNewReleasesResponse(await client.GetNewReleasesForGenreAsync("rock", Category.Album));
        }
Example #40
0
        public async Task EnsureGetArtistProductsReturnsItems()
        {
            IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.search_artists));
            var          t      = await client.GetArtistProductsAsync("test", Category.Album);

            this.ValidateProductListResponse(t);
            t = await client.GetArtistProductsAsync("test");

            this.ValidateProductListResponse(t);
        }
Example #41
0
 public async Task GetTest1()
 {
     var client = new MusicClient("XboxMusicClientTests", "ThisWillBeChangedOften");
     var result = await client.Get("music.C61C0000-0200-11DB-89CA-0019B92A3933");
     Assert.IsNotNull(result);
     Assert.IsNull(result.Error);
     Assert.IsNotNull(result.Artists);
     //Assert.IsNotNull(result.Tracks);
     //Assert.IsNotNull(result.Albums);
 }
Example #42
0
        public async Task FindTest3()
        {
            var client = new MusicClient("XboxMusicClientTests", "ThisWillBeChangedOften");
            var result = await client.Find("caparezza non me lo posso promettere");

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Error);
            Assert.IsNotNull(result.Error.Response);
            Assert.AreEqual("NotFound", result.Error.ErrorCode);
        }
Example #43
0
 /// <summary>
 /// Creates the API client.
 /// </summary>
 /// <param name="countryCode">A country code.</param>
 private static void CreateApiClient(string countryCode)
 {
     if (!string.IsNullOrEmpty(countryCode))
     {
         ApiClient = new MusicClient(ApiKeys.ClientId, countryCode);
     }
     else
     {
         ApiClient = null;
     }
 }
Example #44
0
 public async Task EnsureGetArtistWithInvalidIdReturnsNullResult()
 {
     IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.search_noresults));
     Response<Artist> result = await client.GetArtistAsync("559688");
     Assert.IsNotNull(result, "Expected a result");
     Assert.IsNotNull(result.StatusCode, "Expected a status code");
     Assert.IsTrue(result.StatusCode.HasValue, "Expected a status code");
     Assert.AreEqual(HttpStatusCode.OK, result.StatusCode.Value, "Expected a 200 response");
     Assert.IsNull(result.Result, "Expected no result");
     Assert.IsNull(result.Error, "Expected no error");
 }
 public void EnsureAsyncGetArtistProductsReturnsItems()
 {
     // Only test happy path, as the MusicClient tests cover the unhappy path
     IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.artist_products));
     var artistProductByIdTask = client.GetArtistProductsAsync("test");
     var artistProductByArtistTask = client.GetArtistProductsAsync(new Artist() { Id = "test" });
     artistProductByIdTask.Wait();
     artistProductByArtistTask.Wait();
     this.ValidateProductListResponse(artistProductByIdTask.Result);
     this.ValidateProductListResponse(artistProductByArtistTask.Result);
 }
Example #46
0
        public async Task GetTest1()
        {
            var client = new MusicClient("XboxMusicClientTests", "ThisWillBeChangedOften");
            var result = await client.Get("music.C61C0000-0200-11DB-89CA-0019B92A3933");

            Assert.IsNotNull(result);
            Assert.IsNull(result.Error);
            Assert.IsNotNull(result.Artists);
            //Assert.IsNotNull(result.Tracks);
            //Assert.IsNotNull(result.Albums);
        }
Example #47
0
        public async Task FindTest2()
        {
            var client = new MusicClient("XboxMusicClientTests", "ThisWillBeChangedOften");
            var result = await client.Find("Daft Punk", getAlbums : false);

            Assert.IsNotNull(result);
            Assert.IsNull(result.Error);
            Assert.IsNotNull(result.Artists);
            Assert.IsNotNull(result.Tracks);
            Assert.IsNull(result.Albums);
        }
 public async Task EnsureGetProductReturnsUnknownErrorForFailedCall()
 {
     IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(FakeResponse.ConflictServerError("{ \"error\":\"true\"}")));
     Response<Product> result = await client.GetProductAsync("test");
     Assert.IsNotNull(result, "Expected a result");
     Assert.IsNotNull(result.StatusCode, "Expected a status code");
     Assert.IsTrue(result.StatusCode.HasValue, "Expected a status code");
     Assert.AreNotEqual(HttpStatusCode.OK, result.StatusCode.Value, "Expected a non-OK response");
     Assert.IsNotNull(result.Error, "Expected an error");
     Assert.AreEqual(typeof(ApiCallFailedException), result.Error.GetType(), "Expected an ApiCallFailedException");
 }
Example #49
0
 public async Task EnsureGetGenresReturnsErrorForFailedCall()
 {
     IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(FakeResponse.InternalServerError()));
     var result = await client.GetGenresAsync();
     Assert.IsNotNull(result, "Expected a result");
     Assert.IsNotNull(result.StatusCode, "Expected a status code");
     Assert.IsTrue(result.StatusCode.HasValue, "Expected a status code");
     Assert.AreNotEqual(HttpStatusCode.OK, result.StatusCode.Value, "Expected a non-OK response");
     Assert.IsNotNull(result.Error, "Expected an error");
     Assert.AreEqual(typeof(ApiCallFailedException), result.Error.GetType(), "Expected an ApiCallFailedException");
 }
Example #50
0
        public void EnsureExclusiveMixGroupRequestsSendExclusiveTag()
        {
            var exclusiveTag = "thisIsTheExclusiveTag";
            var handler      = new MockApiRequestHandler(Resources.mixgroups);

            IMusicClient client     = new MusicClient("test", "gb", handler);
            var          groupsTask = client.GetMixGroupsAsync(exclusiveTag);

            Assert.Greater(groupsTask.Result.Result.Count, 0, "Expected more than 0 results");
            Assert.IsTrue(handler.LastQueryString.Contains(new KeyValuePair <string, string>(MusicClientCommand.ParamExclusive, exclusiveTag)));
        }
 public async Task EnsureGetNewReleasesReturnsErrorForFailedCall()
 {
     IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(FakeResponse.NotFound()));
     ListResponse<Product> result = await client.GetNewReleasesAsync(Category.Album);
     Assert.IsNotNull(result, "Expected a result");
     Assert.IsNotNull(result.StatusCode, "Expected a status code");
     Assert.IsTrue(result.StatusCode.HasValue, "Expected a status code");
     Assert.AreNotEqual(HttpStatusCode.OK, result.StatusCode.Value, "Expected a non-OK response");
     Assert.IsNotNull(result.Error, "Expected an error");
     Assert.AreEqual(typeof(ApiCallFailedException), result.Error.GetType(), "Expected an ApiCallFailedException");
 }
Example #52
0
 public async Task EnsureSearchBpmReturnsItems()
 {
     IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.product_parse_tests));
     ListResponse<MusicItem> result = await client.SearchBpmAsync(120, 130);
     Assert.IsNotNull(result, "Expected a result");
     Assert.IsNotNull(result.StatusCode, "Expected a status code");
     Assert.IsTrue(result.StatusCode.HasValue, "Expected a status code");
     Assert.AreEqual(HttpStatusCode.OK, result.StatusCode.Value, "Expected a 200 response");
     Assert.IsNotNull(result.Result, "Expected a list of results");
     Assert.IsNull(result.Error, "Expected no error");
     Assert.Greater(result.Result.Count, 0, "Expected more than 0 results");
 }
        public async Task EnsureGetSimilarProductsReturnsItems()
        {
            IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.product_parse_tests));
            this.ValidateProductListResponse(await client.GetSimilarProductsAsync("test"));
            this.ValidateProductListResponse(await client.GetSimilarProductsAsync("test"));

            var task = client.GetSimilarProductsAsync("test");
            this.ValidateProductListResponse(task.Result);

            var productTask = client.GetSimilarProductsAsync("test");
            this.ValidateProductListResponse(productTask.Result);
        }
Example #54
0
 public async Task EnsureGetAllMixesReturnsItems()
 {
     IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.allmixes));
     ListResponse<Mix> result = await client.GetAllMixesAsync();
     Assert.IsNotNull(result, "Expected a result");
     Assert.IsNotNull(result.StatusCode, "Expected a status code");
     Assert.IsTrue(result.StatusCode.HasValue, "Expected a status code");
     Assert.AreEqual(HttpStatusCode.OK, result.StatusCode.Value, "Expected a 200 response");
     Assert.IsNotNull(result.Result, "Expected a list of results");
     Assert.IsNull(result.Error, "Expected no error");
     Assert.Greater(result.Result.Count, 0, "Expected more than 0 results");
 }
 public async Task EnsureGetSearchSuggestionsReturnsErrorForFailedCall()
 {
     IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.search_suggestions_noresults));
     ListResponse<string> result = await client.GetSearchSuggestionsAsync("muse");
     Assert.IsNotNull(result, "Expected a result");
     Assert.IsNotNull(result.StatusCode, "Expected a status code");
     Assert.IsTrue(result.StatusCode.HasValue, "Expected a status code");
     Assert.AreEqual(HttpStatusCode.OK, result.StatusCode.Value, "Expected a 200 response");
     Assert.IsNotNull(result.Result, "Expected a list of results");
     Assert.IsNull(result.Error, "Expected no error");
     Assert.AreEqual(result.Result.Count, 0, "Expected 0 results");
 }
 public async Task EnsureGetArtistsAroundLocationReturnsErrorForFailedCall()
 {
     IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.search_noresults));
     ListResponse<Artist> result = await client.GetArtistsAroundLocationAsync(51.45534, -2.59239);
     Assert.IsNotNull(result, "Expected a result");
     Assert.IsNotNull(result.StatusCode, "Expected a status code");
     Assert.IsTrue(result.StatusCode.HasValue, "Expected a status code");
     Assert.AreEqual(HttpStatusCode.OK, result.StatusCode.Value, "Expected a 200 response");
     Assert.IsNotNull(result.Result, "Expected a list of results");
     Assert.IsNull(result.Error, "Expected no error");
     Assert.AreEqual(result.Result.Count, 0, "Expected 0 results");
 }
Example #57
0
        public async Task EnsureGetAuthenticationTokenAsyncReturnsExistingTokenIfValid()
        {
            var client = new MusicClient("test", "gb", new MockApiRequestHandler(FakeResponse.NotFound()));
            var token = AuthTokenTests.GetTestAuthToken();
            client.SetAuthenticationToken(token);
            var result = await client.GetAuthenticationTokenAsync("secret", "code");
            Assert.AreEqual(token.AccessToken, result.AccessToken, "Expected the same token");
            Assert.IsTrue(client.IsUserAuthenticated, "Expected an auth'd user");

            // Now clear the token...
            client.SetAuthenticationToken(null);
            Assert.IsFalse(client.IsUserAuthenticated, "Expected an un-auth'd user");
        }
 public void EnsureGetGenresReturnsAnUnhandledErrorForFailedCall()
 {
     IMusicClient client = new MusicClient("test", "gb", new MockApiRequestHandler(FakeResponse.ConflictServerError("{ \"error\":\"true\"}")));
     var task = client.GetGenresAsync();
     task.Wait();
     ListResponse<Genre> result = task.Result;
     Assert.IsNotNull(result, "Expected a result");
     Assert.IsNotNull(result.StatusCode, "Expected a status code");
     Assert.IsTrue(result.StatusCode.HasValue, "Expected a status code");
     Assert.AreNotEqual(HttpStatusCode.OK, result.StatusCode.Value, "Expected a non-OK response");
     Assert.IsNotNull(result.Error, "Expected an error");
     Assert.AreEqual(typeof(ApiCallFailedException), result.Error.GetType(), "Expected an ApiCallFailedException");
 }
 public async Task EnsureNormalCallWorksAsExpected()
 {
     var client = new MusicClient("test", "gb", new MockApiRequestHandler(Resources.user_recent_mixes));
     client.SetAuthenticationToken(AuthTokenTests.GetTestAuthToken());
     var result = await client.GetUserRecentMixesAsync();
     Assert.IsNotNull(result, "Expected a result");
     Assert.IsNotNull(result.StatusCode, "Expected a status code");
     Assert.IsTrue(result.StatusCode.HasValue, "Expected a status code");
     Assert.AreEqual(HttpStatusCode.OK, result.StatusCode.Value, "Expected a 200 response");
     Assert.IsNotNull(result.Result, "Expected a list of results");
     Assert.IsNull(result.Error, "Expected no error");
     Assert.Greater(result.Result.Count, 0, "Expected more than 0 results");
 }
Example #60
0
 /// <summary>
 /// Initializes MixRadio API for further requests. Responses to  
 /// requests depend on the region - TopArtists are country specific
 /// for example, and genres are localized by the region.
 /// </summary>
 /// <param name="countryCode">An ISO 3166-2 country code validated by the MixRadio API CountryResolver</param>
 public void Initialize(string countryCode)
 {
     // Create a music client with correct AppId and Token/AppCode
     if (countryCode == null || countryCode.Length != 2)
     {
         client = new MusicClient(MixRadio.TestApp.ApiKeys.ClientId);
     }
     else
     {
         client = new MusicClient(MixRadio.TestApp.ApiKeys.ClientId, countryCode.ToLower());
     }
     initialized = true;
 }