Skip to content

Commit

Permalink
Merge pull request #628 from henrikfroehling/issue/release-1.4.0/GH-622
Browse files Browse the repository at this point in the history
Resolves GH-622
  • Loading branch information
henrikfroehling authored Mar 18, 2024
2 parents c19146e + ff102e2 commit fbcf5dc
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 0 deletions.
42 changes: 42 additions & 0 deletions Source/Lib/Trakt.NET/Enums/TraktEpisodeType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
namespace TraktNet.Enums
{
/// <summary>Determines the type of an episode.</summary>
public sealed class TraktEpisodeType : TraktEnumeration
{
/// <summary>An invalid episode type.</summary>
public static TraktEpisodeType Unspecified { get; } = new TraktEpisodeType();

/// <summary>The type for a standard episode.</summary>
public static TraktEpisodeType Standard { get; } = new TraktEpisodeType(1, "standard", "standard", "Standard");

/// <summary>The type for a series premiere episode (season 1, episode 1).</summary>
public static TraktEpisodeType SeriesPremiere { get; } = new TraktEpisodeType(2, "series_premiere", "series_premiere", "Series Premiere");

/// <summary>The type for a season premiere episode (episode 1).</summary>
public static TraktEpisodeType SeasonPremiere { get; } = new TraktEpisodeType(4, "season_premiere", "season_premiere", "Season Premiere");

/// <summary>The type for a mid season finale episode.</summary>
public static TraktEpisodeType MidSeasonFinale { get; } = new TraktEpisodeType(8, "mid_season_finale", "mid_season_finale", "Mid Season Finale");

/// <summary>The type for a mid season premiere episode (the next episode after the mid season finale).</summary>
public static TraktEpisodeType MidSeasonPremiere { get; } = new TraktEpisodeType(16, "mid_season_premiere", "mid_season_premiere", "Mid Season Premiere");

/// <summary>The type for a season finale episode.</summary>
public static TraktEpisodeType SeasonFinale { get; } = new TraktEpisodeType(32, "season_finale", "season_finale", "Season Finale");

/// <summary>The type for a series finale episode (last episode to air for an ended show).</summary>
public static TraktEpisodeType SeriesFinale { get; } = new TraktEpisodeType(64, "series_finale", "series_finale", "Series Finale");

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

private TraktEpisodeType(int value, string objectName, string uriName, string displayName) : base(value, objectName, uriName, displayName)
{
}
}
}
4 changes: 4 additions & 0 deletions Source/Lib/Trakt.NET/Objects/Get/Episodes/ITraktEpisode.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace TraktNet.Objects.Get.Episodes
{
using Enums;
using Get.Seasons;
using Modules;
using System;
Expand Down Expand Up @@ -66,5 +67,8 @@ public interface ITraktEpisode

/// <summary>Gets or sets the comment count of the episode.<para>Nullable</para></summary>
int? CommentCount { get; set; }

/// <summary>Gets or sets the episode type. See also <seealso cref="TraktEpisodeType" />.<para>Nullable</para></summary>
TraktEpisodeType EpisodeType { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace TraktNet.Objects.Get.Episodes
{
using Enums;
using Modules;
using Seasons;
using System;
Expand Down Expand Up @@ -66,5 +67,8 @@ public class TraktEpisode : ITraktEpisode

/// <summary>Gets or sets the comment count of the episode.<para>Nullable</para></summary>
public int? CommentCount { get; set; }

/// <summary>Gets or sets the episode type. See also <seealso cref="TraktEpisodeType" />.<para>Nullable</para></summary>
public TraktEpisodeType EpisodeType { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace TraktNet.Objects.Get.Episodes.Json.Reader
{
using Enums;
using Newtonsoft.Json;
using Objects.Json;
using System.Threading;
Expand Down Expand Up @@ -77,6 +78,9 @@ public override async Task<ITraktEpisode> ReadObjectAsync(JsonTextReader jsonRea
case JsonProperties.PROPERTY_NAME_COMMENT_COUNT:
traktEpisode.CommentCount = await jsonReader.ReadAsInt32Async(cancellationToken);
break;
case JsonProperties.PROPERTY_NAME_EPISODE_TYPE:
traktEpisode.EpisodeType = await JsonReaderHelper.ReadEnumerationValueAsync<TraktEpisodeType>(jsonReader, cancellationToken);
break;
default:
await JsonReaderHelper.ReadAndIgnoreInvalidContentAsync(jsonReader, cancellationToken);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktEpi
await jsonWriter.WriteValueAsync(obj.CommentCount, cancellationToken).ConfigureAwait(false);
}

if (obj.EpisodeType != null)
{
await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_EPISODE_TYPE, cancellationToken).ConfigureAwait(false);
await jsonWriter.WriteValueAsync(obj.EpisodeType.ObjectName, cancellationToken).ConfigureAwait(false);
}

await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
}
}
Expand Down
1 change: 1 addition & 0 deletions Source/Lib/Trakt.NET/Objects/Json/JsonProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ internal static class JsonProperties
internal const string PROPERTY_NAME_EDITING = "editing";
internal const string PROPERTY_NAME_EPISODE = "episode";
internal const string PROPERTY_NAME_EPISODE_COUNT = "episode_count";
internal const string PROPERTY_NAME_EPISODE_TYPE = "episode_type";
internal const string PROPERTY_NAME_EPISODES = "episodes";
internal const string PROPERTY_NAME_ERROR = "error";
internal const string PROPERTY_NAME_ERROR_DESCRIPTION = "error_description";
Expand Down
63 changes: 63 additions & 0 deletions Source/Tests/Trakt.NET.Core.Tests/Enums/TraktEpisodeType_Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
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 TraktEpisodeType_Tests
{
[Fact]
public void Test_TraktEpisodeType_GetAll()
{
var allValues = TraktEnumeration.GetAll<TraktEpisodeType>();

allValues.Should().NotBeNull().And.HaveCount(8);
allValues.Should().Contain(new List<TraktEpisodeType>() { TraktEpisodeType.Unspecified, TraktEpisodeType.Standard,
TraktEpisodeType.SeriesPremiere, TraktEpisodeType.SeasonPremiere,
TraktEpisodeType.MidSeasonFinale, TraktEpisodeType.MidSeasonPremiere,
TraktEpisodeType.SeasonFinale, TraktEpisodeType.SeriesFinale });
}

[Fact]
public void Test_TraktEpisodeType_Properties()
{
TraktEpisodeType.Standard.Value.Should().Be(1);
TraktEpisodeType.Standard.ObjectName.Should().Be("standard");
TraktEpisodeType.Standard.UriName.Should().Be("standard");
TraktEpisodeType.Standard.DisplayName.Should().Be("Standard");

TraktEpisodeType.SeriesPremiere.Value.Should().Be(2);
TraktEpisodeType.SeriesPremiere.ObjectName.Should().Be("series_premiere");
TraktEpisodeType.SeriesPremiere.UriName.Should().Be("series_premiere");
TraktEpisodeType.SeriesPremiere.DisplayName.Should().Be("Series Premiere");

TraktEpisodeType.SeasonPremiere.Value.Should().Be(4);
TraktEpisodeType.SeasonPremiere.ObjectName.Should().Be("season_premiere");
TraktEpisodeType.SeasonPremiere.UriName.Should().Be("season_premiere");
TraktEpisodeType.SeasonPremiere.DisplayName.Should().Be("Season Premiere");

TraktEpisodeType.MidSeasonFinale.Value.Should().Be(8);
TraktEpisodeType.MidSeasonFinale.ObjectName.Should().Be("mid_season_finale");
TraktEpisodeType.MidSeasonFinale.UriName.Should().Be("mid_season_finale");
TraktEpisodeType.MidSeasonFinale.DisplayName.Should().Be("Mid Season Finale");

TraktEpisodeType.MidSeasonPremiere.Value.Should().Be(16);
TraktEpisodeType.MidSeasonPremiere.ObjectName.Should().Be("mid_season_premiere");
TraktEpisodeType.MidSeasonPremiere.UriName.Should().Be("mid_season_premiere");
TraktEpisodeType.MidSeasonPremiere.DisplayName.Should().Be("Mid Season Premiere");

TraktEpisodeType.SeasonFinale.Value.Should().Be(32);
TraktEpisodeType.SeasonFinale.ObjectName.Should().Be("season_finale");
TraktEpisodeType.SeasonFinale.UriName.Should().Be("season_finale");
TraktEpisodeType.SeasonFinale.DisplayName.Should().Be("Season Finale");

TraktEpisodeType.SeriesFinale.Value.Should().Be(64);
TraktEpisodeType.SeriesFinale.ObjectName.Should().Be("series_finale");
TraktEpisodeType.SeriesFinale.UriName.Should().Be("series_finale");
TraktEpisodeType.SeriesFinale.DisplayName.Should().Be("Series Finale");
}
}
}

0 comments on commit fbcf5dc

Please sign in to comment.