Skip to content

Commit

Permalink
Merge pull request #506 from henrikfroehling/issue/release-1.4.0/GH-461
Browse files Browse the repository at this point in the history
Resolves GH-461
  • Loading branch information
henrikfroehling authored May 24, 2023
2 parents d306323 + 61f7640 commit b4fee5c
Show file tree
Hide file tree
Showing 54 changed files with 415 additions and 335 deletions.
33 changes: 33 additions & 0 deletions Source/Lib/Trakt.NET/Enums/TraktListPrivacy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace TraktNet.Enums
{
/// <summary>Determines the privacy of a list.</summary>
public sealed class TraktListPrivacy : TraktEnumeration
{
/// <summary>An invalid privacy type.</summary>
public static TraktListPrivacy Unspecified { get; } = new TraktListPrivacy();

/// <summary>The list is private. Only the user who created the list can see it.</summary>
public static TraktListPrivacy Private { get; } = new TraktListPrivacy(1, "private", "private", "Private");

/// <summary>The list is only viewable by a shared link.</summary>
public static TraktListPrivacy Link { get; } = new TraktListPrivacy(2, "link", "link", "Link");

/// <summary>The list can only be seen by friends.</summary>
public static TraktListPrivacy Friends { get; } = new TraktListPrivacy(4, "friends", "friends", "Friends");

/// <summary>The list is public and anyone can see it.</summary>
public static TraktListPrivacy Public { get; } = new TraktListPrivacy(8, "public", "public", "Public");

/// <summary>
/// Initializes a new instance of the <see cref="TraktListPrivacy" /> class.<para />
/// The initialized <see cref="TraktListPrivacy" /> is invalid.
/// </summary>
public TraktListPrivacy()
{
}

private TraktListPrivacy(int value, string objectName, string uriName, string displayName) : base(value, objectName, uriName, displayName)
{
}
}
}
4 changes: 2 additions & 2 deletions Source/Lib/Trakt.NET/Objects/Get/Lists/ITraktList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public interface ITraktList
/// <summary>Gets or sets the list description.<para>Nullable</para></summary>
string Description { get; set; }

/// <summary>Gets or sets the list's visibility status. See also <seealso cref="TraktAccessScope" />.<para>Nullable</para></summary>
TraktAccessScope Privacy { get; set; }
/// <summary>Gets or sets the list's visibility status. See also <seealso cref="TraktListPrivacy" />.<para>Nullable</para></summary>
TraktListPrivacy Privacy { get; set; }

/// <summary>Gets or sets, whether the list displays ranking numbers.</summary>
bool? DisplayNumbers { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class TraktList : ITraktList
/// <summary>Gets or sets the list description.<para>Nullable</para></summary>
public string Description { get; set; }

/// <summary>Gets or sets the list's visibility status. See also <seealso cref="TraktAccessScope" />.<para>Nullable</para></summary>
public TraktAccessScope Privacy { get; set; }
/// <summary>Gets or sets the list's visibility status. See also <seealso cref="TraktListPrivacy" />.<para>Nullable</para></summary>
public TraktListPrivacy Privacy { get; set; }

/// <summary>Gets or sets, whether the list displays ranking numbers.</summary>
public bool? DisplayNumbers { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public override async Task<ITraktList> ReadObjectAsync(JsonTextReader jsonReader
traktList.Description = await jsonReader.ReadAsStringAsync(cancellationToken);
break;
case JsonProperties.PROPERTY_NAME_PRIVACY:
traktList.Privacy = await JsonReaderHelper.ReadEnumerationValueAsync<TraktAccessScope>(jsonReader, cancellationToken);
traktList.Privacy = await JsonReaderHelper.ReadEnumerationValueAsync<TraktListPrivacy>(jsonReader, cancellationToken);
break;
case JsonProperties.PROPERTY_NAME_DISPLAY_NUMBERS:
traktList.DisplayNumbers = await jsonReader.ReadAsBooleanAsync(cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ public interface ITraktUserPersonalListPost : IRequestBody

/// <summary>
/// Gets or sets the optional privacy setting of the personal list.
/// See also <seealso cref="TraktAccessScope" />.
/// See also <seealso cref="TraktListPrivacy" />.
/// <para>Nullable</para>
/// </summary>
TraktAccessScope Privacy { get; set; }
TraktListPrivacy Privacy { get; set; }

/// <summary>Gets or sets, whether the personal list should display numbers.</summary>
bool? DisplayNumbers { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ public class TraktUserPersonalListPost : ITraktUserPersonalListPost

/// <summary>
/// Gets or sets the optional privacy setting of the custom list.
/// See also <seealso cref="TraktAccessScope" />.
/// See also <seealso cref="TraktListPrivacy" />.
/// <para>Nullable</para>
/// </summary>
public TraktAccessScope Privacy { get; set; }
public TraktListPrivacy Privacy { get; set; }

/// <summary>Gets or sets, whether the custom list should display numbers.</summary>
public bool? DisplayNumbers { get; set; }
Expand Down Expand Up @@ -56,15 +56,15 @@ public void Validate()
if (Name.Length == 0)
throw new TraktPostValidationException(nameof(Name), "list name must not be empty");

if (Privacy != null && Privacy == TraktAccessScope.Unspecified)
if (Privacy != null && Privacy == TraktListPrivacy.Unspecified)
throw new TraktPostValidationException(nameof(Privacy), "Privacy must not be unspecified");
}

/// <summary>Returns whether the post has any values set.</summary>
public bool HasAnyValuesSet()
{
return !string.IsNullOrEmpty(Name) || !string.IsNullOrEmpty(Description)
|| (Privacy != null && Privacy != TraktAccessScope.Unspecified)
|| (Privacy != null && Privacy != TraktListPrivacy.Unspecified)
|| DisplayNumbers.HasValue || AllowComments.HasValue
|| (SortBy != null && SortBy != TraktSortBy.Unspecified)
|| (SortHow != null && SortHow != TraktSortHow.Unspecified);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override async Task<ITraktUserPersonalListPost> ReadObjectAsync(JsonTextR
userPersonalListPost.Description = await jsonReader.ReadAsStringAsync(cancellationToken);
break;
case JsonProperties.PROPERTY_NAME_PRIVACY:
userPersonalListPost.Privacy = await JsonReaderHelper.ReadEnumerationValueAsync<TraktAccessScope>(jsonReader, cancellationToken);
userPersonalListPost.Privacy = await JsonReaderHelper.ReadEnumerationValueAsync<TraktListPrivacy>(jsonReader, cancellationToken);
break;
case JsonProperties.PROPERTY_NAME_DISPLAY_NUMBERS:
userPersonalListPost.DisplayNumbers = await jsonReader.ReadAsBooleanAsync(cancellationToken);
Expand Down
47 changes: 47 additions & 0 deletions Source/Tests/Trakt.NET.Core.Tests/Enums/TraktListPrivacy_Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
namespace TraktNet.Core.Tests.Enums
{
using FluentAssertions;
using System.Collections.Generic;
using Trakt.NET.Tests.Utility.Traits;
using TraktNet.Enums;
using Xunit;

[TestCategory("Enums")]
public class TraktListPrivacy_Tests
{
[Fact]
public void Test_TraktListPrivacy_GetAll()
{
var allValues = TraktEnumeration.GetAll<TraktListPrivacy>();

allValues.Should().NotBeNull().And.HaveCount(5);
allValues.Should().Contain(new List<TraktListPrivacy>() { TraktListPrivacy.Unspecified, TraktListPrivacy.Private,
TraktListPrivacy.Link, TraktListPrivacy.Friends,
TraktListPrivacy.Public });
}

[Fact]
public void Test_TraktListPrivacy_Properties()
{
TraktListPrivacy.Private.Value.Should().Be(1);
TraktListPrivacy.Private.ObjectName.Should().Be("private");
TraktListPrivacy.Private.UriName.Should().Be("private");
TraktListPrivacy.Private.DisplayName.Should().Be("Private");

TraktListPrivacy.Link.Value.Should().Be(2);
TraktListPrivacy.Link.ObjectName.Should().Be("link");
TraktListPrivacy.Link.UriName.Should().Be("link");
TraktListPrivacy.Link.DisplayName.Should().Be("Link");

TraktListPrivacy.Friends.Value.Should().Be(4);
TraktListPrivacy.Friends.ObjectName.Should().Be("friends");
TraktListPrivacy.Friends.UriName.Should().Be("friends");
TraktListPrivacy.Friends.DisplayName.Should().Be("Friends");

TraktListPrivacy.Public.Value.Should().Be(8);
TraktListPrivacy.Public.ObjectName.Should().Be("public");
TraktListPrivacy.Public.UriName.Should().Be("public");
TraktListPrivacy.Public.DisplayName.Should().Be("Public");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public async Task Test_TraktListsModule_GetList()
responseValue.Should().NotBeNull();
responseValue.Name.Should().Be("Star Wars in machete order");
responseValue.Description.Should().Be("Next time you want to introduce someone to Star Wars for the first time, watch the films with them in this order: IV, V, II, III, VI.");
responseValue.Privacy.Should().Be(TraktAccessScope.Public);
responseValue.Privacy.Should().Be(TraktListPrivacy.Public);
responseValue.DisplayNumbers.Should().BeTrue();
responseValue.AllowComments.Should().BeFalse();
responseValue.SortBy.Should().Be("rank");
Expand Down
Loading

0 comments on commit b4fee5c

Please sign in to comment.