-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
83f0149
commit 5dffe28
Showing
11 changed files
with
271 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace TraktNET | ||
{ | ||
public class TraktUser : TraktUserMinimal | ||
{ | ||
public DateTime? JoinedAt { get; set; } | ||
|
||
public string? Location { get; set; } | ||
|
||
public string? About { get; set; } | ||
|
||
public TraktGender? Gender { get; set; } | ||
|
||
public uint? Age { get; set; } | ||
|
||
public TraktUserImages? Images { get; set; } | ||
|
||
[JsonPropertyName("vip_og")] | ||
public bool? VIPOG { get; set; } | ||
|
||
public uint? VIPYears { get; set; } | ||
|
||
public string? VIPCoverImage { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace TraktNET | ||
{ | ||
public class TraktUserIds : ITraktIds | ||
{ | ||
public string? Slug { get; set; } | ||
|
||
[JsonPropertyName("uuid")] | ||
public string? UUID { get; set; } | ||
|
||
[JsonIgnore] | ||
public bool HasAnyID => !string.IsNullOrWhiteSpace(Slug) || !string.IsNullOrWhiteSpace(UUID); | ||
|
||
[JsonIgnore] | ||
public string BestID | ||
{ | ||
get | ||
{ | ||
if (!HasAnyID) | ||
return string.Empty; | ||
|
||
if (!string.IsNullOrWhiteSpace(Slug)) | ||
return Slug!; | ||
|
||
if (!string.IsNullOrWhiteSpace(UUID)) | ||
return UUID!; | ||
|
||
return string.Empty; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace TraktNET | ||
{ | ||
public class TraktUserImages | ||
{ | ||
public TraktUserImagesAvatar? Avatar { get; set; } | ||
} | ||
|
||
public class TraktUserImagesAvatar | ||
{ | ||
public string? Full { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace TraktNET | ||
{ | ||
public class TraktUserMinimal | ||
{ | ||
public string? Username { get; set; } | ||
|
||
public bool? Private { get; set; } | ||
|
||
public string? Name { get; set; } | ||
|
||
public bool? VIP { get; set; } | ||
|
||
[JsonPropertyName("vip_ep")] | ||
public bool? VIPEP { get; set; } | ||
|
||
public TraktUserIds? Ids { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"username": "ixxus", | ||
"private": false, | ||
"name": "Henrik", | ||
"vip": true, | ||
"vip_ep": false, | ||
"ids": { | ||
"slug": "ixxus", | ||
"uuid": "jljgsagj092ß9u0294jlgalngoi0t0qntggnafng82" | ||
}, | ||
"joined_at": "2015-02-18T12:54:39.000Z", | ||
"location": "Germany", | ||
"about": "", | ||
"gender": "male", | ||
"age": 36, | ||
"images": { | ||
"avatar": { | ||
"full": "https://walter.trakt.tv/images/users/000/894/246/avatars/large/754b7e3761.png" | ||
} | ||
}, | ||
"vip_og": false, | ||
"vip_years": 6, | ||
"vip_cover_image": "https://walter.trakt.tv/images/shows/000/043/973/fanarts/full/eb3a126015.jpg" | ||
} |
11 changes: 11 additions & 0 deletions
11
src/tests/Trakt.NET.Json.Tests/JsonData/Users/user_minimal.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"username": "ixxus", | ||
"private": false, | ||
"name": "Henrik", | ||
"vip": true, | ||
"vip_ep": false, | ||
"ids": { | ||
"slug": "ixxus", | ||
"uuid": "jljgsagj092ß9u0294jlgalngoi0t0qntggnafng82" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"slug": "ixxus", | ||
"uuid": "jljgsagj092ß9u0294jlgalngoi0t0qntggnafng82" | ||
} |
5 changes: 5 additions & 0 deletions
5
src/tests/Trakt.NET.Json.Tests/JsonData/Users/userimages.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"avatar": { | ||
"full": "https://walter.trakt.tv/images/users/000/894/246/avatars/large/754b7e3761.png" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
namespace TraktNET.Json.Users | ||
{ | ||
public sealed class TraktUserIdsTests | ||
{ | ||
[Fact] | ||
public void TestTraktUserIdsConstructor() | ||
{ | ||
var userIds = new TraktUserIds(); | ||
|
||
userIds.Slug.Should().BeNull(); | ||
userIds.UUID.Should().BeNull(); | ||
|
||
userIds.HasAnyID.Should().BeFalse(); | ||
userIds.BestID.Should().BeEmpty(); | ||
} | ||
|
||
[Fact] | ||
public async Task TestTraktUserIdsFromJson() | ||
{ | ||
TraktUserIds? userIds = await TestUtility.DeserializeJsonAsync<TraktUserIds>("Users\\userids.json"); | ||
|
||
userIds.Should().NotBeNull(); | ||
|
||
userIds!.Slug.Should().Be("ixxus"); | ||
userIds!.UUID.Should().Be("jljgsagj092ß9u0294jlgalngoi0t0qntggnafng82"); | ||
|
||
userIds!.HasAnyID.Should().BeTrue(); | ||
userIds!.BestID.Should().Be("ixxus"); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/tests/Trakt.NET.Json.Tests/Users/TraktUserImagesTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
namespace TraktNET.Json.Users | ||
{ | ||
public sealed class TraktUserImagesTests | ||
{ | ||
[Fact] | ||
public void TestTraktUserImagesConstructor() | ||
{ | ||
var userImages = new TraktUserImages(); | ||
|
||
userImages.Avatar.Should().BeNull(); | ||
} | ||
|
||
[Fact] | ||
public async Task TestTraktUserImagesFromJson() | ||
{ | ||
TraktUserImages? userImages = await TestUtility.DeserializeJsonAsync<TraktUserImages>("Users\\userimages.json"); | ||
|
||
userImages.Should().NotBeNull(); | ||
|
||
userImages!.Avatar.Should().NotBeNull(); | ||
userImages!.Avatar!.Full.Should().Be("https://walter.trakt.tv/images/users/000/894/246/avatars/large/754b7e3761.png"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
namespace TraktNET.Json.Users | ||
{ | ||
public sealed class TraktUserTests | ||
{ | ||
[Fact] | ||
public void TestTraktUserConstructor() | ||
{ | ||
var user = new TraktUser(); | ||
|
||
user.Username.Should().BeNull(); | ||
user.Private.Should().BeNull(); | ||
user.Name.Should().BeNull(); | ||
user.VIP.Should().BeNull(); | ||
user.VIPEP.Should().BeNull(); | ||
user.Ids.Should().BeNull(); | ||
user.JoinedAt.Should().BeNull(); | ||
user.Location.Should().BeNull(); | ||
user.About.Should().BeNull(); | ||
user.Gender.Should().BeNull(); | ||
user.Age.Should().BeNull(); | ||
user.Images.Should().BeNull(); | ||
user.VIPOG.Should().BeNull(); | ||
user.VIPYears.Should().BeNull(); | ||
user.VIPCoverImage.Should().BeNull(); | ||
} | ||
|
||
[Fact] | ||
public async Task TestTraktUserFromJsonMinimal() | ||
{ | ||
TraktUserMinimal? user = await TestUtility.DeserializeJsonAsync<TraktUserMinimal>("Users\\user_minimal.json"); | ||
|
||
user.Should().NotBeNull(); | ||
|
||
user!.Username.Should().Be("ixxus"); | ||
user!.Private.Should().BeFalse(); | ||
user!.Name.Should().Be("Henrik"); | ||
user!.VIP.Should().BeTrue(); | ||
user!.VIPEP.Should().BeFalse(); | ||
|
||
user!.Ids.Should().NotBeNull(); | ||
user!.Ids!.Slug.Should().Be("ixxus"); | ||
user!.Ids!.UUID.Should().Be("jljgsagj092ß9u0294jlgalngoi0t0qntggnafng82"); | ||
user!.Ids!.HasAnyID.Should().BeTrue(); | ||
user!.Ids!.BestID.Should().Be("ixxus"); | ||
} | ||
|
||
[Fact] | ||
public async Task TestTraktUserFromJson() | ||
{ | ||
TraktUser? user = await TestUtility.DeserializeJsonAsync<TraktUser>("Users\\user.json"); | ||
|
||
user.Should().NotBeNull(); | ||
|
||
user!.Username.Should().Be("ixxus"); | ||
user!.Private.Should().BeFalse(); | ||
user!.Name.Should().Be("Henrik"); | ||
user!.VIP.Should().BeTrue(); | ||
user!.VIPEP.Should().BeFalse(); | ||
|
||
user!.Ids.Should().NotBeNull(); | ||
user!.Ids!.Slug.Should().Be("ixxus"); | ||
user!.Ids!.UUID.Should().Be("jljgsagj092ß9u0294jlgalngoi0t0qntggnafng82"); | ||
user!.Ids!.HasAnyID.Should().BeTrue(); | ||
user!.Ids!.BestID.Should().Be("ixxus"); | ||
|
||
user!.JoinedAt.Should().Be(TestUtility.ParseUTCDateTime("2015-02-18T12:54:39.000Z")); | ||
user!.Location.Should().Be("Germany"); | ||
user!.About.Should().BeEmpty(); | ||
user!.Gender.Should().Be(TraktGender.Male); | ||
user!.Age.Should().Be(36U); | ||
|
||
user!.Images.Should().NotBeNull(); | ||
user!.Images!.Avatar.Should().NotBeNull(); | ||
user!.Images!.Avatar!.Full.Should().Be("https://walter.trakt.tv/images/users/000/894/246/avatars/large/754b7e3761.png"); | ||
|
||
user!.VIPOG.Should().BeFalse(); | ||
user!.VIPYears.Should().Be(6U); | ||
user!.VIPCoverImage.Should().Be("https://walter.trakt.tv/images/shows/000/043/973/fanarts/full/eb3a126015.jpg"); | ||
} | ||
} | ||
} |