Skip to content

Commit 03871a5

Browse files
Tests. GetFeaturedPlaylists -> Timestamp DateTime. PagedPlaylists -> Paged<PlaylistSimplified>
1 parent fdcfd50 commit 03871a5

File tree

7 files changed

+109
-32
lines changed

7 files changed

+109
-32
lines changed

src/SpotifyApi.NetCore.Tests/BrowseApiTests.cs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,71 @@ namespace SpotifyApi.NetCore.Tests
1212
[TestClass]
1313
public class BrowseApiTests
1414
{
15+
[TestMethod]
16+
[TestCategory("Integration")]
17+
public async Task GetCategories_Limit2_ItemsLength2()
18+
{
19+
// arrange
20+
var http = new HttpClient();
21+
var accounts = new AccountsService(http, TestsHelper.GetLocalConfig());
22+
23+
var api = new BrowseApi(http, accounts);
24+
25+
// act
26+
var response = await api.GetCategories(limit:2);
27+
Assert.AreEqual(2, response.Items.Length);
28+
}
29+
30+
[TestMethod]
31+
[TestCategory("Integration")]
32+
public async Task GetCategory_FromNZCategories_SameCategoryHref()
33+
{
34+
// arrange
35+
var http = new HttpClient();
36+
var accounts = new AccountsService(http, TestsHelper.GetLocalConfig());
37+
38+
var api = new BrowseApi(http, accounts);
39+
var category = (await api.GetCategories(limit: 1, country:SpotifyCountryCodes.New_Zealand)).Items[0];
40+
41+
// act
42+
var response = await api.GetCategory(category.Id, country:SpotifyCountryCodes.New_Zealand);
43+
44+
Assert.AreEqual(category.Href, response.Href);
45+
}
46+
47+
[TestMethod]
48+
[TestCategory("Integration")]
49+
public async Task GetCategoryPlaylists_FromFirstNZCategoryLimit2_ItemsLength2()
50+
{
51+
// arrange
52+
var http = new HttpClient();
53+
var accounts = new AccountsService(http, TestsHelper.GetLocalConfig());
54+
55+
var api = new BrowseApi(http, accounts);
56+
var category = (await api.GetCategories(limit: 1, country: SpotifyCountryCodes.New_Zealand)).Items[0];
57+
58+
// act
59+
var response = await api.GetCategoryPlaylists(category.Id, country: SpotifyCountryCodes.New_Zealand, limit: 2);
60+
61+
Assert.AreEqual(2, response.Items.Length);
62+
}
63+
64+
[TestMethod]
65+
[TestCategory("Integration")]
66+
public async Task GetFeaturedPlaylists_Limit2_ItemsLength2()
67+
{
68+
// arrange
69+
var http = new HttpClient();
70+
var accounts = new AccountsService(http, TestsHelper.GetLocalConfig());
71+
72+
var api = new BrowseApi(http, accounts);
73+
74+
// act
75+
var response = await api.GetFeaturedPlaylists(country: SpotifyCountryCodes.New_Zealand, limit: 2);
76+
77+
Assert.AreEqual(2, response.Items.Length);
78+
}
79+
1580
[TestMethod]
1681
[TestCategory("Integration")]
1782
public async Task GetNewReleases_NoParams_NoError()

src/SpotifyApi.NetCore.Tests/Extensions/UriBuilderExtensionTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,5 +144,18 @@ public void AppendToQueryAsCsv_ThreeValues_WellFormed()
144144
Assert.AreEqual("?numbers=1,2,3", builder.Uri.Query);
145145
}
146146

147+
[TestMethod]
148+
public void AppendToQueryAsTimestampIso8601_DateTime_ExpectedFormat()
149+
{
150+
// arrange
151+
var builder = new UriBuilder("https://api.spotify.com/v1/browse/featured-playlists");
152+
153+
// act
154+
builder.AppendToQueryAsTimestampIso8601("timestamp", new DateTime(2014, 10, 23, 9, 0, 0));
155+
156+
// assert
157+
Assert.AreEqual("?timestamp=2014-10-23T09:00:00", builder.Uri.Query);
158+
}
159+
147160
}
148161
}

src/SpotifyApi.NetCore/BrowseApi.cs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,10 @@ public async Task<T> GetCategoryPlaylists<T>(
232232
/// in a particular language. Note that, if locale is not supplied, or if the specified language
233233
/// is not available, the category strings returned will be in the Spotify default language
234234
/// (American English).</param>
235-
/// <param name="timestamp">Optional. A timestamp in ISO 8601 format: yyyy-MM-ddTHH:mm:ss.
236-
/// Use this parameter to specify the user’s local time to get results tailored for that specific
237-
/// date and time in the day. If not provided, the response defaults to the current UTC time.
238-
/// Example: “2014-10-23T09:00:00” for a user whose local time is 9AM. If there were no featured
239-
/// playlists (or there is no data) at the specified time, the response will revert to the
240-
/// current UTC time.</param>
235+
/// <param name="timestamp">Optional. Use this parameter to specify the user’s local time to
236+
/// get results tailored for that specific date and time in the day. If not provided, the response
237+
/// defaults to the current UTC time. If there were no featured playlists (or there is no data)
238+
/// at the specified time, the response will revert to the current UTC time.</param>
241239
/// <param name="limit">Optional. Maximum number of results to return. Default: 20, Minimum: 1,
242240
/// Maximum: 50.</param>
243241
/// <param name="offset">Optional. The index of the first result to return. Default: 0 (the
@@ -249,7 +247,7 @@ public async Task<T> GetCategoryPlaylists<T>(
249247
public Task<FeaturedPlaylists> GetFeaturedPlaylists(
250248
string country = null,
251249
string locale = null,
252-
string timestamp = null,
250+
DateTime? timestamp = null,
253251
int? limit = null,
254252
int offset = 0,
255253
string accessToken = null) => GetFeaturedPlaylists<FeaturedPlaylists>(
@@ -272,12 +270,10 @@ public Task<FeaturedPlaylists> GetFeaturedPlaylists(
272270
/// in a particular language. Note that, if locale is not supplied, or if the specified language
273271
/// is not available, the category strings returned will be in the Spotify default language
274272
/// (American English).</param>
275-
/// <param name="timestamp">Optional. A timestamp in ISO 8601 format: yyyy-MM-ddTHH:mm:ss.
276-
/// Use this parameter to specify the user’s local time to get results tailored for that specific
277-
/// date and time in the day. If not provided, the response defaults to the current UTC time.
278-
/// Example: “2014-10-23T09:00:00” for a user whose local time is 9AM. If there were no featured
279-
/// playlists (or there is no data) at the specified time, the response will revert to the
280-
/// current UTC time.</param>
273+
/// <param name="timestamp">Optional. Use this parameter to specify the user’s local time to
274+
/// get results tailored for that specific date and time in the day. If not provided, the response
275+
/// defaults to the current UTC time. If there were no featured playlists (or there is no data)
276+
/// at the specified time, the response will revert to the current UTC time.</param>
281277
/// <param name="limit">Optional. Maximum number of results to return. Default: 20, Minimum: 1,
282278
/// Maximum: 50.</param>
283279
/// <param name="offset">Optional. The index of the first result to return. Default: 0 (the
@@ -288,16 +284,16 @@ public Task<FeaturedPlaylists> GetFeaturedPlaylists(
288284
/// <remarks> https://developer.spotify.com/documentation/web-api/reference/browse/get-list-featured-playlists/ </remarks>
289285
public async Task<T> GetFeaturedPlaylists<T>(
290286
string country = null,
291-
string locale = null,
292-
string timestamp = null,
287+
string locale = null,
288+
DateTime? timestamp = null,
293289
int? limit = null,
294290
int offset = 0,
295291
string accessToken = null)
296292
{
297293
var builder = new UriBuilder($"{BaseUrl}/browse/featured-playlists");
298294
builder.AppendToQueryIfValueNotNullOrWhiteSpace("country", country);
299295
builder.AppendToQueryIfValueNotNullOrWhiteSpace("locale", locale);
300-
builder.AppendToQueryIfValueNotNullOrWhiteSpace("timestamp", timestamp);
296+
builder.AppendToQueryAsTimestampIso8601("timestamp", timestamp);
301297
builder.AppendToQueryIfValueGreaterThan0("limit", limit);
302298
builder.AppendToQueryIfValueGreaterThan0("offset", offset);
303299
return await GetModelFromProperty<T>(builder.Uri, "playlists", accessToken: accessToken);

src/SpotifyApi.NetCore/Extensions/UriBuilderExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Globalization;
23

34
namespace SpotifyApi.NetCore
45
{
@@ -42,5 +43,10 @@ public static void AppendToQueryIfValueNotNullOrWhiteSpace(
4243
{
4344
if (!string.IsNullOrWhiteSpace(value)) AppendToQuery(builder, name, value);
4445
}
46+
47+
public static void AppendToQueryAsTimestampIso8601(this UriBuilder builder, string name, DateTime? timestamp)
48+
{
49+
if (timestamp.HasValue) AppendToQuery(builder, name, timestamp.Value.ToString("s", CultureInfo.InvariantCulture));
50+
}
4551
}
4652
}

src/SpotifyApi.NetCore/IBrowseApi.cs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Threading.Tasks;
23

34
namespace SpotifyApi.NetCore
@@ -157,12 +158,10 @@ Task<T> GetCategoryPlaylists<T>(
157158
/// in a particular language. Note that, if locale is not supplied, or if the specified language
158159
/// is not available, the category strings returned will be in the Spotify default language
159160
/// (American English).</param>
160-
/// <param name="timestamp">Optional. A timestamp in ISO 8601 format: yyyy-MM-ddTHH:mm:ss.
161-
/// Use this parameter to specify the user’s local time to get results tailored for that specific
162-
/// date and time in the day. If not provided, the response defaults to the current UTC time.
163-
/// Example: “2014-10-23T09:00:00” for a user whose local time is 9AM. If there were no featured
164-
/// playlists (or there is no data) at the specified time, the response will revert to the
165-
/// current UTC time.</param>
161+
/// <param name="timestamp">Optional. Use this parameter to specify the user’s local time to
162+
/// get results tailored for that specific date and time in the day. If not provided, the response
163+
/// defaults to the current UTC time. If there were no featured playlists (or there is no data)
164+
/// at the specified time, the response will revert to the current UTC time.</param>
166165
/// <param name="limit">Optional. Maximum number of results to return. Default: 20, Minimum: 1,
167166
/// Maximum: 50.</param>
168167
/// <param name="offset">Optional. The index of the first result to return. Default: 0 (the
@@ -174,7 +173,7 @@ Task<T> GetCategoryPlaylists<T>(
174173
Task<FeaturedPlaylists> GetFeaturedPlaylists(
175174
string country = null,
176175
string locale = null,
177-
string timestamp = null,
176+
DateTime? timestamp = null,
178177
int? limit = null,
179178
int offset = 0,
180179
string accessToken = null);
@@ -191,12 +190,10 @@ Task<FeaturedPlaylists> GetFeaturedPlaylists(
191190
/// in a particular language. Note that, if locale is not supplied, or if the specified language
192191
/// is not available, the category strings returned will be in the Spotify default language
193192
/// (American English).</param>
194-
/// <param name="timestamp">Optional. A timestamp in ISO 8601 format: yyyy-MM-ddTHH:mm:ss.
195-
/// Use this parameter to specify the user’s local time to get results tailored for that specific
196-
/// date and time in the day. If not provided, the response defaults to the current UTC time.
197-
/// Example: “2014-10-23T09:00:00” for a user whose local time is 9AM. If there were no featured
198-
/// playlists (or there is no data) at the specified time, the response will revert to the
199-
/// current UTC time.</param>
193+
/// <param name="timestamp">Optional. Use this parameter to specify the user’s local time to
194+
/// get results tailored for that specific date and time in the day. If not provided, the response
195+
/// defaults to the current UTC time. If there were no featured playlists (or there is no data)
196+
/// at the specified time, the response will revert to the current UTC time.</param>
200197
/// <param name="limit">Optional. Maximum number of results to return. Default: 20, Minimum: 1,
201198
/// Maximum: 50.</param>
202199
/// <param name="offset">Optional. The index of the first result to return. Default: 0 (the
@@ -208,7 +205,7 @@ Task<FeaturedPlaylists> GetFeaturedPlaylists(
208205
Task<T> GetFeaturedPlaylists<T>(
209206
string country = null,
210207
string locale = null,
211-
string timestamp = null,
208+
DateTime? timestamp = null,
212209
int? limit = null,
213210
int offset = 0,
214211
string accessToken = null);

src/SpotifyApi.NetCore/Models/PagedPlaylists.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace SpotifyApi.NetCore
44
{
5-
public class PagedPlaylists : Paged<Playlist>
5+
public class PagedPlaylists : Paged<PlaylistSimplified>
66
{
77
}
88
}

src/SpotifyApi.NetCore/SpotifyApi.NetCore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<PackageId>SpotifyApi.NetCore</PackageId>
55
<Title>Spotify Web API .NET Core</Title>
66
<Description>Lightweight .NET Core client wrapper for the Spotify Web API</Description>
7-
<Version>3.1.0-preview</Version>
7+
<Version>3.1.0</Version>
88
<Authors>Daniel Larsen and contributors</Authors>
99
<Company>Ringobot</Company>
1010
<Copyright>Copyright 2020 Daniel Larsen and contributors</Copyright>

0 commit comments

Comments
 (0)