Skip to content

Commit

Permalink
Tests. GetFeaturedPlaylists -> Timestamp DateTime. PagedPlaylists -> …
Browse files Browse the repository at this point in the history
…Paged<PlaylistSimplified>
  • Loading branch information
DanielLarsenNZ committed May 30, 2020
1 parent fdcfd50 commit 03871a5
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 32 deletions.
65 changes: 65 additions & 0 deletions src/SpotifyApi.NetCore.Tests/BrowseApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,71 @@ namespace SpotifyApi.NetCore.Tests
[TestClass]
public class BrowseApiTests
{
[TestMethod]
[TestCategory("Integration")]
public async Task GetCategories_Limit2_ItemsLength2()
{
// arrange
var http = new HttpClient();
var accounts = new AccountsService(http, TestsHelper.GetLocalConfig());

var api = new BrowseApi(http, accounts);

// act
var response = await api.GetCategories(limit:2);
Assert.AreEqual(2, response.Items.Length);
}

[TestMethod]
[TestCategory("Integration")]
public async Task GetCategory_FromNZCategories_SameCategoryHref()
{
// arrange
var http = new HttpClient();
var accounts = new AccountsService(http, TestsHelper.GetLocalConfig());

var api = new BrowseApi(http, accounts);
var category = (await api.GetCategories(limit: 1, country:SpotifyCountryCodes.New_Zealand)).Items[0];

// act
var response = await api.GetCategory(category.Id, country:SpotifyCountryCodes.New_Zealand);

Assert.AreEqual(category.Href, response.Href);
}

[TestMethod]
[TestCategory("Integration")]
public async Task GetCategoryPlaylists_FromFirstNZCategoryLimit2_ItemsLength2()
{
// arrange
var http = new HttpClient();
var accounts = new AccountsService(http, TestsHelper.GetLocalConfig());

var api = new BrowseApi(http, accounts);
var category = (await api.GetCategories(limit: 1, country: SpotifyCountryCodes.New_Zealand)).Items[0];

// act
var response = await api.GetCategoryPlaylists(category.Id, country: SpotifyCountryCodes.New_Zealand, limit: 2);

Assert.AreEqual(2, response.Items.Length);
}

[TestMethod]
[TestCategory("Integration")]
public async Task GetFeaturedPlaylists_Limit2_ItemsLength2()
{
// arrange
var http = new HttpClient();
var accounts = new AccountsService(http, TestsHelper.GetLocalConfig());

var api = new BrowseApi(http, accounts);

// act
var response = await api.GetFeaturedPlaylists(country: SpotifyCountryCodes.New_Zealand, limit: 2);

Assert.AreEqual(2, response.Items.Length);
}

[TestMethod]
[TestCategory("Integration")]
public async Task GetNewReleases_NoParams_NoError()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,18 @@ public void AppendToQueryAsCsv_ThreeValues_WellFormed()
Assert.AreEqual("?numbers=1,2,3", builder.Uri.Query);
}

[TestMethod]
public void AppendToQueryAsTimestampIso8601_DateTime_ExpectedFormat()
{
// arrange
var builder = new UriBuilder("https://api.spotify.com/v1/browse/featured-playlists");

// act
builder.AppendToQueryAsTimestampIso8601("timestamp", new DateTime(2014, 10, 23, 9, 0, 0));

// assert
Assert.AreEqual("?timestamp=2014-10-23T09:00:00", builder.Uri.Query);
}

}
}
28 changes: 12 additions & 16 deletions src/SpotifyApi.NetCore/BrowseApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,10 @@ public async Task<T> GetCategoryPlaylists<T>(
/// in a particular language. Note that, if locale is not supplied, or if the specified language
/// is not available, the category strings returned will be in the Spotify default language
/// (American English).</param>
/// <param name="timestamp">Optional. A timestamp in ISO 8601 format: yyyy-MM-ddTHH:mm:ss.
/// Use this parameter to specify the user’s local time to get results tailored for that specific
/// date and time in the day. If not provided, the response defaults to the current UTC time.
/// Example: “2014-10-23T09:00:00” for a user whose local time is 9AM. If there were no featured
/// playlists (or there is no data) at the specified time, the response will revert to the
/// current UTC time.</param>
/// <param name="timestamp">Optional. Use this parameter to specify the user’s local time to
/// get results tailored for that specific date and time in the day. If not provided, the response
/// defaults to the current UTC time. If there were no featured playlists (or there is no data)
/// at the specified time, the response will revert to the current UTC time.</param>
/// <param name="limit">Optional. Maximum number of results to return. Default: 20, Minimum: 1,
/// Maximum: 50.</param>
/// <param name="offset">Optional. The index of the first result to return. Default: 0 (the
Expand All @@ -249,7 +247,7 @@ public async Task<T> GetCategoryPlaylists<T>(
public Task<FeaturedPlaylists> GetFeaturedPlaylists(
string country = null,
string locale = null,
string timestamp = null,
DateTime? timestamp = null,
int? limit = null,
int offset = 0,
string accessToken = null) => GetFeaturedPlaylists<FeaturedPlaylists>(
Expand All @@ -272,12 +270,10 @@ public Task<FeaturedPlaylists> GetFeaturedPlaylists(
/// in a particular language. Note that, if locale is not supplied, or if the specified language
/// is not available, the category strings returned will be in the Spotify default language
/// (American English).</param>
/// <param name="timestamp">Optional. A timestamp in ISO 8601 format: yyyy-MM-ddTHH:mm:ss.
/// Use this parameter to specify the user’s local time to get results tailored for that specific
/// date and time in the day. If not provided, the response defaults to the current UTC time.
/// Example: “2014-10-23T09:00:00” for a user whose local time is 9AM. If there were no featured
/// playlists (or there is no data) at the specified time, the response will revert to the
/// current UTC time.</param>
/// <param name="timestamp">Optional. Use this parameter to specify the user’s local time to
/// get results tailored for that specific date and time in the day. If not provided, the response
/// defaults to the current UTC time. If there were no featured playlists (or there is no data)
/// at the specified time, the response will revert to the current UTC time.</param>
/// <param name="limit">Optional. Maximum number of results to return. Default: 20, Minimum: 1,
/// Maximum: 50.</param>
/// <param name="offset">Optional. The index of the first result to return. Default: 0 (the
Expand All @@ -288,16 +284,16 @@ public Task<FeaturedPlaylists> GetFeaturedPlaylists(
/// <remarks> https://developer.spotify.com/documentation/web-api/reference/browse/get-list-featured-playlists/ </remarks>
public async Task<T> GetFeaturedPlaylists<T>(
string country = null,
string locale = null,
string timestamp = null,
string locale = null,
DateTime? timestamp = null,
int? limit = null,
int offset = 0,
string accessToken = null)
{
var builder = new UriBuilder($"{BaseUrl}/browse/featured-playlists");
builder.AppendToQueryIfValueNotNullOrWhiteSpace("country", country);
builder.AppendToQueryIfValueNotNullOrWhiteSpace("locale", locale);
builder.AppendToQueryIfValueNotNullOrWhiteSpace("timestamp", timestamp);
builder.AppendToQueryAsTimestampIso8601("timestamp", timestamp);
builder.AppendToQueryIfValueGreaterThan0("limit", limit);
builder.AppendToQueryIfValueGreaterThan0("offset", offset);
return await GetModelFromProperty<T>(builder.Uri, "playlists", accessToken: accessToken);
Expand Down
6 changes: 6 additions & 0 deletions src/SpotifyApi.NetCore/Extensions/UriBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Globalization;

namespace SpotifyApi.NetCore
{
Expand Down Expand Up @@ -42,5 +43,10 @@ public static void AppendToQueryIfValueNotNullOrWhiteSpace(
{
if (!string.IsNullOrWhiteSpace(value)) AppendToQuery(builder, name, value);
}

public static void AppendToQueryAsTimestampIso8601(this UriBuilder builder, string name, DateTime? timestamp)
{
if (timestamp.HasValue) AppendToQuery(builder, name, timestamp.Value.ToString("s", CultureInfo.InvariantCulture));
}
}
}
25 changes: 11 additions & 14 deletions src/SpotifyApi.NetCore/IBrowseApi.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Threading.Tasks;

namespace SpotifyApi.NetCore
Expand Down Expand Up @@ -157,12 +158,10 @@ Task<T> GetCategoryPlaylists<T>(
/// in a particular language. Note that, if locale is not supplied, or if the specified language
/// is not available, the category strings returned will be in the Spotify default language
/// (American English).</param>
/// <param name="timestamp">Optional. A timestamp in ISO 8601 format: yyyy-MM-ddTHH:mm:ss.
/// Use this parameter to specify the user’s local time to get results tailored for that specific
/// date and time in the day. If not provided, the response defaults to the current UTC time.
/// Example: “2014-10-23T09:00:00” for a user whose local time is 9AM. If there were no featured
/// playlists (or there is no data) at the specified time, the response will revert to the
/// current UTC time.</param>
/// <param name="timestamp">Optional. Use this parameter to specify the user’s local time to
/// get results tailored for that specific date and time in the day. If not provided, the response
/// defaults to the current UTC time. If there were no featured playlists (or there is no data)
/// at the specified time, the response will revert to the current UTC time.</param>
/// <param name="limit">Optional. Maximum number of results to return. Default: 20, Minimum: 1,
/// Maximum: 50.</param>
/// <param name="offset">Optional. The index of the first result to return. Default: 0 (the
Expand All @@ -174,7 +173,7 @@ Task<T> GetCategoryPlaylists<T>(
Task<FeaturedPlaylists> GetFeaturedPlaylists(
string country = null,
string locale = null,
string timestamp = null,
DateTime? timestamp = null,
int? limit = null,
int offset = 0,
string accessToken = null);
Expand All @@ -191,12 +190,10 @@ Task<FeaturedPlaylists> GetFeaturedPlaylists(
/// in a particular language. Note that, if locale is not supplied, or if the specified language
/// is not available, the category strings returned will be in the Spotify default language
/// (American English).</param>
/// <param name="timestamp">Optional. A timestamp in ISO 8601 format: yyyy-MM-ddTHH:mm:ss.
/// Use this parameter to specify the user’s local time to get results tailored for that specific
/// date and time in the day. If not provided, the response defaults to the current UTC time.
/// Example: “2014-10-23T09:00:00” for a user whose local time is 9AM. If there were no featured
/// playlists (or there is no data) at the specified time, the response will revert to the
/// current UTC time.</param>
/// <param name="timestamp">Optional. Use this parameter to specify the user’s local time to
/// get results tailored for that specific date and time in the day. If not provided, the response
/// defaults to the current UTC time. If there were no featured playlists (or there is no data)
/// at the specified time, the response will revert to the current UTC time.</param>
/// <param name="limit">Optional. Maximum number of results to return. Default: 20, Minimum: 1,
/// Maximum: 50.</param>
/// <param name="offset">Optional. The index of the first result to return. Default: 0 (the
Expand All @@ -208,7 +205,7 @@ Task<FeaturedPlaylists> GetFeaturedPlaylists(
Task<T> GetFeaturedPlaylists<T>(
string country = null,
string locale = null,
string timestamp = null,
DateTime? timestamp = null,
int? limit = null,
int offset = 0,
string accessToken = null);
Expand Down
2 changes: 1 addition & 1 deletion src/SpotifyApi.NetCore/Models/PagedPlaylists.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace SpotifyApi.NetCore
{
public class PagedPlaylists : Paged<Playlist>
public class PagedPlaylists : Paged<PlaylistSimplified>
{
}
}
2 changes: 1 addition & 1 deletion src/SpotifyApi.NetCore/SpotifyApi.NetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<PackageId>SpotifyApi.NetCore</PackageId>
<Title>Spotify Web API .NET Core</Title>
<Description>Lightweight .NET Core client wrapper for the Spotify Web API</Description>
<Version>3.1.0-preview</Version>
<Version>3.1.0</Version>
<Authors>Daniel Larsen and contributors</Authors>
<Company>Ringobot</Company>
<Copyright>Copyright 2020 Daniel Larsen and contributors</Copyright>
Expand Down

0 comments on commit 03871a5

Please sign in to comment.