Removes FluentAssertions library from test projects, due to licensing changes

This commit is contained in:
BinaryAlley committed 2025-02-03 00:31:15 +02:00
1 parent c1100e5398
commit d46bfae4fc
235 files changed
+4468 -4725

No files matched your search

@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.Infrastructure.Time;
using Lumina.Infrastructure.Common.Models.Configuration;
using Lumina.Infrastructure.Core.Authentication;
@@ -55,19 +54,20 @@ public class JwtTokenGeneratorTests
string token = _sut.GenerateToken(userId, username);
// Assert
token.Should().NotBeNullOrEmpty();
Assert.NotNull(token);
Assert.NotEmpty(token);
JwtSecurityToken jwtToken = tokenHandler.ReadJwtToken(token);
// verify token properties
jwtToken.Issuer.Should().Be(_jwtSettings.Issuer);
jwtToken.Audiences.Should().ContainSingle().Which.Should().Be(_jwtSettings.Audience);
jwtToken.ValidTo.Should().Be(_fixedUtcNow.AddMinutes(_jwtSettings.ExpiryMinutes));
Assert.Equal(_jwtSettings.Issuer, jwtToken.Issuer);
Assert.Single(jwtToken.Audiences, _jwtSettings.Audience);
Assert.Equal(_fixedUtcNow.AddMinutes(_jwtSettings.ExpiryMinutes), jwtToken.ValidTo);
// verify claims
jwtToken.Claims.Should().Contain(c => c.Type == JwtRegisteredClaimNames.Sub && c.Value == userId);
jwtToken.Claims.Should().Contain(c => c.Type == JwtRegisteredClaimNames.UniqueName && c.Value == username);
jwtToken.Claims.Should().Contain(c => c.Type == JwtRegisteredClaimNames.Jti && c.Value == userId);
Assert.Contains(jwtToken.Claims, c => c.Type == JwtRegisteredClaimNames.Sub && c.Value == userId);
Assert.Contains(jwtToken.Claims, c => c.Type == JwtRegisteredClaimNames.UniqueName && c.Value == username);
Assert.Contains(jwtToken.Claims, c => c.Type == JwtRegisteredClaimNames.Jti && c.Value == userId);
// verify the token is actually valid
TokenValidationParameters validationParameters = new()
@@ -86,8 +86,8 @@ public class JwtTokenGeneratorTests
ClaimsPrincipal principal = tokenHandler.ValidateToken(token, validationParameters, out SecurityToken validatedToken);
principal.Should().NotBeNull();
validatedToken.Should().NotBeNull();
Assert.NotNull(principal);
Assert.NotNull(validatedToken);
}
[Fact]
@@ -102,7 +102,7 @@ public class JwtTokenGeneratorTests
JwtSecurityToken jwtToken = tokenHandler.ReadJwtToken(token);
// Assert
jwtToken.ValidTo.Should().Be(_fixedUtcNow.AddMinutes(_jwtSettings.ExpiryMinutes));
Assert.Equal(_fixedUtcNow.AddMinutes(_jwtSettings.ExpiryMinutes), jwtToken.ValidTo);
_ = _mockDateTimeProvider.Received(1).UtcNow;
}
@@ -118,7 +118,7 @@ public class JwtTokenGeneratorTests
string token2 = _sut.GenerateToken(userId2, username2);
// Assert
token1.Should().NotBe(token2);
Assert.NotEqual(token1, token2);
}
[Fact]
@@ -132,6 +132,6 @@ public class JwtTokenGeneratorTests
string token2 = _sut.GenerateToken(userId, username);
// Assert
token1.Should().Be(token2);
Assert.Equal(token1, token2);
}
}
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using FluentAssertions;
using Lumina.Infrastructure.Common.Errors;
using Lumina.Infrastructure.Common.Models.Configuration;
using Lumina.Infrastructure.Common.Validators;
@@ -39,8 +38,8 @@ public class QRCodeGeneratorTests
string result = _sut.GenerateQrCodeDataUri(username, secret);
// Assert
result.Should().StartWith("data:image/png;base64,");
result.Should().Match(uri => IsBase64String(uri.Substring(22))); // Skip "data:image/png;base64,"
Assert.StartsWith("data:image/png;base64,", result);
Assert.True(IsBase64String(result[22..])); // skip "data:image/png;base64,"
}
[Fact]
@@ -54,8 +53,8 @@ public class QRCodeGeneratorTests
string result = _sut.GenerateQrCodeDataUri(username, secret);
// Assert
result.Should().StartWith("data:image/png;base64,");
result.Should().Match(uri => IsBase64String(uri.Substring(22)));
Assert.StartsWith("data:image/png;base64,", result);
Assert.True(IsBase64String(result[22..]));
}
[Fact]
@@ -70,7 +69,7 @@ public class QRCodeGeneratorTests
string result2 = _sut.GenerateQrCodeDataUri(username2, secret);
// Assert
result1.Should().NotBe(result2);
Assert.NotEqual(result1, result2);
}
[Fact]
@@ -84,7 +83,7 @@ public class QRCodeGeneratorTests
string result2 = _sut.GenerateQrCodeDataUri(username, secret);
// Assert
result1.Should().Be(result2);
Assert.Equal(result1, result2);
}
[Theory]
@@ -99,8 +98,8 @@ public class QRCodeGeneratorTests
string result = _sut.GenerateQrCodeDataUri(invalidUsername!, secret);
// Assert
result.Should().StartWith("data:image/png;base64,");
result.Should().Match(uri => IsBase64String(uri.Substring(22)));
Assert.StartsWith("data:image/png;base64,", result);
Assert.True(IsBase64String(result[22..]));
}
[Theory]
@@ -117,8 +116,8 @@ public class QRCodeGeneratorTests
string result = _sut.GenerateQrCodeDataUri(username, secret);
// Assert
result.Should().StartWith("data:image/png;base64,");
result.Should().Match(uri => IsBase64String(uri.Substring(22)));
Assert.StartsWith("data:image/png;base64,", result);
Assert.True(IsBase64String(result[22..]));
}
[Fact]
@@ -132,8 +131,8 @@ public class QRCodeGeneratorTests
string result = _sut.GenerateQrCodeDataUri(username, shortSecret);
// Assert
result.Should().StartWith("data:image/png;base64,");
result.Should().Match(uri => IsBase64String(uri.Substring(22)));
Assert.StartsWith("data:image/png;base64,", result);
Assert.True(IsBase64String(result[22..]));
}
private static bool IsBase64String(string base64)
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Infrastructure.Core.Authentication;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -29,7 +28,8 @@ public class TokenGeneratorTests
string token = _sut.GenerateToken();
// Assert
token.Should().NotBeNullOrEmpty();
Assert.NotNull(token);
Assert.NotEmpty(token);
}
[Fact]
@@ -39,9 +39,9 @@ public class TokenGeneratorTests
string token = _sut.GenerateToken();
// Assert
token.Should().NotContain("+", "Token should not contain '+'");
token.Should().NotContain("/", "Token should not contain '/'");
token.Should().NotContain("=", "Token should not contain '='");
Assert.DoesNotContain("+", token);
Assert.DoesNotContain("/", token);
Assert.DoesNotContain("=", token);
}
[Fact]
@@ -53,9 +53,9 @@ public class TokenGeneratorTests
string token3 = _sut.GenerateToken();
// Assert
token1.Should().NotBe(token2);
token1.Should().NotBe(token3);
token2.Should().NotBe(token3);
Assert.NotEqual(token1, token2);
Assert.NotEqual(token1, token3);
Assert.NotEqual(token2, token3);
}
[Fact]
@@ -66,6 +66,6 @@ public class TokenGeneratorTests
// Assert
// 32 bytes in Base64 without padding should be 43 characters
token.Length.Should().Be(43);
Assert.Equal(43, token.Length);
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Infrastructure.Core.Authentication;
using OtpNet;
using System.Diagnostics.CodeAnalysis;
@@ -30,7 +29,7 @@ public class TotpTokenGeneratorTests
byte[] secret = _sut.GenerateSecret();
// Assert
secret.Should().NotBeEmpty();
Assert.NotEmpty(secret);
}
[Fact]
@@ -42,9 +41,9 @@ public class TotpTokenGeneratorTests
byte[] secret3 = _sut.GenerateSecret();
// Assert
secret1.Should().NotBeEquivalentTo(secret2);
secret1.Should().NotBeEquivalentTo(secret3);
secret2.Should().NotBeEquivalentTo(secret3);
Assert.NotEqual(secret1, secret2);
Assert.NotEqual(secret1, secret3);
Assert.NotEqual(secret2, secret3);
}
[Fact]
@@ -59,7 +58,7 @@ public class TotpTokenGeneratorTests
bool result = _sut.ValidateToken(secret, validToken);
// Assert
result.Should().BeTrue();
Assert.True(result);
}
[Theory]
@@ -78,7 +77,7 @@ public class TotpTokenGeneratorTests
bool result = _sut.ValidateToken(secret, invalidToken);
// Assert
result.Should().BeFalse();
Assert.False(result);
}
[Fact]
@@ -94,7 +93,7 @@ public class TotpTokenGeneratorTests
bool result = _sut.ValidateToken(secret2, token);
// Assert
result.Should().BeFalse();
Assert.False(result);
}
[Fact]
@@ -104,6 +103,6 @@ public class TotpTokenGeneratorTests
byte[] secret = _sut.GenerateSecret();
// Assert
secret.Length.Should().Be(20); // Standard TOTP secret length
Assert.Equal(20, secret.Length); // standard TOTP secret length
}
}
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
@@ -59,7 +58,7 @@ public class AuthorizationServiceTests
bool result = await _sut.HasPermissionAsync(userId, AuthorizationPermission.CanViewUsers, CancellationToken.None);
// Assert
result.Should().BeFalse();
Assert.False(result);
await _mockUserRepository.Received(1).GetByIdAsync(userId, Arg.Any<CancellationToken>());
}
@@ -76,7 +75,7 @@ public class AuthorizationServiceTests
bool result = await _sut.HasPermissionAsync(userId, AuthorizationPermission.CanViewUsers, CancellationToken.None);
// Assert
result.Should().BeFalse();
Assert.False(result);
await _mockUserRepository.Received(1).GetByIdAsync(userId, Arg.Any<CancellationToken>());
}
@@ -94,7 +93,7 @@ public class AuthorizationServiceTests
bool result = await _sut.HasPermissionAsync(user.Id, AuthorizationPermission.CanViewUsers, CancellationToken.None);
// Assert
result.Should().BeTrue();
Assert.True(result);
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, Arg.Any<CancellationToken>());
}
@@ -117,7 +116,7 @@ public class AuthorizationServiceTests
bool result = await _sut.HasPermissionAsync(user.Id, AuthorizationPermission.CanViewUsers, CancellationToken.None);
// Assert
result.Should().BeTrue();
Assert.True(result);
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, Arg.Any<CancellationToken>());
}
@@ -134,7 +133,7 @@ public class AuthorizationServiceTests
bool result = await _sut.HasPermissionAsync(user.Id, AuthorizationPermission.CanViewUsers, CancellationToken.None);
// Assert
result.Should().BeFalse();
Assert.False(result);
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, Arg.Any<CancellationToken>());
}
@@ -152,7 +151,7 @@ public class AuthorizationServiceTests
bool result = await _sut.HasPermissionAsync(user.Id, AuthorizationPermission.CanViewUsers, CancellationToken.None);
// Assert
result.Should().BeFalse();
Assert.False(result);
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, Arg.Any<CancellationToken>());
}
@@ -176,7 +175,7 @@ public class AuthorizationServiceTests
bool result = await _sut.HasPermissionAsync(user.Id, AuthorizationPermission.CanViewUsers, CancellationToken.None);
// Assert
result.Should().BeTrue();
Assert.True(result);
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, Arg.Any<CancellationToken>());
}
@@ -192,7 +191,7 @@ public class AuthorizationServiceTests
bool result = await _sut.IsInRoleAsync(userId, "Admin", CancellationToken.None);
// Assert
result.Should().BeFalse();
Assert.False(result);
await _mockUserRepository.Received(1).GetByIdAsync(userId, Arg.Any<CancellationToken>());
}
@@ -209,7 +208,7 @@ public class AuthorizationServiceTests
bool result = await _sut.IsInRoleAsync(userId, "Admin", CancellationToken.None);
// Assert
result.Should().BeFalse();
Assert.False(result);
await _mockUserRepository.Received(1).GetByIdAsync(userId, Arg.Any<CancellationToken>());
}
@@ -232,7 +231,7 @@ public class AuthorizationServiceTests
bool result = await _sut.IsInRoleAsync(user.Id, "Admin", CancellationToken.None);
// Assert
result.Should().BeTrue();
Assert.True(result);
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, Arg.Any<CancellationToken>());
}
@@ -255,7 +254,7 @@ public class AuthorizationServiceTests
bool result = await _sut.IsInRoleAsync(user.Id, "Admin", CancellationToken.None);
// Assert
result.Should().BeFalse();
Assert.False(result);
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, Arg.Any<CancellationToken>());
}
@@ -272,7 +271,7 @@ public class AuthorizationServiceTests
bool result = await _sut.IsInRoleAsync(user.Id, "Admin", CancellationToken.None);
// Assert
result.Should().BeFalse();
Assert.False(result);
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, Arg.Any<CancellationToken>());
}
@@ -292,7 +291,7 @@ public class AuthorizationServiceTests
bool result = await _sut.EvaluatePolicyAsync<IAuthorizationPolicy>(userId, CancellationToken.None);
// Assert
result.Should().BeTrue();
Assert.True(result);
await mockPolicy.Received(1).EvaluateAsync(userId, Arg.Any<CancellationToken>());
_mockAuthorizationPolicyFactory.Received(1).CreatePolicy<IAuthorizationPolicy>();
}
@@ -313,7 +312,7 @@ public class AuthorizationServiceTests
bool result = await _sut.EvaluatePolicyAsync<IAuthorizationPolicy>(userId, CancellationToken.None);
// Assert
result.Should().BeFalse();
Assert.False(result);
await mockPolicy.Received(1).EvaluateAsync(userId, Arg.Any<CancellationToken>());
_mockAuthorizationPolicyFactory.Received(1).CreatePolicy<IAuthorizationPolicy>();
}
@@ -334,8 +333,8 @@ public class AuthorizationServiceTests
Func<Task> act = async () => await _sut.EvaluatePolicyAsync<IAuthorizationPolicy>(userId, CancellationToken.None);
// Assert
await act.Should().ThrowAsync<InvalidOperationException>()
.WithMessage("Policy evaluation failed");
InvalidOperationException exception = await Assert.ThrowsAsync<InvalidOperationException>(act);
Assert.Equal("Policy evaluation failed", exception.Message);
await mockPolicy.Received(1).EvaluateAsync(userId, Arg.Any<CancellationToken>());
_mockAuthorizationPolicyFactory.Received(1).CreatePolicy<IAuthorizationPolicy>();
}
@@ -352,8 +351,8 @@ public class AuthorizationServiceTests
Func<Task> act = async () => await _sut.EvaluatePolicyAsync<IAuthorizationPolicy>(userId, CancellationToken.None);
// Assert
await act.Should().ThrowAsync<InvalidOperationException>()
.WithMessage("Policy creation failed");
InvalidOperationException exception = await Assert.ThrowsAsync<InvalidOperationException>(act);
Assert.Equal("Policy creation failed", exception.Message);
_mockAuthorizationPolicyFactory.Received(1).CreatePolicy<IAuthorizationPolicy>();
}
@@ -392,7 +391,7 @@ public class AuthorizationServiceTests
bool result = await _sut.EvaluatePolicyAsync<ITestAuthorizationPolicy>(userId, CancellationToken.None);
// Assert
result.Should().BeTrue();
Assert.True(result);
await mockPolicy.Received(1).EvaluateAsync(userId, Arg.Any<CancellationToken>());
_mockAuthorizationPolicyFactory.Received(1).CreatePolicy<ITestAuthorizationPolicy>();
}
@@ -409,8 +408,8 @@ public class AuthorizationServiceTests
ErrorOr<UserAuthorizationEntity> result = await _sut.GetUserAuthorizationAsync(userId, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Users.UserDoesNotExist);
Assert.True(result.IsError);
Assert.Equal(Errors.Users.UserDoesNotExist, result.FirstError);
await _mockUserRepository.Received(1).GetByIdAsync(userId, Arg.Any<CancellationToken>());
}
@@ -427,8 +426,8 @@ public class AuthorizationServiceTests
ErrorOr<UserAuthorizationEntity> result = await _sut.GetUserAuthorizationAsync(userId, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
await _mockUserRepository.Received(1).GetByIdAsync(userId, Arg.Any<CancellationToken>());
}
@@ -444,10 +443,10 @@ public class AuthorizationServiceTests
ErrorOr<UserAuthorizationEntity> result = await _sut.GetUserAuthorizationAsync(user.Id, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.UserId.Should().Be(user.Id);
result.Value.Role.Should().BeNull();
result.Value.Permissions.Should().BeEmpty();
Assert.False(result.IsError);
Assert.Equal(user.Id, result.Value.UserId);
Assert.Null(result.Value.Role);
Assert.Empty(result.Value.Permissions);
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, Arg.Any<CancellationToken>());
}
@@ -469,14 +468,11 @@ public class AuthorizationServiceTests
ErrorOr<UserAuthorizationEntity> result = await _sut.GetUserAuthorizationAsync(user.Id, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.UserId.Should().Be(user.Id);
result.Value.Role.Should().BeNull();
result.Value.Permissions.Should().BeEquivalentTo(
[
AuthorizationPermission.CanViewUsers,
AuthorizationPermission.CanDeleteUsers
]);
Assert.False(result.IsError);
Assert.Equal(user.Id, result.Value.UserId);
Assert.Null(result.Value.Role);
Assert.Equal([AuthorizationPermission.CanViewUsers, AuthorizationPermission.CanDeleteUsers],
result.Value.Permissions);
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, Arg.Any<CancellationToken>());
}
@@ -502,14 +498,11 @@ public class AuthorizationServiceTests
ErrorOr<UserAuthorizationEntity> result = await _sut.GetUserAuthorizationAsync(user.Id, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.UserId.Should().Be(user.Id);
result.Value.Role.Should().BeEquivalentTo("Admin");
result.Value.Permissions.Should().BeEquivalentTo(
[
AuthorizationPermission.CanViewUsers,
AuthorizationPermission.CanDeleteUsers
]);
Assert.False(result.IsError);
Assert.Equal(user.Id, result.Value.UserId);
Assert.Equal("Admin", result.Value.Role);
Assert.Equal([AuthorizationPermission.CanViewUsers, AuthorizationPermission.CanDeleteUsers],
result.Value.Permissions);
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, Arg.Any<CancellationToken>());
}
@@ -536,15 +529,18 @@ public class AuthorizationServiceTests
ErrorOr<UserAuthorizationEntity> result = await _sut.GetUserAuthorizationAsync(user.Id, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.UserId.Should().Be(user.Id);
result.Value.Role.Should().BeEquivalentTo("Admin");
result.Value.Permissions.Should().BeEquivalentTo(
[
AuthorizationPermission.CanViewUsers,
AuthorizationPermission.CanDeleteUsers,
AuthorizationPermission.CanRegisterUsers
]);
Assert.False(result.IsError);
Assert.Equal(user.Id, result.Value.UserId);
Assert.Equal("Admin", result.Value.Role);
Assert.Equivalent(
new HashSet<AuthorizationPermission>
{
AuthorizationPermission.CanViewUsers,
AuthorizationPermission.CanDeleteUsers,
AuthorizationPermission.CanRegisterUsers
},
result.Value.Permissions
);
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, Arg.Any<CancellationToken>());
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.Infrastructure.Authorization.Policies.Common.Base;
using Lumina.Infrastructure.Core.Authorization.Policies.Common.Factory;
using Lumina.Infrastructure.UnitTests.Core.Authorization.Policies.Common.Factory.Fixtures;
@@ -32,9 +31,9 @@ public class AuthorizationPolicyFactoryTests
TestAuthorizationPolicy result = policyFactory.CreatePolicy<TestAuthorizationPolicy>();
// Assert
result.Should().NotBeNull();
result.Should().BeAssignableTo<IAuthorizationPolicy>();
result.Should().BeOfType<TestAuthorizationPolicy>();
Assert.NotNull(result);
Assert.IsAssignableFrom<IAuthorizationPolicy>(result);
Assert.IsType<TestAuthorizationPolicy>(result);
}
[Fact]
@@ -47,8 +46,10 @@ public class AuthorizationPolicyFactoryTests
// Act & Assert
Action act = () => policyFactory.CreatePolicy<IUnregisteredPolicy>();
act.Should().Throw<InvalidOperationException>()
.WithMessage("No service for type 'Lumina.Infrastructure.UnitTests.Core.Authorization.Policies.Common.Factory.Fixtures.IUnregisteredPolicy' has been registered.");
InvalidOperationException exception = Assert.Throws<InvalidOperationException>(() =>
policyFactory.CreatePolicy<IUnregisteredPolicy>());
Assert.Equal("No service for type 'Lumina.Infrastructure.UnitTests.Core.Authorization.Policies.Common.Factory.Fixtures.IUnregisteredPolicy' has been registered.",
exception.Message);
}
[Fact]
@@ -61,7 +62,6 @@ public class AuthorizationPolicyFactoryTests
AuthorizationPolicyFactory policyFactory = new(mockServiceProvider);
// Act & Assert
Action act = () => policyFactory.CreatePolicy<TestAuthorizationPolicy>();
act.Should().Throw<InvalidOperationException>();
Assert.Throws<InvalidOperationException>(() => policyFactory.CreatePolicy<TestAuthorizationPolicy>());
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Infrastructure.Common.Models.Configuration;
using Lumina.Infrastructure.Core.Security;
using Lumina.Infrastructure.UnitTests.Core.Security.Fixtures;
@@ -39,8 +38,9 @@ public class CryptographyServiceTests
string result = _sut.Encrypt(plaintext);
// Assert
result.Should().NotBeNullOrEmpty();
result.Should().NotBe(plaintext);
Assert.NotNull(result);
Assert.NotEmpty(result);
Assert.NotEqual(plaintext, result);
}
[Fact]
@@ -54,7 +54,7 @@ public class CryptographyServiceTests
string result2 = _sut.Encrypt(plaintext);
// Assert
result1.Should().NotBe(result2);
Assert.NotEqual(result1, result2);
}
[Theory]
@@ -66,9 +66,9 @@ public class CryptographyServiceTests
Action act = () => _sut.Encrypt(invalidInput!);
// Assert
act.Should().Throw<ArgumentException>()
.WithParameterName("plaintext")
.WithMessage("Value cannot be null or empty*");
ArgumentException exception = Assert.Throws<ArgumentException>(() => _sut.Encrypt(invalidInput!));
Assert.Equal("plaintext", exception.ParamName);
Assert.StartsWith("Value cannot be null or empty", exception.Message);
}
[Fact]
@@ -82,7 +82,7 @@ public class CryptographyServiceTests
string decrypted = _sut.Decrypt(encrypted);
// Assert
decrypted.Should().Be(originalText);
Assert.Equal(originalText, decrypted);
}
[Theory]
@@ -94,9 +94,9 @@ public class CryptographyServiceTests
Action act = () => _sut.Decrypt(invalidInput!);
// Assert
act.Should().Throw<ArgumentException>()
.WithParameterName("ciphertext")
.WithMessage("Value cannot be null or empty*");
ArgumentException exception = Assert.Throws<ArgumentException>(() => _sut.Decrypt(invalidInput!));
Assert.Equal("ciphertext", exception.ParamName);
Assert.StartsWith("Value cannot be null or empty", exception.Message);
}
[Theory]
@@ -108,7 +108,7 @@ public class CryptographyServiceTests
Action act = () => _sut.Decrypt(invalidInput);
// Assert
act.Should().Throw<FormatException>();
Assert.Throws<FormatException>(() => _sut.Decrypt(invalidInput));
}
[Fact]
@@ -121,8 +121,8 @@ public class CryptographyServiceTests
Action act = () => _sut.Decrypt(shortCiphertext);
// Assert
act.Should().Throw<ArgumentException>()
.WithMessage("Invalid ciphertext");
ArgumentException exception = Assert.Throws<ArgumentException>(() => _sut.Decrypt(shortCiphertext));
Assert.Equal("Invalid ciphertext", exception.Message);
}
[Fact]
@@ -141,7 +141,7 @@ public class CryptographyServiceTests
Action act = () => _sut.Decrypt(corrupted);
// Assert
act.Should().Throw<CryptographicException>();
Assert.Throws<CryptographicException>(() => _sut.Decrypt(corrupted));
}
[Fact]
@@ -155,7 +155,6 @@ public class CryptographyServiceTests
_sut.Dispose();
// Assert
Action act = () => _sut.Decrypt(encrypted);
act.Should().Throw<CryptographicException>();
Assert.Throws<CryptographicException>(() => _sut.Decrypt(encrypted));
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Infrastructure.Core.Security;
using System;
using System.Diagnostics.CodeAnalysis;
@@ -33,8 +32,9 @@ public class HashServiceTests
string result = _sut.HashString(password);
// Assert
result.Should().NotBeNullOrEmpty();
result.Should().NotBe(password);
Assert.NotNull(result);
Assert.NotEmpty(result);
Assert.NotEqual(password, result);
}
[Fact]
@@ -48,7 +48,7 @@ public class HashServiceTests
string hash2 = _sut.HashString(password);
// Assert
hash1.Should().NotBe(hash2);
Assert.NotEqual(hash1, hash2);
}
[Theory]
@@ -63,10 +63,10 @@ public class HashServiceTests
string hash = _sut.HashString(input);
// Assert
hash.Should().NotBeNullOrEmpty();
Assert.NotNull(hash);
Assert.NotEmpty(hash);
// verify it's a valid Base64 string
Action decode = () => Convert.FromBase64String(hash);
decode.Should().NotThrow();
Assert.NotNull(Convert.FromBase64String(hash));
}
[Fact]
@@ -80,7 +80,7 @@ public class HashServiceTests
bool result = _sut.CheckStringAgainstHash(password, hash);
// Assert
result.Should().BeTrue();
Assert.True(result);
}
[Fact]
@@ -95,7 +95,7 @@ public class HashServiceTests
bool result = _sut.CheckStringAgainstHash(wrongPassword, hash);
// Assert
result.Should().BeFalse();
Assert.False(result);
}
[Theory]
@@ -111,7 +111,7 @@ public class HashServiceTests
bool result = _sut.CheckStringAgainstHash(password, invalidHash);
// Assert
result.Should().BeFalse();
Assert.False(result);
}
[Fact]
@@ -125,7 +125,7 @@ public class HashServiceTests
Action act = () => _sut.CheckStringAgainstHash(password, invalidHash);
// Assert
act.Should().Throw<FormatException>();
Assert.Throws<FormatException>(() => _sut.CheckStringAgainstHash(password, invalidHash));
}
[Theory]
@@ -136,7 +136,7 @@ public class HashServiceTests
Action act = () => _sut.HashString(nullPassword!);
// Assert
act.Should().Throw<ArgumentNullException>();
Assert.Throws<ArgumentNullException>(() => _sut.HashString(nullPassword!));
}
[Theory]
@@ -150,7 +150,7 @@ public class HashServiceTests
Action act = () => _sut.CheckStringAgainstHash(nullPassword!, hash);
// Assert
act.Should().Throw<ArgumentNullException>();
Assert.Throws<ArgumentNullException>(() => _sut.CheckStringAgainstHash(nullPassword!, hash));
}
[Fact]
@@ -160,6 +160,6 @@ public class HashServiceTests
Action act = () => _sut.CheckStringAgainstHash("password", null!);
// Assert
act.Should().Throw<ArgumentNullException>();
Assert.Throws<ArgumentNullException>(() => _sut.CheckStringAgainstHash("password", null!));
}
}