Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

phase out fluent assertions in favor of shouldly #1708

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Shouldly" Version="4.2.1" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" />
<PackageReference Include="coverlet.collector">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
118 changes: 59 additions & 59 deletions bff/test/Duende.Bff.EntityFramework.Tests/UserSessionStoreTests.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright (c) Duende Software. All rights reserved.
// See LICENSE in the project root for license information.

using FluentAssertions;
using Microsoft.AspNetCore.Builder;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Linq;
using System.Threading.Tasks;
using Shouldly;
using Xunit;

namespace Duende.Bff.EntityFramework.Tests
Expand All @@ -31,7 +31,7 @@ public UserSessionStoreTests()
[Fact]
public async Task CreateUserSessionAsync_should_succeed()
{
_database.UserSessions.Count().Should().Be(0);
_database.UserSessions.Count().ShouldBe(0);

await _subject.CreateUserSessionAsync(new UserSession
{
Expand All @@ -44,7 +44,7 @@ await _subject.CreateUserSessionAsync(new UserSession
Ticket = "ticket"
});

_database.UserSessions.Count().Should().Be(1);
_database.UserSessions.Count().ShouldBe(1);
}


Expand All @@ -64,20 +64,20 @@ await _subject.CreateUserSessionAsync(new UserSession

var item = await _subject.GetUserSessionAsync("key123");

item.Should().NotBeNull();
item.Key.Should().Be("key123");
item.SubjectId.Should().Be("sub");
item.SessionId.Should().Be("sid");
item.Ticket.Should().Be("ticket");
item.Created.Should().Be(new DateTime(2020, 3, 1, 9, 12, 33, DateTimeKind.Utc));
item.Renewed.Should().Be(new DateTime(2021, 4, 2, 10, 13, 34, DateTimeKind.Utc));
item.Expires.Should().Be(new DateTime(2022, 5, 3, 11, 14, 35, DateTimeKind.Utc));
item.ShouldNotBeNull();
item.Key.ShouldBe("key123");
item.SubjectId.ShouldBe("sub");
item.SessionId.ShouldBe("sid");
item.Ticket.ShouldBe("ticket");
item.Created.ShouldBe(new DateTime(2020, 3, 1, 9, 12, 33, DateTimeKind.Utc));
item.Renewed.ShouldBe(new DateTime(2021, 4, 2, 10, 13, 34, DateTimeKind.Utc));
item.Expires.ShouldBe(new DateTime(2022, 5, 3, 11, 14, 35, DateTimeKind.Utc));
}
[Fact]
public async Task GetUserSessionAsync_for_invalid_key_should_return_null()
{
var item = await _subject.GetUserSessionAsync("invalid");
item.Should().BeNull();
item.ShouldBeNull();
}


Expand Down Expand Up @@ -107,14 +107,14 @@ await _subject.CreateUserSessionAsync(new UserSession
});

var item = await _subject.GetUserSessionAsync("key123");
item.Should().NotBeNull();
item.Key.Should().Be("key123");
item.SubjectId.Should().Be("sub");
item.SessionId.Should().Be("sid");
item.Ticket.Should().Be("ticket2");
item.Created.Should().Be(new DateTime(2020, 3, 1, 9, 12, 33, DateTimeKind.Utc));
item.Renewed.Should().Be(new DateTime(2024, 1, 3, 5, 7, 9, DateTimeKind.Utc));
item.Expires.Should().Be(new DateTime(2025, 2, 4, 6, 8, 10, DateTimeKind.Utc));
item.ShouldNotBeNull();
item.Key.ShouldBe("key123");
item.SubjectId.ShouldBe("sub");
item.SessionId.ShouldBe("sid");
item.Ticket.ShouldBe("ticket2");
item.Created.ShouldBe(new DateTime(2020, 3, 1, 9, 12, 33, DateTimeKind.Utc));
item.Renewed.ShouldBe(new DateTime(2024, 1, 3, 5, 7, 9, DateTimeKind.Utc));
item.Expires.ShouldBe(new DateTime(2025, 2, 4, 6, 8, 10, DateTimeKind.Utc));
}
{
await _subject.UpdateUserSessionAsync("key123", new UserSessionUpdate
Expand All @@ -128,14 +128,14 @@ await _subject.CreateUserSessionAsync(new UserSession
});

var item = await _subject.GetUserSessionAsync("key123");
item.Should().NotBeNull();
item.Key.Should().Be("key123");
item.SubjectId.Should().Be("sub2");
item.SessionId.Should().Be("sid2");
item.Ticket.Should().Be("ticket3");
item.Created.Should().Be(new DateTime(2022, 3, 1, 9, 12, 33, DateTimeKind.Utc));
item.Renewed.Should().Be(new DateTime(2024, 1, 3, 5, 7, 9, DateTimeKind.Utc));
item.Expires.Should().Be(new DateTime(2025, 2, 4, 6, 8, 10, DateTimeKind.Utc));
item.ShouldNotBeNull();
item.Key.ShouldBe("key123");
item.SubjectId.ShouldBe("sub2");
item.SessionId.ShouldBe("sid2");
item.Ticket.ShouldBe("ticket3");
item.Created.ShouldBe(new DateTime(2022, 3, 1, 9, 12, 33, DateTimeKind.Utc));
item.Renewed.ShouldBe(new DateTime(2024, 1, 3, 5, 7, 9, DateTimeKind.Utc));
item.Expires.ShouldBe(new DateTime(2025, 2, 4, 6, 8, 10, DateTimeKind.Utc));
}
}
[Fact]
Expand All @@ -149,7 +149,7 @@ public async Task UpdateUserSessionAsync_for_invalid_key_should_succeed()
});

var item = await _subject.GetUserSessionAsync("key123");
item.Should().BeNull();
item.ShouldBeNull();
}


Expand All @@ -162,11 +162,11 @@ await _subject.CreateUserSessionAsync(new UserSession {
SessionId = "session",
Ticket = "ticket",
});
_database.UserSessions.Count().Should().Be(1);
_database.UserSessions.Count().ShouldBe(1);

await _subject.DeleteUserSessionAsync("key123");

_database.UserSessions.Count().Should().Be(0);
_database.UserSessions.Count().ShouldBe(0);
}
[Fact]
public async Task DeleteUserSessionAsync_for_invalid_key_should_succeed()
Expand Down Expand Up @@ -222,9 +222,9 @@ await _subject.CreateUserSessionAsync(new UserSession
});

var items = await _subject.GetUserSessionsAsync(new UserSessionsFilter { SubjectId = "sub2" });
items.Count().Should().Be(3);
items.Select(x => x.SubjectId).Distinct().Should().BeEquivalentTo(new[] { "sub2" });
items.Select(x => x.SessionId).Should().BeEquivalentTo(new[] { "sid2_1", "sid2_2", "sid2_3", });
items.Count().ShouldBe(3);
items.Select(x => x.SubjectId).Distinct().ToArray().ShouldBeEquivalentTo(new[] { "sub2" });
items.Select(x => x.SessionId).ToArray().ShouldBeEquivalentTo(new[] { "sid2_1", "sid2_2", "sid2_3", });
}
[Fact]
public async Task GetUserSessionsAsync_for_invalid_sub_should_return_empty()
Expand Down Expand Up @@ -273,7 +273,7 @@ await _subject.CreateUserSessionAsync(new UserSession
});

var items = await _subject.GetUserSessionsAsync(new UserSessionsFilter { SubjectId = "invalid" });
items.Count().Should().Be(0);
items.Count().ShouldBe(0);
}
[Fact]
public async Task GetUserSessionsAsync_for_valid_sid_should_succeed()
Expand Down Expand Up @@ -322,9 +322,9 @@ await _subject.CreateUserSessionAsync(new UserSession
});

var items = await _subject.GetUserSessionsAsync(new UserSessionsFilter { SessionId = "sid2_2" });
items.Count().Should().Be(1);
items.Select(x => x.SubjectId).Should().BeEquivalentTo(new[] { "sub2" });
items.Select(x => x.SessionId).Should().BeEquivalentTo(new[] { "sid2_2" });
items.Count().ShouldBe(1);
items.Select(x => x.SubjectId).ToArray().ShouldBeEquivalentTo(new[] { "sub2" });
items.Select(x => x.SessionId).ToArray().ShouldBeEquivalentTo(new[] { "sid2_2" });
}
[Fact]
public async Task GetUserSessionsAsync_for_invalid_sid_should_return_empty()
Expand Down Expand Up @@ -373,7 +373,7 @@ await _subject.CreateUserSessionAsync(new UserSession
});

var items = await _subject.GetUserSessionsAsync(new UserSessionsFilter { SessionId = "invalid" });
items.Count().Should().Be(0);
items.Count().ShouldBe(0);
}
[Fact]
public async Task GetUserSessionsAsync_for_valid_sub_and_sid_should_succeed()
Expand Down Expand Up @@ -422,9 +422,9 @@ await _subject.CreateUserSessionAsync(new UserSession
});

var items = await _subject.GetUserSessionsAsync(new UserSessionsFilter { SubjectId = "sub2", SessionId = "sid2_2" });
items.Count().Should().Be(1);
items.Select(x => x.SubjectId).Should().BeEquivalentTo(new[] { "sub2" });
items.Select(x => x.SessionId).Should().BeEquivalentTo(new[] { "sid2_2" });
items.Count().ShouldBe(1);
items.Select(x => x.SubjectId).ToArray().ShouldBeEquivalentTo(new[] { "sub2" });
items.Select(x => x.SessionId).ToArray().ShouldBeEquivalentTo(new[] { "sid2_2" });
}
[Fact]
public async Task GetUserSessionsAsync_for_invalid_sub_and_sid_should_succeed()
Expand Down Expand Up @@ -474,22 +474,22 @@ await _subject.CreateUserSessionAsync(new UserSession

{
var items = await _subject.GetUserSessionsAsync(new UserSessionsFilter { SubjectId = "invalid", SessionId = "invalid" });
items.Count().Should().Be(0);
items.Count().ShouldBe(0);
}
{
var items = await _subject.GetUserSessionsAsync(new UserSessionsFilter { SubjectId = "sub1", SessionId = "invalid" });
items.Count().Should().Be(0);
items.Count().ShouldBe(0);
}
{
var items = await _subject.GetUserSessionsAsync(new UserSessionsFilter { SubjectId = "invalid", SessionId = "sid1_1" });
items.Count().Should().Be(0);
items.Count().ShouldBe(0);
}
}
[Fact]
public async Task GetUserSessionsAsync_for_missing_sub_and_sid_should_throw()
{
Func<Task> f = () => _subject.GetUserSessionsAsync(new UserSessionsFilter());
await f.Should().ThrowAsync<Exception>();
await f.ShouldThrowAsync<Exception>();
}


Expand Down Expand Up @@ -540,8 +540,8 @@ await _subject.CreateUserSessionAsync(new UserSession
});

await _subject.DeleteUserSessionsAsync(new UserSessionsFilter { SubjectId = "sub2" });
_database.UserSessions.Count().Should().Be(3);
_database.UserSessions.Count(x => x.SubjectId == "sub2").Should().Be(0);
_database.UserSessions.Count().ShouldBe(3);
_database.UserSessions.Count(x => x.SubjectId == "sub2").ShouldBe(0);
}
[Fact]
public async Task DeleteUserSessionsAsync_for_invalid_sub_should_do_nothing()
Expand Down Expand Up @@ -590,7 +590,7 @@ await _subject.CreateUserSessionAsync(new UserSession
});

await _subject.DeleteUserSessionsAsync(new UserSessionsFilter { SubjectId = "invalid" });
_database.UserSessions.Count().Should().Be(6);
_database.UserSessions.Count().ShouldBe(6);
}
[Fact]
public async Task DeleteUserSessionsAsync_for_valid_sid_should_succeed()
Expand Down Expand Up @@ -639,8 +639,8 @@ await _subject.CreateUserSessionAsync(new UserSession
});

await _subject.DeleteUserSessionsAsync(new UserSessionsFilter { SessionId = "sid2_2" });
_database.UserSessions.Count().Should().Be(5);
_database.UserSessions.Count(x => x.SessionId == "sid2_2").Should().Be(0);
_database.UserSessions.Count().ShouldBe(5);
_database.UserSessions.Count(x => x.SessionId == "sid2_2").ShouldBe(0);
}
[Fact]
public async Task DeleteUserSessionsAsync_for_invalid_sid_should_do_nothing()
Expand Down Expand Up @@ -689,7 +689,7 @@ await _subject.CreateUserSessionAsync(new UserSession
});

await _subject.DeleteUserSessionsAsync(new UserSessionsFilter { SessionId = "invalid" });
_database.UserSessions.Count().Should().Be(6);
_database.UserSessions.Count().ShouldBe(6);
}
[Fact]
public async Task DeleteUserSessionsAsync_for_valid_sub_and_sid_should_succeed()
Expand Down Expand Up @@ -738,8 +738,8 @@ await _subject.CreateUserSessionAsync(new UserSession
});

await _subject.DeleteUserSessionsAsync(new UserSessionsFilter { SubjectId = "sub2", SessionId = "sid2_2" });
_database.UserSessions.Count().Should().Be(5);
_database.UserSessions.Count(x => x.SubjectId == "sub2" && x.SessionId == "sid2_2").Should().Be(0);
_database.UserSessions.Count().ShouldBe(5);
_database.UserSessions.Count(x => x.SubjectId == "sub2" && x.SessionId == "sid2_2").ShouldBe(0);
}
[Fact]
public async Task DeleteUserSessionsAsync_for_invalid_sub_and_sid_should_succeed()
Expand Down Expand Up @@ -789,22 +789,22 @@ await _subject.CreateUserSessionAsync(new UserSession

{
await _subject.DeleteUserSessionsAsync(new UserSessionsFilter { SubjectId = "invalid", SessionId = "invalid" });
_database.UserSessions.Count().Should().Be(6);
_database.UserSessions.Count().ShouldBe(6);
}
{
await _subject.DeleteUserSessionsAsync(new UserSessionsFilter { SubjectId = "sub1", SessionId = "invalid" });
_database.UserSessions.Count().Should().Be(6);
_database.UserSessions.Count().ShouldBe(6);
}
{
await _subject.DeleteUserSessionsAsync(new UserSessionsFilter { SubjectId = "invalid", SessionId = "sid1_1" });
_database.UserSessions.Count().Should().Be(6);
_database.UserSessions.Count().ShouldBe(6);
}
}
[Fact]
public async Task DeleteUserSessionsAsync_for_missing_sub_and_sid_should_throw()
{
Func<Task> f = () => _subject.DeleteUserSessionsAsync(new UserSessionsFilter());
await f.Should().ThrowAsync<Exception>();
await f.ShouldThrowAsync<Exception>();
}

[Fact]
Expand Down Expand Up @@ -841,7 +841,7 @@ public async Task concurrent_deletes_with_exception_handler_and_detatching_shoul
await ctx1.SaveChangesAsync();

Func<Task> f1 = async () => await ctx2.SaveChangesAsync();
await f1.Should().ThrowAsync<DbUpdateConcurrencyException>();
await f1.ShouldThrowAsync<DbUpdateConcurrencyException>();

try
{
Expand Down
2 changes: 1 addition & 1 deletion bff/test/Duende.Bff.Tests/Duende.Bff.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Shouldly" Version="4.2.1" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" />
<PackageReference Include="coverlet.collector">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
Loading
Loading