Skip to content

Commit

Permalink
[v2] Replace FluentAssertions with Shouldly
Browse files Browse the repository at this point in the history
There are still some extensions missing:
- No support for some nullable types, like `bool?` or `uint?`
- No support for `ShouldBe(new Dictionary<TKey, TValue>{ ... })`
  • Loading branch information
henrikfroehling committed Feb 7, 2025
1 parent 4d313b7 commit 2e27a06
Show file tree
Hide file tree
Showing 231 changed files with 8,132 additions and 7,839 deletions.
2 changes: 1 addition & 1 deletion src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<ItemGroup>
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
<PackageVersion Include="coverlet.msbuild" Version="6.0.4" />
<PackageVersion Include="FluentAssertions" Version="8.0.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageVersion Include="RichardSzalay.MockHttp" Version="7.0.0" />
<PackageVersion Include="Shouldly" Version="4.3.0" />
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
<PackageVersion Include="xunit" Version="2.9.3" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.1" />
Expand Down
2 changes: 1 addition & 1 deletion src/tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup Condition="'$(IsTestProject)' == 'true' AND '$(IsTestUtilityProject)' != 'true'">
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Shouldly" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />

Expand Down
24 changes: 12 additions & 12 deletions src/tests/libs/Trakt.NET.Core.Tests/Contexts/TraktContextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,52 +10,52 @@ public void TestTraktContextWithClientIDAndSecret()
{
var context = new TraktDefaultContext(ClientID, ClientSecret);

context.ID.Should().NotBeNullOrEmpty();
context.ClientID.Should().Be(ClientID);
context.ClientSecret.Should().Be(ClientSecret);
context.Authorization.Should().BeNull();
context.ID.ShouldNotBeNullOrEmpty();
context.ClientID.ShouldBe(ClientID);
context.ClientSecret.ShouldBe(ClientSecret);
context.Authorization.ShouldBeNull();
}

[Fact]
public void TestTraktContextHasCorrectBaseUri()
{
var context = new TraktDefaultContext(ClientID, ClientSecret);

context.BaseUri.AbsoluteUri.Should().Be("https://api.trakt.tv/");
context.BaseUri.AbsoluteUri.ShouldBe("https://api.trakt.tv/");
}

[Fact]
public void TestTraktContextHasCorrectBaseAuthorizationUri()
{
var context = new TraktDefaultContext(ClientID, ClientSecret);

context.BaseAuthorizationUri.AbsoluteUri.Should().Be("https://trakt.tv/");
context.BaseAuthorizationUri.AbsoluteUri.ShouldBe("https://trakt.tv/");
}

[Fact]
public void TestTraktContextInvalidClientID()
{
Action act = () => _ = new TraktDefaultContext(string.Empty, ClientSecret);
act.Should().Throw<ArgumentException>();
act.ShouldThrow<ArgumentException>();

act = () => _ = new TraktDefaultContext(" ", ClientSecret);
act.Should().Throw<ArgumentException>();
act.ShouldThrow<ArgumentException>();

act = () => _ = new TraktDefaultContext(" id ", ClientSecret);
act.Should().Throw<ArgumentException>();
act.ShouldThrow<ArgumentException>();
}

[Fact]
public void TestTraktContextInvalidClientSecret()
{
Action act = () => _ = new TraktDefaultContext(ClientID, string.Empty);
act.Should().Throw<ArgumentException>();
act.ShouldThrow<ArgumentException>();

act = () => _ = new TraktDefaultContext(ClientID, " ");
act.Should().Throw<ArgumentException>();
act.ShouldThrow<ArgumentException>();

act = () => _ = new TraktDefaultContext(ClientID, " secret ");
act.Should().Throw<ArgumentException>();
act.ShouldThrow<ArgumentException>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,52 +10,52 @@ public void TestTraktSandboxContextWithClientIDAndSecret()
{
var context = new TraktSandboxContext(ClientID, ClientSecret);

context.ID.Should().NotBeNullOrEmpty();
context.ClientID.Should().Be(ClientID);
context.ClientSecret.Should().Be(ClientSecret);
context.Authorization.Should().BeNull();
context.ID.ShouldNotBeNullOrEmpty();
context.ClientID.ShouldBe(ClientID);
context.ClientSecret.ShouldBe(ClientSecret);
context.Authorization.ShouldBeNull();
}

[Fact]
public void TestTraktSandboxContextHasCorrectBaseUri()
{
var context = new TraktSandboxContext(ClientID, ClientSecret);

context.BaseUri.AbsoluteUri.Should().Be("https://api-staging.trakt.tv/");
context.BaseUri.AbsoluteUri.ShouldBe("https://api-staging.trakt.tv/");
}

[Fact]
public void TestTraktSandboxContextHasCorrectBaseAuthorizationUri()
{
var context = new TraktSandboxContext(ClientID, ClientSecret);

context.BaseAuthorizationUri.AbsoluteUri.Should().Be("https://staging.trakt.tv/");
context.BaseAuthorizationUri.AbsoluteUri.ShouldBe("https://staging.trakt.tv/");
}

[Fact]
public void TestTraktSandboxContextInvalidClientID()
{
Action act = () => _ = new TraktSandboxContext(string.Empty, ClientSecret);
act.Should().Throw<ArgumentException>();
act.ShouldThrow<ArgumentException>();

act = () => _ = new TraktSandboxContext(" ", ClientSecret);
act.Should().Throw<ArgumentException>();
act.ShouldThrow<ArgumentException>();

act = () => _ = new TraktSandboxContext(" id ", ClientSecret);
act.Should().Throw<ArgumentException>();
act.ShouldThrow<ArgumentException>();
}

[Fact]
public void TestTraktSandboxContextInvalidClientSecret()
{
Action act = () => _ = new TraktSandboxContext(ClientID, string.Empty);
act.Should().Throw<ArgumentException>();
act.ShouldThrow<ArgumentException>();

act = () => _ = new TraktSandboxContext(ClientID, " ");
act.Should().Throw<ArgumentException>();
act.ShouldThrow<ArgumentException>();

act = () => _ = new TraktSandboxContext(ClientID, " secret ");
act.Should().Throw<ArgumentException>();
act.ShouldThrow<ArgumentException>();
}
}
}
26 changes: 13 additions & 13 deletions src/tests/libs/Trakt.NET.Core.Tests/Enums/TraktAccessScopeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@ public sealed class TraktAccessScopeTests
[Fact]
public void TestTraktAccessScopeToJson()
{
TraktAccessScope.Unspecified.ToJson().Should().BeNull();
TraktAccessScope.Private.ToJson().Should().Be("private");
TraktAccessScope.Friends.ToJson().Should().Be("friends");
TraktAccessScope.Public.ToJson().Should().Be("public");
TraktAccessScope.Unspecified.ToJson().ShouldBeNull();
TraktAccessScope.Private.ToJson().ShouldBe("private");
TraktAccessScope.Friends.ToJson().ShouldBe("friends");
TraktAccessScope.Public.ToJson().ShouldBe("public");
}

[Fact]
public void TestTraktAccessScopeFromJson()
{
"unspecified".ToTraktAccessScope().Should().Be(TraktAccessScope.Unspecified);
"private".ToTraktAccessScope().Should().Be(TraktAccessScope.Private);
"friends".ToTraktAccessScope().Should().Be(TraktAccessScope.Friends);
"public".ToTraktAccessScope().Should().Be(TraktAccessScope.Public);
"unspecified".ToTraktAccessScope().ShouldBe(TraktAccessScope.Unspecified);
"private".ToTraktAccessScope().ShouldBe(TraktAccessScope.Private);
"friends".ToTraktAccessScope().ShouldBe(TraktAccessScope.Friends);
"public".ToTraktAccessScope().ShouldBe(TraktAccessScope.Public);

string? nullValue = null;
nullValue.ToTraktAccessScope().Should().Be(TraktAccessScope.Unspecified);
nullValue.ToTraktAccessScope().ShouldBe(TraktAccessScope.Unspecified);
}

[Fact]
public void TestTraktAccessScopeDisplayName()
{
TraktAccessScope.Unspecified.DisplayName().Should().Be("Unspecified");
TraktAccessScope.Private.DisplayName().Should().Be("Private");
TraktAccessScope.Friends.DisplayName().Should().Be("Friends");
TraktAccessScope.Public.DisplayName().Should().Be("Public");
TraktAccessScope.Unspecified.DisplayName().ShouldBe("Unspecified");
TraktAccessScope.Private.DisplayName().ShouldBe("Private");
TraktAccessScope.Friends.DisplayName().ShouldBe("Friends");
TraktAccessScope.Public.DisplayName().ShouldBe("Public");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@ public sealed class TraktAccessTokenGrantTypeTests
[Fact]
public void TestTraktAccessTokenGrantTypeToJson()
{
TraktAccessTokenGrantType.Unspecified.ToJson().Should().BeNull();
TraktAccessTokenGrantType.AuthorizationCode.ToJson().Should().Be("authorization_code");
TraktAccessTokenGrantType.RefreshToken.ToJson().Should().Be("refresh_token");
TraktAccessTokenGrantType.Unspecified.ToJson().ShouldBeNull();
TraktAccessTokenGrantType.AuthorizationCode.ToJson().ShouldBe("authorization_code");
TraktAccessTokenGrantType.RefreshToken.ToJson().ShouldBe("refresh_token");
}

[Fact]
public void TestTraktAccessTokenGrantTypeFromJson()
{
"unspecified".ToTraktAccessTokenGrantType().Should().Be(TraktAccessTokenGrantType.Unspecified);
"authorization_code".ToTraktAccessTokenGrantType().Should().Be(TraktAccessTokenGrantType.AuthorizationCode);
"refresh_token".ToTraktAccessTokenGrantType().Should().Be(TraktAccessTokenGrantType.RefreshToken);
"unspecified".ToTraktAccessTokenGrantType().ShouldBe(TraktAccessTokenGrantType.Unspecified);
"authorization_code".ToTraktAccessTokenGrantType().ShouldBe(TraktAccessTokenGrantType.AuthorizationCode);
"refresh_token".ToTraktAccessTokenGrantType().ShouldBe(TraktAccessTokenGrantType.RefreshToken);

string? nullValue = null;
nullValue.ToTraktAccessTokenGrantType().Should().Be(TraktAccessTokenGrantType.Unspecified);
nullValue.ToTraktAccessTokenGrantType().ShouldBe(TraktAccessTokenGrantType.Unspecified);
}

[Fact]
public void TestTraktAccessTokenGrantTypeDisplayName()
{
TraktAccessTokenGrantType.Unspecified.DisplayName().Should().Be("Unspecified");
TraktAccessTokenGrantType.AuthorizationCode.DisplayName().Should().Be("Authorization Code");
TraktAccessTokenGrantType.RefreshToken.DisplayName().Should().Be("Refresh Token");
TraktAccessTokenGrantType.Unspecified.DisplayName().ShouldBe("Unspecified");
TraktAccessTokenGrantType.AuthorizationCode.DisplayName().ShouldBe("Authorization Code");
TraktAccessTokenGrantType.RefreshToken.DisplayName().ShouldBe("Refresh Token");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ public sealed class TraktAccessTokenTypeTests
[Fact]
public void TestTraktAccessTokenTypeToJson()
{
TraktAccessTokenType.Unspecified.ToJson().Should().BeNull();
TraktAccessTokenType.Bearer.ToJson().Should().Be("bearer");
TraktAccessTokenType.Unspecified.ToJson().ShouldBeNull();
TraktAccessTokenType.Bearer.ToJson().ShouldBe("bearer");
}

[Fact]
public void TestTraktAccessTokenTypeFromJson()
{
"unspecified".ToTraktAccessTokenType().Should().Be(TraktAccessTokenType.Unspecified);
"bearer".ToTraktAccessTokenType().Should().Be(TraktAccessTokenType.Bearer);
"unspecified".ToTraktAccessTokenType().ShouldBe(TraktAccessTokenType.Unspecified);
"bearer".ToTraktAccessTokenType().ShouldBe(TraktAccessTokenType.Bearer);

string? nullValue = null;
nullValue.ToTraktAccessTokenType().Should().Be(TraktAccessTokenType.Unspecified);
nullValue.ToTraktAccessTokenType().ShouldBe(TraktAccessTokenType.Unspecified);
}

[Fact]
public void TestTraktAccessTokenTypeDisplayName()
{
TraktAccessTokenType.Unspecified.DisplayName().Should().Be("Unspecified");
TraktAccessTokenType.Bearer.DisplayName().Should().Be("Bearer");
TraktAccessTokenType.Unspecified.DisplayName().ShouldBe("Unspecified");
TraktAccessTokenType.Bearer.DisplayName().ShouldBe("Bearer");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,40 @@ public sealed class TraktCommentObjectTypeTests
[Fact]
public void TestTraktCommentObjectTypeToJson()
{
TraktCommentObjectType.Unspecified.ToJson().Should().BeNull();
TraktCommentObjectType.Movie.ToJson().Should().Be("movie");
TraktCommentObjectType.Show.ToJson().Should().Be("show");
TraktCommentObjectType.Season.ToJson().Should().Be("season");
TraktCommentObjectType.Episode.ToJson().Should().Be("episode");
TraktCommentObjectType.List.ToJson().Should().Be("list");
TraktCommentObjectType.All.ToJson().Should().Be("all");
TraktCommentObjectType.Unspecified.ToJson().ShouldBeNull();
TraktCommentObjectType.Movie.ToJson().ShouldBe("movie");
TraktCommentObjectType.Show.ToJson().ShouldBe("show");
TraktCommentObjectType.Season.ToJson().ShouldBe("season");
TraktCommentObjectType.Episode.ToJson().ShouldBe("episode");
TraktCommentObjectType.List.ToJson().ShouldBe("list");
TraktCommentObjectType.All.ToJson().ShouldBe("all");
}

[Fact]
public void TestTraktCommentObjectTypeFromJson()
{
"unspecified".ToTraktCommentObjectType().Should().Be(TraktCommentObjectType.Unspecified);
"movie".ToTraktCommentObjectType().Should().Be(TraktCommentObjectType.Movie);
"show".ToTraktCommentObjectType().Should().Be(TraktCommentObjectType.Show);
"season".ToTraktCommentObjectType().Should().Be(TraktCommentObjectType.Season);
"episode".ToTraktCommentObjectType().Should().Be(TraktCommentObjectType.Episode);
"list".ToTraktCommentObjectType().Should().Be(TraktCommentObjectType.List);
"all".ToTraktCommentObjectType().Should().Be(TraktCommentObjectType.All);
"unspecified".ToTraktCommentObjectType().ShouldBe(TraktCommentObjectType.Unspecified);
"movie".ToTraktCommentObjectType().ShouldBe(TraktCommentObjectType.Movie);
"show".ToTraktCommentObjectType().ShouldBe(TraktCommentObjectType.Show);
"season".ToTraktCommentObjectType().ShouldBe(TraktCommentObjectType.Season);
"episode".ToTraktCommentObjectType().ShouldBe(TraktCommentObjectType.Episode);
"list".ToTraktCommentObjectType().ShouldBe(TraktCommentObjectType.List);
"all".ToTraktCommentObjectType().ShouldBe(TraktCommentObjectType.All);

string? nullValue = null;
nullValue.ToTraktCommentObjectType().Should().Be(TraktCommentObjectType.Unspecified);
nullValue.ToTraktCommentObjectType().ShouldBe(TraktCommentObjectType.Unspecified);
}

[Fact]
public void TestTraktCommentObjectTypeDisplayName()
{
TraktCommentObjectType.Unspecified.DisplayName().Should().Be("Unspecified");
TraktCommentObjectType.Movie.DisplayName().Should().Be("Movie");
TraktCommentObjectType.Show.DisplayName().Should().Be("Show");
TraktCommentObjectType.Season.DisplayName().Should().Be("Season");
TraktCommentObjectType.Episode.DisplayName().Should().Be("Episode");
TraktCommentObjectType.List.DisplayName().Should().Be("List");
TraktCommentObjectType.All.DisplayName().Should().Be("All");
TraktCommentObjectType.Unspecified.DisplayName().ShouldBe("Unspecified");
TraktCommentObjectType.Movie.DisplayName().ShouldBe("Movie");
TraktCommentObjectType.Show.DisplayName().ShouldBe("Show");
TraktCommentObjectType.Season.DisplayName().ShouldBe("Season");
TraktCommentObjectType.Episode.DisplayName().ShouldBe("Episode");
TraktCommentObjectType.List.DisplayName().ShouldBe("List");
TraktCommentObjectType.All.DisplayName().ShouldBe("All");
}
}
}
Loading

0 comments on commit 2e27a06

Please sign in to comment.