Skip to content

Commit ca8cf45

Browse files
authored
Minor internal-only refactorings for consistency (#1532)
* Stronger assertions on exception type * Move [Theory] above test data
1 parent fc5abe1 commit ca8cf45

File tree

6 files changed

+9
-9
lines changed

6 files changed

+9
-9
lines changed

src/Common/test/Net.Test/WindowsNetworkFileShareTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ public void GetErrorForKnownNumber_ReturnsKnownError()
1414
{
1515
Action action = () => WindowsNetworkFileShare.ThrowForNonZeroResult(5, "execute");
1616

17-
action.Should().ThrowExactly<IOException>().WithInnerException<Win32Exception>()
17+
action.Should().ThrowExactly<IOException>().WithInnerExceptionExactly<Win32Exception>()
1818
.WithMessage(Platform.IsWindows ? "Access is Denied*" : "Input/output error");
1919

2020
action = () => WindowsNetworkFileShare.ThrowForNonZeroResult(1222, "execute");
2121

22-
action.Should().ThrowExactly<IOException>().WithInnerException<Win32Exception>()
22+
action.Should().ThrowExactly<IOException>().WithInnerExceptionExactly<Win32Exception>()
2323
.WithMessage(Platform.IsWindows ? "The network is not present or not started." : "Unknown error 1222");
2424
}
2525

@@ -28,7 +28,7 @@ public void GetErrorForUnknownNumber_ReturnsUnKnownError()
2828
{
2929
Action action = () => WindowsNetworkFileShare.ThrowForNonZeroResult(9999, "execute");
3030

31-
action.Should().ThrowExactly<IOException>().WithInnerException<Win32Exception>()
31+
action.Should().ThrowExactly<IOException>().WithInnerExceptionExactly<Win32Exception>()
3232
.WithMessage(Platform.IsWindows ? "Unknown error (0x270f)" : "Unknown error 9999");
3333
}
3434

src/Management/test/Endpoint.Test/Actuators/CloudFoundry/CloudFoundrySecurityMiddlewareTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,8 @@ public async Task RedactsHttpHeaders()
326326
logMessages.Should().Contain("Authorization: *");
327327
}
328328

329-
[ClassData(typeof(CloudFoundrySecurityMiddlewareTestScenarios))]
330329
[Theory]
330+
[ClassData(typeof(CloudFoundrySecurityMiddlewareTestScenarios))]
331331
public async Task Returns_expected_response_on_permission_check(string scenario, HttpStatusCode? steeltoeStatusCode, string? errorMessage,
332332
string[] expectedLogs, bool useStatusCodeFromResponse)
333333
{

src/Management/test/Endpoint.Test/Actuators/CloudFoundry/PermissionsProviderTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ public async Task EmptyTokenIsUnauthorized()
3232
unauthorized.Message.Should().Be(PermissionsProvider.Messages.AuthorizationHeaderInvalid);
3333
}
3434

35+
[Theory]
3536
[InlineData(false, true, EndpointPermissions.Restricted)]
3637
[InlineData(true, true, EndpointPermissions.Full)]
37-
[Theory]
3838
public async Task ParsePermissionsResponseAsyncReturnsExpected(bool readSensitive, bool readBasic, EndpointPermissions expectedPermissions)
3939
{
4040
PermissionsProvider permissionsProvider = GetPermissionsProvider();
@@ -52,6 +52,7 @@ public async Task ParsePermissionsResponseAsyncReturnsExpected(bool readSensitiv
5252
result.Should().Be(expectedPermissions);
5353
}
5454

55+
[Theory]
5556
[InlineData("unavailable", HttpStatusCode.ServiceUnavailable, PermissionsProvider.Messages.CloudFoundryNotReachable)]
5657
[InlineData("not-found", HttpStatusCode.Unauthorized, PermissionsProvider.Messages.InvalidToken)]
5758
[InlineData("unauthorized", HttpStatusCode.Unauthorized, PermissionsProvider.Messages.InvalidToken)]
@@ -61,7 +62,6 @@ public async Task ParsePermissionsResponseAsyncReturnsExpected(bool readSensitiv
6162
"Exception of type 'System.Net.Http.HttpRequestException' with error 'NameResolutionError' was thrown")]
6263
[InlineData("no_sensitive_data", HttpStatusCode.OK, "")]
6364
[InlineData("success", HttpStatusCode.OK, "")]
64-
[Theory]
6565
public async Task Returns_expected_response_on_permission_check(string scenario, HttpStatusCode? steeltoeStatusCode, string errorMessage)
6666
{
6767
var appSettings = new Dictionary<string, string?>

src/Management/test/Endpoint.Test/Actuators/HeapDump/HeapDumperTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void Includes_captured_log_for_thrown_exception()
8080

8181
action.Should().ThrowExactly<InvalidOperationException>()
8282
.WithMessage($"Failed to create a gcdump. Captured log:{System.Environment.NewLine}Failed to perform this operation.")
83-
.WithInnerException<ArgumentException>().WithMessage("Simulated failure.");
83+
.WithInnerExceptionExactly<ArgumentException>().WithMessage("Simulated failure.");
8484
}
8585

8686
[Fact]

src/Management/test/Endpoint.Test/SpringBootAdminClient/SpringBootAdminContentNegotiationTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public sealed class SpringBootAdminContentNegotiationTest
3030
};
3131

3232
// AcceptHeader values captured from Spring Boot Admin 3.4.1
33+
[Theory]
3334
[InlineData("", $"{ActuatorV3},{SpringBootStandardAccept}", ActuatorV3)]
3435
[InlineData("beans", SpringBootStandardAccept, ActuatorV3)]
3536
[InlineData("env", SpringBootStandardAccept, ActuatorV3)]
@@ -42,7 +43,6 @@ public sealed class SpringBootAdminContentNegotiationTest
4243
[InlineData("loggers", SpringBootStandardAccept, ActuatorV3)]
4344
[InlineData("mappings", SpringBootStandardAccept, ActuatorV3)]
4445
[InlineData("threaddump", SpringBootStandardAccept, ActuatorV3)]
45-
[Theory]
4646
public async Task Responses_for_SpringBootAdmin_match_expectations(string endpoint, string acceptHeader, string responseContentType)
4747
{
4848
WebApplicationBuilder builder = TestWebApplicationBuilderFactory.Create();

src/Security/test/Authorization.Certificate.Test/ApplicationInstanceCertificateTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace Steeltoe.Security.Authorization.Certificate.Test;
66

77
public sealed class ApplicationInstanceCertificateTest
88
{
9+
[Theory]
910
[InlineData("This subject does not match a supported pattern", false, null, null)]
1011
[InlineData(
1112
"CN=34c9765d-b5da-49a7-4a53-1c58, OU=app:e5950275-afce-480a-a017-babafd3d5798 + OU=space:ab60aac2-fb64-43ab-ba24-c57a15a7e114 + OU=organization:7fe4d027-2058-4539-a40c-702ac1373905",
@@ -14,7 +15,6 @@ public sealed class ApplicationInstanceCertificateTest
1415
"CN=69ed1418-8434-4b14-9ad9-636d71ba782a, OU=app:e268b8bf-cdad-4014-a18f-1131c73d9450 + OU=space:122b942a-d7b9-4839-b26e-836654b9785f + OU=organization:a8fef16f-94c0-49e3-aa0b-ced7c3da6229",
1516
true, "a8fef16f-94c0-49e3-aa0b-ced7c3da6229", "122b942a-d7b9-4839-b26e-836654b9785f")]
1617
[InlineData("CN=\"69ed1418\", OU=app:e268b8bf + OU=space:\"122b942a\" + OU=organization:a8fef16f", true, "a8fef16f", "122b942a")]
17-
[Theory]
1818
public void SubjectParsingProducesExpectedResults(string subject, bool shouldParse, string? expectedOrgId, string? expectedSpaceId)
1919
{
2020
ApplicationInstanceCertificate.TryParse(subject, out ApplicationInstanceCertificate? instanceCertificate).Should().Be(shouldParse);

0 commit comments

Comments
 (0)