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

Get\ting rid of FluentAssertions #31

Merged
merged 1 commit into from
Jan 26, 2025
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 @@ -12,9 +12,9 @@
<ItemGroup>
<PackageReference Include="AutoFixture" Version="4.18.1"/>
<PackageReference Include="AutoFixture.Xunit2" Version="4.18.1"/>
<PackageReference Include="FluentAssertions" Version="6.12.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0"/>
<PackageReference Include="Moq" Version="4.20.70"/>
<PackageReference Include="Shouldly" Version="4.3.0" />
<PackageReference Include="xunit" Version="2.4.2"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
2 changes: 1 addition & 1 deletion tests/Bw.VaultDigest.UnitTests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
global using Xunit;
global using FluentAssertions;
global using Shouldly;
global using Moq;
global using AutoFixture;
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public async Task GetLogins_WhenUnauthorized(string password, string sessionToke
VerifyLoginCalled(keys.ClientId, keys.ClientSecret, Times.Once());
VerifyUnlockCalled(password, Times.Once());
VerifyGetLoginsCalled(sessionToken, Times.Once());
logins.Should().BeEquivalentTo(items);
logins.ShouldBeEquivalentTo(items);
}

[Theory]
Expand All @@ -171,7 +171,7 @@ public async Task GetLogins_WhenLocked(string password, string sessionToken, Lis
VerifyLoginNotCalled();
VerifyUnlockCalled(password, Times.Once());
VerifyGetLoginsCalled(sessionToken, Times.Once());
logins.Should().BeEquivalentTo(items);
logins.ShouldBeEquivalentTo(items);
}

[Theory]
Expand All @@ -192,9 +192,7 @@ public async Task GetLogins_WhenResultFailed(string password, string sessionToke
Func<Task> act = () => _bwClientMock.Object.GetItems();

await act
.Should()
.ThrowAsync<Exception>()
.WithMessage("Failed to get logins");
.ShouldThrowAsync<Exception>("Failed to get logins");

VerifyLoginNotCalled();
VerifyUnlockCalled(password, Times.Once());
Expand All @@ -215,9 +213,7 @@ public async Task GetLogins_WhenFailedToGetPassword()
Func<Task> act = () => _bwClientMock.Object.GetItems();

await act
.Should()
.ThrowAsync<Exception>()
.WithMessage("Could not retrieve master password");
.ShouldThrowAsync<Exception>("Could not retrieve master password");

VerifyLoginNotCalled();
VerifyUnlockCalled(It.IsAny<string>(), Times.Never());
Expand All @@ -236,9 +232,7 @@ public async Task GetLogins_WhenFailedToGetApiKey()
Func<Task> act = () => _bwClientMock.Object.GetItems();

await act
.Should()
.ThrowAsync<Exception>()
.WithMessage("Could not retrieve Api Keys to login");
.ShouldThrowAsync<Exception>("Could not retrieve Api Keys to login");

VerifyLoginNotCalled();
VerifyUnlockCalled(It.IsAny<string>(), Times.Never());
Expand All @@ -257,9 +251,7 @@ public async Task GetLogins_WhenUnknownStatusReceived()
Func<Task> act = () => _bwClientMock.Object.GetItems();

await act
.Should()
.ThrowAsync<Exception>()
.WithMessage("Unknown status received");
.ShouldThrowAsync<Exception>("Unknown status received");

VerifyLoginNotCalled();
VerifyUnlockCalled(It.IsAny<string>(), Times.Never());
Expand Down Expand Up @@ -291,6 +283,6 @@ public async Task GetLogins_ShouldSyncWhenOutdated(string password, string sessi
.Verify(c => c.Request<string>(EmptyEnvVars, "sync"), Times.Once());
VerifyUnlockCalled(password, Times.Once());
VerifyGetLoginsCalled(sessionToken, Times.Once());
logins.Should().BeEquivalentTo(items);
logins.ShouldBeEquivalentTo(items);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,6 @@ public void Deserialize_ValidJson_ReturnsObject()
]
""";
var obj = JsonSerializer.Deserialize<IEnumerable<Item>>(str, BwClient.SerializeOptions);
obj.Should().NotBeNull();
obj.ShouldNotBeNull();
}
}
21 changes: 11 additions & 10 deletions tests/Bw.VaultDigest.UnitTests/Infrastructure/LoginsMappingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ public void LoginMapping_ShouldMapLoginsOnly()

var logins = items.ToLogins(DateTime.Now);

logins.Should().HaveCount(loginItems.Length);
logins.Should().OnlyContain(l => loginItems.Any(li => li.Id == l.Id));
logins.Count.ShouldBe(loginItems.Length);
logins.ShouldContain(l => loginItems.Any(li => li.Id == l.Id));
logins.ShouldNotContain(l => loginItems.All(li => li.Id != l.Id));
}

private class StrengthCalculationData : TheoryData<Strength, string>
Expand Down Expand Up @@ -215,10 +216,10 @@ public void LoginMapping_StrengthCalculation(Strength expectedStrength, string p

var logins = items.ToLogins(_fixture.Create<DateTime>());

logins.Should().HaveCount(1);
logins[0].Id.Should().Be(item.Id);
logins[0].Name.Should().Be(item.Name);
logins[0].Strength.Should().Be(expectedStrength);
logins.Count.ShouldBe(1);
logins[0].Id.ShouldBe(item.Id);
logins[0].Name.ShouldBe(item.Name);
logins[0].Strength.ShouldBe(expectedStrength);
}

private class AgeCalculationData : TheoryData<Age, DateTime, DateTime>
Expand Down Expand Up @@ -256,9 +257,9 @@ public void LoginMapping_AgeCalculation(Age expectedAge, DateTime date, DateTime

var logins = items.ToLogins(now);

logins.Should().HaveCount(1);
logins[0].Id.Should().Be(item.Id);
logins[0].Name.Should().Be(item.Name);
logins[0].Age.Should().Be(expectedAge);
logins.Count.ShouldBe(1);
logins[0].Id.ShouldBe(item.Id);
logins[0].Name.ShouldBe(item.Name);
logins[0].Age.ShouldBe(expectedAge);
}
}
24 changes: 12 additions & 12 deletions tests/Bw.VaultDigest.UnitTests/Services/DigestServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public void ToStrengthSlices_Spec()
var result =
logins.ToList().ToStrengthSlices();

result.Should().HaveCount(5);
result.Should().Contain(s => s.FillColor == Colors.Red && s.Value == 5);
result.Should().Contain(s => s.FillColor == Colors.Orange && s.Value == 7);
result.Should().Contain(s => s.FillColor == Colors.Yellow && s.Value == 9);
result.Should().Contain(s => s.FillColor == Colors.LightGreen && s.Value == 12);
result.Should().Contain(s => s.FillColor == Colors.Green && s.Value == 15);
result.Count.ShouldBe(5);
result.ShouldContain(s => s.FillColor == Colors.Red && s.Value == 5);
result.ShouldContain(s => s.FillColor == Colors.Orange && s.Value == 7);
result.ShouldContain(s => s.FillColor == Colors.Yellow && s.Value == 9);
result.ShouldContain(s => s.FillColor == Colors.LightGreen && s.Value == 12);
result.ShouldContain(s => s.FillColor == Colors.Green && s.Value == 15);
}

[Fact]
Expand All @@ -51,11 +51,11 @@ public void ToAgesSlices_Spec()
var result =
logins.ToList().ToAgeSlices();

result.Should().HaveCount(5);
result.Should().Contain(s => s.FillColor == Colors.Red && s.Value == 5);
result.Should().Contain(s => s.FillColor == Colors.Orange && s.Value == 7);
result.Should().Contain(s => s.FillColor == Colors.Yellow && s.Value == 9);
result.Should().Contain(s => s.FillColor == Colors.LightGreen && s.Value == 12);
result.Should().Contain(s => s.FillColor == Colors.Green && s.Value == 15);
result.Count.ShouldBe(5);
result.ShouldContain(s => s.FillColor == Colors.Red && s.Value == 5);
result.ShouldContain(s => s.FillColor == Colors.Orange && s.Value == 7);
result.ShouldContain(s => s.FillColor == Colors.Yellow && s.Value == 9);
result.ShouldContain(s => s.FillColor == Colors.LightGreen && s.Value == 12);
result.ShouldContain(s => s.FillColor == Colors.Green && s.Value == 15);
}
}
Loading