Skip to content

Commit

Permalink
GH-346 GH-340: Add tests for comment post builder
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikfroehling committed Oct 30, 2022
1 parent 464f601 commit 01b571d
Show file tree
Hide file tree
Showing 17 changed files with 1,026 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ internal abstract class ACommentPostBuilder<TPostBuilder, TPostObject>
where TPostObject : ITraktCommentPost
{
protected string _comment;
protected bool _hasSpoiler;
protected bool? _hasSpoiler;
protected ITraktConnections _sharing;

protected ACommentPostBuilder()
{
_comment = string.Empty;
_hasSpoiler = false;
_comment = null;
_hasSpoiler = null;
_sharing = null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ public override ITraktEpisodeCommentPost Build()
ITraktEpisodeCommentPost episodeCommentPost = new TraktEpisodeCommentPost
{
Comment = _comment,
Spoiler = _hasSpoiler,
Sharing = _sharing,
Episode = _episode
};

if (_hasSpoiler.HasValue)
episodeCommentPost.Spoiler = _hasSpoiler.Value;

episodeCommentPost.Validate();
return episodeCommentPost;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ public override ITraktListCommentPost Build()
ITraktListCommentPost listCommentPost = new TraktListCommentPost
{
Comment = _comment,
Spoiler = _hasSpoiler,
Sharing = _sharing,
List = _list
};

if (_hasSpoiler.HasValue)
listCommentPost.Spoiler = _hasSpoiler.Value;

listCommentPost.Validate();
return listCommentPost;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ public override ITraktMovieCommentPost Build()
ITraktMovieCommentPost movieCommentPost = new TraktMovieCommentPost
{
Comment = _comment,
Spoiler = _hasSpoiler,
Sharing = _sharing,
Movie = _movie
};

if (_hasSpoiler.HasValue)
movieCommentPost.Spoiler = _hasSpoiler.Value;

movieCommentPost.Validate();
return movieCommentPost;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ public override ITraktSeasonCommentPost Build()
ITraktSeasonCommentPost seasonCommentPost = new TraktSeasonCommentPost
{
Comment = _comment,
Spoiler = _hasSpoiler,
Sharing = _sharing,
Season = _season
};

if (_hasSpoiler.HasValue)
seasonCommentPost.Spoiler = _hasSpoiler.Value;

seasonCommentPost.Validate();
return seasonCommentPost;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ public override ITraktShowCommentPost Build()
ITraktShowCommentPost showCommentPost = new TraktShowCommentPost
{
Comment = _comment,
Spoiler = _hasSpoiler,
Sharing = _sharing,
Show = _show
};

if (_hasSpoiler.HasValue)
showCommentPost.Spoiler = _hasSpoiler.Value;

showCommentPost.Validate();
return showCommentPost;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
namespace TraktNet.PostBuilder.Tests
{
using FluentAssertions;
using System;
using Trakt.NET.Tests.Utility.Traits;
using TraktNet.Objects.Get.Episodes;
using TraktNet.Objects.Post.Comments;
using Xunit;

[Category("PostBuilder")]
public partial class TraktPost_EpisodeCommentPostBuilder_Tests
{
[Fact]
public void Test_TraktPost_EpisodeCommentPostBuilder_WithComment_ArgumentNullException()
{
Func<ITraktEpisodeCommentPost> act = () => TraktPost.NewEpisodeCommentPost()
.WithComment(null)
.WithEpisode(TraktPost_Tests_Common_Data.EPISODE_1)
.Build();

act.Should().Throw<ArgumentNullException>();
}

[Fact]
public void Test_TraktPost_EpisodeCommentPostBuilder_WithComment_ArgumentOutOfRangeException()
{
Func<ITraktEpisodeCommentPost> act = () => TraktPost.NewEpisodeCommentPost()
.WithComment(TraktPost_Tests_Common_Data.INVALID_COMMENT)
.WithEpisode(TraktPost_Tests_Common_Data.EPISODE_1)
.Build();

act.Should().Throw<ArgumentOutOfRangeException>();
}

[Fact]
public void Test_TraktPost_EpisodeCommentPostBuilder_WithEpisode_Episode_ArgumentNullException()
{
Func<ITraktEpisodeCommentPost> act = () => TraktPost.NewEpisodeCommentPost()
.WithComment(TraktPost_Tests_Common_Data.VALID_COMMENT)
.WithEpisode(null)
.Build();

act.Should().Throw<ArgumentNullException>();
}

[Fact]
public void Test_TraktPost_EpisodeCommentPostBuilder_WithEpisode_EpisodeIds_ArgumentNullException()
{
Func<ITraktEpisodeCommentPost> act = () => TraktPost.NewEpisodeCommentPost()
.WithComment(TraktPost_Tests_Common_Data.VALID_COMMENT)
.WithEpisode(new TraktEpisode())
.Build();

act.Should().Throw<ArgumentNullException>();
}

[Fact]
public void Test_TraktPost_EpisodeCommentPostBuilder_WithEpisode_EpisodeIds_ArgumentException()
{
Func<ITraktEpisodeCommentPost> act = () => TraktPost.NewEpisodeCommentPost()
.WithComment(TraktPost_Tests_Common_Data.VALID_COMMENT)
.WithEpisode(new TraktEpisode { Ids = new TraktEpisodeIds() })
.Build();

act.Should().Throw<ArgumentException>();
}

[Fact]
public void Test_TraktPost_EpisodeCommentPostBuilder_WithSharing_ArgumentNullException()
{
Func<ITraktEpisodeCommentPost> act = () => TraktPost.NewEpisodeCommentPost()
.WithComment(TraktPost_Tests_Common_Data.VALID_COMMENT)
.WithEpisode(TraktPost_Tests_Common_Data.EPISODE_1)
.WithSharing(null)
.Build();

act.Should().Throw<ArgumentNullException>();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
namespace TraktNet.PostBuilder.Tests
{
using FluentAssertions;
using System;
using Trakt.NET.Tests.Utility.Traits;
using TraktNet.Objects.Post.Comments;
using Xunit;

[Category("PostBuilder")]
public partial class TraktPost_EpisodeCommentPostBuilder_Tests
{
[Fact]
public void Test_TraktPost_EpisodeCommentPostBuilder_Empty_Build()
{
Func<ITraktEpisodeCommentPost> act = () => TraktPost.NewEpisodeCommentPost().Build();
act.Should().Throw<ArgumentNullException>();
}

[Fact]
public void Test_TraktPost_EpisodeCommentPostBuilder_Comment_Episode()
{
ITraktEpisodeCommentPost episodeCommentPost = TraktPost.NewEpisodeCommentPost()
.WithComment(TraktPost_Tests_Common_Data.VALID_COMMENT)
.WithEpisode(TraktPost_Tests_Common_Data.EPISODE_1)
.Build();

episodeCommentPost.Should().NotBeNull();
episodeCommentPost.Comment.Should().Be(TraktPost_Tests_Common_Data.VALID_COMMENT);
episodeCommentPost.Episode.Should().NotBeNull();
episodeCommentPost.Episode.Ids.Should().NotBeNull();
episodeCommentPost.Episode.Ids.Trakt.Should().Be(TraktPost_Tests_Common_Data.EPISODE_1.Ids.Trakt);
episodeCommentPost.Episode.Ids.Imdb.Should().Be(TraktPost_Tests_Common_Data.EPISODE_1.Ids.Imdb);
episodeCommentPost.Episode.Ids.Tvdb.Should().Be(TraktPost_Tests_Common_Data.EPISODE_1.Ids.Tvdb);
episodeCommentPost.Episode.Ids.TvRage.Should().Be(TraktPost_Tests_Common_Data.EPISODE_1.Ids.TvRage);
episodeCommentPost.Episode.Ids.Tmdb.Should().Be(TraktPost_Tests_Common_Data.EPISODE_1.Ids.Tmdb);
episodeCommentPost.Sharing.Should().BeNull();
episodeCommentPost.Spoiler.Should().BeNull();
}

[Fact]
public void Test_TraktPost_EpisodeCommentPostBuilder_Comment_Episode_Sharing()
{
ITraktEpisodeCommentPost episodeCommentPost = TraktPost.NewEpisodeCommentPost()
.WithComment(TraktPost_Tests_Common_Data.VALID_COMMENT)
.WithEpisode(TraktPost_Tests_Common_Data.EPISODE_1)
.WithSharing(TraktPost_Tests_Common_Data.SHARING)
.Build();

episodeCommentPost.Should().NotBeNull();
episodeCommentPost.Comment.Should().Be(TraktPost_Tests_Common_Data.VALID_COMMENT);
episodeCommentPost.Episode.Should().NotBeNull();
episodeCommentPost.Episode.Ids.Should().NotBeNull();
episodeCommentPost.Episode.Ids.Trakt.Should().Be(TraktPost_Tests_Common_Data.EPISODE_1.Ids.Trakt);
episodeCommentPost.Episode.Ids.Imdb.Should().Be(TraktPost_Tests_Common_Data.EPISODE_1.Ids.Imdb);
episodeCommentPost.Episode.Ids.Tvdb.Should().Be(TraktPost_Tests_Common_Data.EPISODE_1.Ids.Tvdb);
episodeCommentPost.Episode.Ids.TvRage.Should().Be(TraktPost_Tests_Common_Data.EPISODE_1.Ids.TvRage);
episodeCommentPost.Episode.Ids.Tmdb.Should().Be(TraktPost_Tests_Common_Data.EPISODE_1.Ids.Tmdb);
episodeCommentPost.Sharing.Should().NotBeNull();
episodeCommentPost.Sharing.Apple.Should().BeTrue();
episodeCommentPost.Sharing.Facebook.Should().BeTrue();
episodeCommentPost.Sharing.Google.Should().BeTrue();
episodeCommentPost.Sharing.Medium.Should().BeTrue();
episodeCommentPost.Sharing.Slack.Should().BeTrue();
episodeCommentPost.Sharing.Tumblr.Should().BeTrue();
episodeCommentPost.Sharing.Twitter.Should().BeTrue();
episodeCommentPost.Spoiler.Should().BeNull();
}

[Fact]
public void Test_TraktPost_EpisodeCommentPostBuilder_Comment_Episode_Spoiler()
{
ITraktEpisodeCommentPost episodeCommentPost = TraktPost.NewEpisodeCommentPost()
.WithComment(TraktPost_Tests_Common_Data.VALID_COMMENT)
.WithEpisode(TraktPost_Tests_Common_Data.EPISODE_1)
.WithSpoiler(true)
.Build();

episodeCommentPost.Should().NotBeNull();
episodeCommentPost.Comment.Should().Be(TraktPost_Tests_Common_Data.VALID_COMMENT);
episodeCommentPost.Episode.Should().NotBeNull();
episodeCommentPost.Episode.Ids.Should().NotBeNull();
episodeCommentPost.Episode.Ids.Trakt.Should().Be(TraktPost_Tests_Common_Data.EPISODE_1.Ids.Trakt);
episodeCommentPost.Episode.Ids.Imdb.Should().Be(TraktPost_Tests_Common_Data.EPISODE_1.Ids.Imdb);
episodeCommentPost.Episode.Ids.Tvdb.Should().Be(TraktPost_Tests_Common_Data.EPISODE_1.Ids.Tvdb);
episodeCommentPost.Episode.Ids.TvRage.Should().Be(TraktPost_Tests_Common_Data.EPISODE_1.Ids.TvRage);
episodeCommentPost.Episode.Ids.Tmdb.Should().Be(TraktPost_Tests_Common_Data.EPISODE_1.Ids.Tmdb);
episodeCommentPost.Sharing.Should().BeNull();
episodeCommentPost.Spoiler.Should().BeTrue();
}

[Fact]
public void Test_TraktPost_EpisodeCommentPostBuilder_Complete()
{
ITraktEpisodeCommentPost episodeCommentPost = TraktPost.NewEpisodeCommentPost()
.WithComment(TraktPost_Tests_Common_Data.VALID_COMMENT)
.WithEpisode(TraktPost_Tests_Common_Data.EPISODE_1)
.WithSharing(TraktPost_Tests_Common_Data.SHARING)
.WithSpoiler(true)
.Build();

episodeCommentPost.Should().NotBeNull();
episodeCommentPost.Comment.Should().Be(TraktPost_Tests_Common_Data.VALID_COMMENT);
episodeCommentPost.Episode.Should().NotBeNull();
episodeCommentPost.Episode.Ids.Should().NotBeNull();
episodeCommentPost.Episode.Ids.Trakt.Should().Be(TraktPost_Tests_Common_Data.EPISODE_1.Ids.Trakt);
episodeCommentPost.Episode.Ids.Imdb.Should().Be(TraktPost_Tests_Common_Data.EPISODE_1.Ids.Imdb);
episodeCommentPost.Episode.Ids.Tvdb.Should().Be(TraktPost_Tests_Common_Data.EPISODE_1.Ids.Tvdb);
episodeCommentPost.Episode.Ids.TvRage.Should().Be(TraktPost_Tests_Common_Data.EPISODE_1.Ids.TvRage);
episodeCommentPost.Episode.Ids.Tmdb.Should().Be(TraktPost_Tests_Common_Data.EPISODE_1.Ids.Tmdb);
episodeCommentPost.Sharing.Should().NotBeNull();
episodeCommentPost.Sharing.Apple.Should().BeTrue();
episodeCommentPost.Sharing.Facebook.Should().BeTrue();
episodeCommentPost.Sharing.Google.Should().BeTrue();
episodeCommentPost.Sharing.Medium.Should().BeTrue();
episodeCommentPost.Sharing.Slack.Should().BeTrue();
episodeCommentPost.Sharing.Tumblr.Should().BeTrue();
episodeCommentPost.Sharing.Twitter.Should().BeTrue();
episodeCommentPost.Spoiler.Should().BeTrue();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
namespace TraktNet.PostBuilder.Tests
{
using FluentAssertions;
using System;
using Trakt.NET.Tests.Utility.Traits;
using TraktNet.Objects.Get.Lists;
using TraktNet.Objects.Post.Comments;
using Xunit;

[Category("PostBuilder")]
public partial class TraktPost_ListCommentPostBuilder_Tests
{
[Fact]
public void Test_TraktPost_ListCommentPostBuilder_WithComment_ArgumentNullException()
{
Func<ITraktListCommentPost> act = () => TraktPost.NewListCommentPost()
.WithComment(null)
.WithList(TraktPost_Tests_Common_Data.LIST)
.Build();

act.Should().Throw<ArgumentNullException>();
}

[Fact]
public void Test_TraktPost_ListCommentPostBuilder_WithComment_ArgumentOutOfRangeException()
{
Func<ITraktListCommentPost> act = () => TraktPost.NewListCommentPost()
.WithComment(TraktPost_Tests_Common_Data.INVALID_COMMENT)
.WithList(TraktPost_Tests_Common_Data.LIST)
.Build();

act.Should().Throw<ArgumentOutOfRangeException>();
}

[Fact]
public void Test_TraktPost_ListCommentPostBuilder_WithList_List_ArgumentNullException()
{
Func<ITraktListCommentPost> act = () => TraktPost.NewListCommentPost()
.WithComment(TraktPost_Tests_Common_Data.VALID_COMMENT)
.WithList(null)
.Build();

act.Should().Throw<ArgumentNullException>();
}

[Fact]
public void Test_TraktPost_ListCommentPostBuilder_WithList_ListIds_ArgumentNullException()
{
Func<ITraktListCommentPost> act = () => TraktPost.NewListCommentPost()
.WithComment(TraktPost_Tests_Common_Data.VALID_COMMENT)
.WithList(new TraktList())
.Build();

act.Should().Throw<ArgumentNullException>();
}

[Fact]
public void Test_TraktPost_ListCommentPostBuilder_WithList_ListIds_ArgumentException()
{
Func<ITraktListCommentPost> act = () => TraktPost.NewListCommentPost()
.WithComment(TraktPost_Tests_Common_Data.VALID_COMMENT)
.WithList(new TraktList { Ids = new TraktListIds() })
.Build();

act.Should().Throw<ArgumentException>();
}

[Fact]
public void Test_TraktPost_ListCommentPostBuilder_WithSharing_ArgumentNullException()
{
Func<ITraktListCommentPost> act = () => TraktPost.NewListCommentPost()
.WithComment(TraktPost_Tests_Common_Data.VALID_COMMENT)
.WithList(TraktPost_Tests_Common_Data.LIST)
.WithSharing(null)
.Build();

act.Should().Throw<ArgumentNullException>();
}
}
}
Loading

0 comments on commit 01b571d

Please sign in to comment.