From 43f6a4a02fb608ce06479f668dc0255e71293660 Mon Sep 17 00:00:00 2001 From: Aleksander Heintz Date: Thu, 6 Mar 2025 11:00:38 +0100 Subject: [PATCH] chore: xunit v3 and shouldly --- Directory.Build.targets | 95 ++++++++++++------- Directory.Packages.props | 12 ++- .../AltinnProblemDetailsTests.cs | 22 ++--- .../AltinnValidationProblemDetailsTests.cs | 18 ++-- .../ProblemDetails.Tests/ErrorCodeTests.cs | 40 ++++---- .../ProblemDescriptorFactoryTests.cs | 10 +- .../ProblemDescriptorTests.cs | 28 +++--- .../ProblemExtensionDataTests.cs | 16 ++-- .../test/ProblemDetails.Tests/ResultTests.cs | 24 ++--- .../ValidationErrorsTests.cs | 36 +++---- ...zation.ServiceDefaults.Npgsql.Tests.csproj | 1 + ...Authorization.ServiceDefaults.Tests.csproj | 1 + .../ExampleDataTests.cs | 24 ++--- .../OpenApiExampleProviderTests.cs | 2 +- ...rn.SourceGenerator.IntegrationTests.csproj | 3 +- .../Altinn.Urn.SourceGenerator.Tests.csproj | 4 +- .../SourceGeneratorUtils.cs | 6 +- .../UrnExampleDataProviderResolverTests.cs | 8 +- .../UrnSwaggerFilterTests.cs | 27 +++--- .../test/Altinn.Urn.Tests/KeyValueUrnTests.cs | 74 +++++++-------- 20 files changed, 241 insertions(+), 210 deletions(-) diff --git a/Directory.Build.targets b/Directory.Build.targets index e2cc715..b6f532b 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -5,38 +5,67 @@ $(CoreBuildDependsOn);_CheckVersion - - false - - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - all - runtime; build; native; contentfiles; analyzers - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - + + + + + false + $(NoWarn);SA0001 + v3 + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + all + runtime; build; native; contentfiles; analyzers + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + \ No newline at end of file diff --git a/Directory.Packages.props b/Directory.Packages.props index 7e6bf40..d0f16f7 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -15,8 +15,8 @@ - + @@ -38,20 +38,24 @@ + - + - + + + + - \ No newline at end of file + diff --git a/src/Altinn.Authorization.ProblemDetails/test/ProblemDetails.Tests/AltinnProblemDetailsTests.cs b/src/Altinn.Authorization.ProblemDetails/test/ProblemDetails.Tests/AltinnProblemDetailsTests.cs index b79222a..736c5f6 100644 --- a/src/Altinn.Authorization.ProblemDetails/test/ProblemDetails.Tests/AltinnProblemDetailsTests.cs +++ b/src/Altinn.Authorization.ProblemDetails/test/ProblemDetails.Tests/AltinnProblemDetailsTests.cs @@ -22,28 +22,28 @@ static void TestRoundTrip(ProblemDescriptor descriptor) var deserialized = JsonSerializer.Deserialize(json, _options); Assert.NotNull(deserialized); - deserialized.Detail.Should().Be(problemDetails.Detail); - deserialized.Status.Should().Be(problemDetails.Status); - deserialized.ErrorCode.Should().Be(problemDetails.ErrorCode); + deserialized.Detail.ShouldBe(problemDetails.Detail); + deserialized.Status.ShouldBe(problemDetails.Status); + deserialized.ErrorCode.ShouldBe(problemDetails.ErrorCode); } } [Fact] public void SetsStatusCode() { - TestErrors.BadRequest.StatusCode.Should().Be(HttpStatusCode.BadRequest); - TestErrors.NotFound.StatusCode.Should().Be(HttpStatusCode.NotFound); - TestErrors.InternalServerError.StatusCode.Should().Be(HttpStatusCode.InternalServerError); - TestErrors.NotImplemented.StatusCode.Should().Be(HttpStatusCode.NotImplemented); + TestErrors.BadRequest.StatusCode.ShouldBe(HttpStatusCode.BadRequest); + TestErrors.NotFound.StatusCode.ShouldBe(HttpStatusCode.NotFound); + TestErrors.InternalServerError.StatusCode.ShouldBe(HttpStatusCode.InternalServerError); + TestErrors.NotImplemented.StatusCode.ShouldBe(HttpStatusCode.NotImplemented); } [Fact] public void SetsDetail() { - TestErrors.BadRequest.Detail.Should().Be("Bad request"); - TestErrors.NotFound.Detail.Should().Be("Not found"); - TestErrors.InternalServerError.Detail.Should().Be("Internal server error"); - TestErrors.NotImplemented.Detail.Should().Be("Not implemented"); + TestErrors.BadRequest.Detail.ShouldBe("Bad request"); + TestErrors.NotFound.Detail.ShouldBe("Not found"); + TestErrors.InternalServerError.Detail.ShouldBe("Internal server error"); + TestErrors.NotImplemented.Detail.ShouldBe("Not implemented"); } internal static class TestErrors diff --git a/src/Altinn.Authorization.ProblemDetails/test/ProblemDetails.Tests/AltinnValidationProblemDetailsTests.cs b/src/Altinn.Authorization.ProblemDetails/test/ProblemDetails.Tests/AltinnValidationProblemDetailsTests.cs index e9d8d74..502f387 100644 --- a/src/Altinn.Authorization.ProblemDetails/test/ProblemDetails.Tests/AltinnValidationProblemDetailsTests.cs +++ b/src/Altinn.Authorization.ProblemDetails/test/ProblemDetails.Tests/AltinnValidationProblemDetailsTests.cs @@ -12,7 +12,7 @@ public void HasCorrectErrorCode() { var problemDetails = new AltinnValidationProblemDetails(); - problemDetails.ErrorCode.Should().Be(StdProblemDescriptors.ValidationError.ErrorCode); + problemDetails.ErrorCode.ShouldBe(StdProblemDescriptors.ValidationError.ErrorCode); } [Fact] @@ -28,9 +28,9 @@ public void CanDeserializeAsValidationProblemDetails() var deserialized = JsonSerializer.Deserialize(serialized, _options); Assert.NotNull(deserialized); - deserialized.Errors.Should().BeEmpty(); - deserialized.Status.Should().Be(problemDetails.Status); - deserialized.Detail.Should().Be(problemDetails.Detail); + deserialized.Errors.ShouldBeEmpty(); + deserialized.Status.ShouldBe(problemDetails.Status); + deserialized.Detail.ShouldBe(problemDetails.Detail); } [Fact] @@ -46,9 +46,9 @@ public void CanRoundTripThroughJson() var deserialized = JsonSerializer.Deserialize(serialized, _options); Assert.NotNull(deserialized); - deserialized.Errors.Should().BeEquivalentTo(problemDetails.Errors); - deserialized.Status.Should().Be(problemDetails.Status); - deserialized.Detail.Should().Be(problemDetails.Detail); + deserialized.Errors.ShouldBeEquivalentTo(problemDetails.Errors); + deserialized.Status.ShouldBe(problemDetails.Status); + deserialized.Detail.ShouldBe(problemDetails.Detail); } [Fact] @@ -59,8 +59,8 @@ public void CanDeserializeEmptyObject() var deserialized = JsonSerializer.Deserialize(json, _options); Assert.NotNull(deserialized); - deserialized.ErrorCode.Should().NotBe(StdProblemDescriptors.ValidationError.ErrorCode); - deserialized.Errors.Should().BeEmpty(); + deserialized.ErrorCode.ShouldNotBe(StdProblemDescriptors.ValidationError.ErrorCode); + deserialized.Errors.ShouldBeEmpty(); } private static class ValidationDescriptors diff --git a/src/Altinn.Authorization.ProblemDetails/test/ProblemDetails.Tests/ErrorCodeTests.cs b/src/Altinn.Authorization.ProblemDetails/test/ProblemDetails.Tests/ErrorCodeTests.cs index 3d640f4..c3749dd 100644 --- a/src/Altinn.Authorization.ProblemDetails/test/ProblemDetails.Tests/ErrorCodeTests.cs +++ b/src/Altinn.Authorization.ProblemDetails/test/ProblemDetails.Tests/ErrorCodeTests.cs @@ -23,27 +23,27 @@ static void CheckEquality(ErrorCodeDomain domain, uint value) var errorCode1 = domain.Code(value); var errorCode2 = domain.Code(value); - errorCode1.Should().Be(errorCode2); - errorCode1.GetHashCode().Should().Be(errorCode2.GetHashCode()); - errorCode1.Equals(errorCode2).Should().BeTrue(); - errorCode2.Equals(errorCode1).Should().BeTrue(); - errorCode1.Equals((object)errorCode2).Should().BeTrue(); - errorCode2.Equals((object)errorCode1).Should().BeTrue(); - (errorCode1 == errorCode2).Should().BeTrue(); - (errorCode2 == errorCode1).Should().BeTrue(); - (errorCode1 != errorCode2).Should().BeFalse(); - (errorCode2 != errorCode1).Should().BeFalse(); + errorCode1.ShouldBe(errorCode2); + errorCode1.GetHashCode().ShouldBe(errorCode2.GetHashCode()); + errorCode1.Equals(errorCode2).ShouldBeTrue(); + errorCode2.Equals(errorCode1).ShouldBeTrue(); + errorCode1.Equals((object)errorCode2).ShouldBeTrue(); + errorCode2.Equals((object)errorCode1).ShouldBeTrue(); + (errorCode1 == errorCode2).ShouldBeTrue(); + (errorCode2 == errorCode1).ShouldBeTrue(); + (errorCode1 != errorCode2).ShouldBeFalse(); + (errorCode2 != errorCode1).ShouldBeFalse(); var other = _domain.Code(42); - errorCode1.Should().NotBe(other); - errorCode1.Equals(other).Should().BeFalse(); - other.Equals(errorCode1).Should().BeFalse(); - errorCode1.Equals((object)other).Should().BeFalse(); - other.Equals((object)errorCode1).Should().BeFalse(); - (errorCode1 == other).Should().BeFalse(); - (other == errorCode1).Should().BeFalse(); - (errorCode1 != other).Should().BeTrue(); - (other != errorCode1).Should().BeTrue(); + errorCode1.ShouldNotBe(other); + errorCode1.Equals(other).ShouldBeFalse(); + other.Equals(errorCode1).ShouldBeFalse(); + errorCode1.Equals((object)other).ShouldBeFalse(); + other.Equals((object)errorCode1).ShouldBeFalse(); + (errorCode1 == other).ShouldBeFalse(); + (other == errorCode1).ShouldBeFalse(); + (errorCode1 != other).ShouldBeTrue(); + (other != errorCode1).ShouldBeTrue(); } } @@ -51,6 +51,6 @@ static void CheckEquality(ErrorCodeDomain domain, uint value) public void Throws_IfTooLarge() { Action act = () => _domain.Code(100_000); - act.Should().Throw(); + act.ShouldThrow(); } } diff --git a/src/Altinn.Authorization.ProblemDetails/test/ProblemDetails.Tests/ProblemDescriptorFactoryTests.cs b/src/Altinn.Authorization.ProblemDetails/test/ProblemDetails.Tests/ProblemDescriptorFactoryTests.cs index 8642677..19ca9a5 100644 --- a/src/Altinn.Authorization.ProblemDetails/test/ProblemDetails.Tests/ProblemDescriptorFactoryTests.cs +++ b/src/Altinn.Authorization.ProblemDetails/test/ProblemDetails.Tests/ProblemDescriptorFactoryTests.cs @@ -14,10 +14,10 @@ public void Create_ReturnsCorrectAltinnProblemDetails() var result = factory.Create(1, HttpStatusCode.BadRequest, "Test error"); // Assert - result.Should().NotBeNull(); - result.ErrorCode.ToString().Should().Be("TEST-00001"); - result.StatusCode.Should().Be(HttpStatusCode.BadRequest); - result.Detail.Should().Be("Test error"); + result.ShouldNotBeNull(); + result.ErrorCode.ToString().ShouldBe("TEST-00001"); + result.StatusCode.ShouldBe(HttpStatusCode.BadRequest); + result.Detail.ShouldBe("Test error"); } [Fact] @@ -25,6 +25,6 @@ public void New_WithInvalidDomainName_ThrowsArgumentException() { // Arrange & Act & Assert Action act = () => ProblemDescriptorFactory.New("TESTDOMAIN"); - act.Should().ThrowExactly(); + act.ShouldThrow(); } } diff --git a/src/Altinn.Authorization.ProblemDetails/test/ProblemDetails.Tests/ProblemDescriptorTests.cs b/src/Altinn.Authorization.ProblemDetails/test/ProblemDetails.Tests/ProblemDescriptorTests.cs index dbd6410..d0086da 100644 --- a/src/Altinn.Authorization.ProblemDetails/test/ProblemDetails.Tests/ProblemDescriptorTests.cs +++ b/src/Altinn.Authorization.ProblemDetails/test/ProblemDetails.Tests/ProblemDescriptorTests.cs @@ -20,14 +20,12 @@ public void Create_WithExtensionsDictionary_ReturnsAltinnProblemDetailsWithExten var result = descriptor.ToProblemDetails(extensions); // Assert - result.Should().NotBeNull(); - result.ErrorCode.ToString().Should().Be("TEST-00001"); - result.Status.Should().Be((int)HttpStatusCode.BadRequest); - result.Detail.Should().Be("Test error"); - result.Extensions.Should().ContainKey("Key1") - .WhoseValue.Should().Be("Value1"); - result.Extensions.Should().ContainKey("Key2") - .WhoseValue.Should().Be(123); + result.ShouldNotBeNull(); + result.ErrorCode.ToString().ShouldBe("TEST-00001"); + result.Status.ShouldBe((int)HttpStatusCode.BadRequest); + result.Detail.ShouldBe("Test error"); + result.Extensions.ShouldContainKeyAndValue("Key1", "Value1"); + result.Extensions.ShouldContainKeyAndValue("Key2", 123); } [Fact] @@ -44,13 +42,11 @@ public void Create_WithExtensionsCollectionExpression_ReturnsAltinnProblemDetail ]); // Assert - result.Should().NotBeNull(); - result.ErrorCode.ToString().Should().Be("TEST-00001"); - result.Status.Should().Be((int)HttpStatusCode.BadRequest); - result.Detail.Should().Be("Test error"); - result.Extensions.Should().ContainKey("Key1") - .WhoseValue.Should().Be("Value1"); - result.Extensions.Should().ContainKey("Key2") - .WhoseValue.Should().Be(123); + result.ShouldNotBeNull(); + result.ErrorCode.ToString().ShouldBe("TEST-00001"); + result.Status.ShouldBe((int)HttpStatusCode.BadRequest); + result.Detail.ShouldBe("Test error"); + result.Extensions.ShouldContainKeyAndValue("Key1", "Value1"); + result.Extensions.ShouldContainKeyAndValue("Key2", 123); } } diff --git a/src/Altinn.Authorization.ProblemDetails/test/ProblemDetails.Tests/ProblemExtensionDataTests.cs b/src/Altinn.Authorization.ProblemDetails/test/ProblemDetails.Tests/ProblemExtensionDataTests.cs index 32b5838..f33a0e3 100644 --- a/src/Altinn.Authorization.ProblemDetails/test/ProblemDetails.Tests/ProblemExtensionDataTests.cs +++ b/src/Altinn.Authorization.ProblemDetails/test/ProblemDetails.Tests/ProblemExtensionDataTests.cs @@ -213,10 +213,10 @@ public static void Dictionary_Values_Tests() ]; var values = (data as IDictionary).Values; - values.Should().HaveCount(4); - values.Should().BeEquivalentTo(["first value", "value", "value 2", "other value"]); - values.IsReadOnly.Should().BeTrue(); - values.Contains("value").Should().BeTrue(); + values.Count.ShouldBe(4); + values.ShouldBe((IEnumerable)["first value", "value", "value 2", "other value"]); + values.IsReadOnly.ShouldBeTrue(); + values.Contains("value").ShouldBeTrue(); } [Fact] @@ -230,10 +230,10 @@ public static void Dictionary_Keys_Tests() ]; var keys = (data as IDictionary).Keys; - keys.Should().HaveCount(4); - keys.Should().BeEquivalentTo(["first key", "key", "key", "other key"]); - keys.IsReadOnly.Should().BeTrue(); - keys.Contains("key").Should().BeTrue(); + keys.Count.ShouldBe(4); + keys.ShouldBe((IEnumerable)["first key", "key", "key", "other key"]); + keys.IsReadOnly.ShouldBeTrue(); + keys.Contains("key").ShouldBeTrue(); } private static void AssertEqual(ProblemExtensionData expected, ProblemExtensionData actual) diff --git a/src/Altinn.Authorization.ProblemDetails/test/ProblemDetails.Tests/ResultTests.cs b/src/Altinn.Authorization.ProblemDetails/test/ProblemDetails.Tests/ResultTests.cs index 972fd07..24be74f 100644 --- a/src/Altinn.Authorization.ProblemDetails/test/ProblemDetails.Tests/ResultTests.cs +++ b/src/Altinn.Authorization.ProblemDetails/test/ProblemDetails.Tests/ResultTests.cs @@ -19,7 +19,7 @@ static void Test(Result input, ErrorCode expected) _ => input.Problem.ErrorCode, }; - actual.Should().Be(expected); + actual.ShouldBe(expected); // IsProblem check actual = input switch @@ -28,7 +28,7 @@ static void Test(Result input, ErrorCode expected) _ => input.Value, }; - actual.Should().Be(expected); + actual.ShouldBe(expected); // Using the 'is' pattern with IsSuccess if (input is { IsSuccess: true }) @@ -40,7 +40,7 @@ static void Test(Result input, ErrorCode expected) actual = input.Problem.ErrorCode; } - actual.Should().Be(expected); + actual.ShouldBe(expected); // Using the 'is' pattern with IsProblem if (input is { IsProblem: true }) @@ -52,7 +52,7 @@ static void Test(Result input, ErrorCode expected) actual = input.Value; } - actual.Should().Be(expected); + actual.ShouldBe(expected); } } @@ -62,18 +62,18 @@ static void Test(Result input, ErrorCode expected) public void ValidationTestCase(bool fail) { var result = TrySomething(fail); - result.IsProblem.Should().Be(fail); + result.IsProblem.ShouldBe(fail); if (result.IsProblem) { - result.Problem.ErrorCode.Should().Be(StdProblemDescriptors.ErrorCodes.ValidationError); - result.Problem.Should().BeOfType() - .Which.Errors.Should().ContainSingle() - .Which.ErrorCode.Should().Be(StdValidationErrors.ErrorCodes.Required); + result.Problem.ErrorCode.ShouldBe(StdProblemDescriptors.ErrorCodes.ValidationError); + var problem = result.Problem.ShouldBeOfType(); + problem.Errors.Length.ShouldBe(1); + problem.Errors[0].ErrorCode.ShouldBe(StdValidationErrors.ErrorCodes.Required); } else { - result.Value.Should().Be(42); + result.Value.ShouldBe(42); } static Result TrySomething(bool fail) @@ -99,8 +99,8 @@ public void EnsureSuccess_ThrowsIfProblem() { Result result = StdProblemDescriptors.ValidationError; Action action = () => result.EnsureSuccess(); - action.Should().Throw() - .Which.Problem.ErrorCode.Should().Be(StdProblemDescriptors.ErrorCodes.ValidationError); + action.ShouldThrow() + .Problem.ErrorCode.ShouldBe(StdProblemDescriptors.ErrorCodes.ValidationError); } [Fact] diff --git a/src/Altinn.Authorization.ProblemDetails/test/ProblemDetails.Tests/ValidationErrorsTests.cs b/src/Altinn.Authorization.ProblemDetails/test/ProblemDetails.Tests/ValidationErrorsTests.cs index a841606..779afe5 100644 --- a/src/Altinn.Authorization.ProblemDetails/test/ProblemDetails.Tests/ValidationErrorsTests.cs +++ b/src/Altinn.Authorization.ProblemDetails/test/ProblemDetails.Tests/ValidationErrorsTests.cs @@ -7,8 +7,8 @@ public void DefaultValidationErrors_IsEmpty() { var errors = new ValidationErrorBuilder(); - errors.Count.Should().Be(0); - errors.IsEmpty.Should().BeTrue(); + errors.Count.ShouldBe(0); + errors.IsEmpty.ShouldBeTrue(); } [Fact] @@ -18,13 +18,13 @@ public void CanAddValidationErrors() errors.Add(StdValidationErrors.Required, "/path"); - errors.Count.Should().Be(1); - errors.IsEmpty.Should().BeFalse(); + errors.Count.ShouldBe(1); + errors.IsEmpty.ShouldBeFalse(); errors.Add(StdValidationErrors.Required, "/path2"); - errors.Count.Should().Be(2); - errors.IsEmpty.Should().BeFalse(); + errors.Count.ShouldBe(2); + errors.IsEmpty.ShouldBeFalse(); } [Fact] @@ -32,13 +32,13 @@ public void Empty_TryTo_Returns_False() { var errors = new ValidationErrorBuilder(); - errors.TryBuild(out var instance).Should().BeFalse(); - errors.TryToProblemDetails(out var details).Should().BeFalse(); - errors.TryToActionResult(out var result).Should().BeFalse(); + errors.TryBuild(out var instance).ShouldBeFalse(); + errors.TryToProblemDetails(out var details).ShouldBeFalse(); + errors.TryToActionResult(out var result).ShouldBeFalse(); - instance.Should().BeNull(); - details.Should().BeNull(); - result.Should().BeNull(); + instance.ShouldBeNull(); + details.ShouldBeNull(); + result.ShouldBeNull(); } [Fact] @@ -49,12 +49,12 @@ public void Errors_TryTo_Returns_True() errors.Add(StdValidationErrors.Required, "/path"); errors.Add(StdValidationErrors.Required, "/path2"); - errors.TryBuild(out var instance).Should().BeTrue(); - errors.TryToProblemDetails(out var details).Should().BeTrue(); - errors.TryToActionResult(out var result).Should().BeTrue(); + errors.TryBuild(out var instance).ShouldBeTrue(); + errors.TryToProblemDetails(out var details).ShouldBeTrue(); + errors.TryToActionResult(out var result).ShouldBeTrue(); - instance.Should().NotBeNull(); - details.Should().NotBeNull(); - result.Should().NotBeNull(); + instance.ShouldNotBeNull(); + details.ShouldNotBeNull(); + result.ShouldNotBeNull(); } } diff --git a/src/Altinn.Authorization.ServiceDefaults/test/ServiceDefaults.Npgsql.Tests/Altinn.Authorization.ServiceDefaults.Npgsql.Tests.csproj b/src/Altinn.Authorization.ServiceDefaults/test/ServiceDefaults.Npgsql.Tests/Altinn.Authorization.ServiceDefaults.Npgsql.Tests.csproj index 21c131e..22a1214 100644 --- a/src/Altinn.Authorization.ServiceDefaults/test/ServiceDefaults.Npgsql.Tests/Altinn.Authorization.ServiceDefaults.Npgsql.Tests.csproj +++ b/src/Altinn.Authorization.ServiceDefaults/test/ServiceDefaults.Npgsql.Tests/Altinn.Authorization.ServiceDefaults.Npgsql.Tests.csproj @@ -4,6 +4,7 @@ false true true + v2 diff --git a/src/Altinn.Authorization.ServiceDefaults/test/ServiceDefaults.Tests/Altinn.Authorization.ServiceDefaults.Tests.csproj b/src/Altinn.Authorization.ServiceDefaults/test/ServiceDefaults.Tests/Altinn.Authorization.ServiceDefaults.Tests.csproj index a741ebb..3515918 100644 --- a/src/Altinn.Authorization.ServiceDefaults/test/ServiceDefaults.Tests/Altinn.Authorization.ServiceDefaults.Tests.csproj +++ b/src/Altinn.Authorization.ServiceDefaults/test/ServiceDefaults.Tests/Altinn.Authorization.ServiceDefaults.Tests.csproj @@ -3,6 +3,7 @@ false true + v2 diff --git a/src/Altinn.Swashbuckle/test/Altinn.Swashbuckle.Tests/ExampleDataTests.cs b/src/Altinn.Swashbuckle/test/Altinn.Swashbuckle.Tests/ExampleDataTests.cs index 3fe3b1e..1e44fd1 100644 --- a/src/Altinn.Swashbuckle/test/Altinn.Swashbuckle.Tests/ExampleDataTests.cs +++ b/src/Altinn.Swashbuckle/test/Altinn.Swashbuckle.Tests/ExampleDataTests.cs @@ -49,7 +49,7 @@ public void CanGenerateTestDataForBuiltins(Type type) var enumerator = examples.GetEnumerator(); // check that it's not empty - enumerator.MoveNext().Should().BeTrue(); + enumerator.MoveNext().ShouldBeTrue(); } [Fact] @@ -61,15 +61,15 @@ public void CanAddProviders() var examples = ExampleData.GetExamples(options); Assert.NotNull(examples); - examples.Should().NotBeEmpty(); - examples.Should().Contain("foo"); - examples.Should().Contain("bar"); + examples.ShouldNotBeEmpty(); + examples.ShouldContain("foo"); + examples.ShouldContain("bar"); // can still get builtins var intExamples = ExampleData.GetExamples(options); Assert.NotNull(intExamples); - intExamples.Should().NotBeEmpty(); + intExamples.ShouldNotBeEmpty(); } [Fact] @@ -81,15 +81,15 @@ public void CanAddResolvers() var examples = ExampleData.GetExamples(options); Assert.NotNull(examples); - examples.Should().NotBeEmpty(); - examples.Should().Contain("foo"); - examples.Should().Contain("bar"); + examples.ShouldNotBeEmpty(); + examples.ShouldContain("foo"); + examples.ShouldContain("bar"); // can still get builtins var intExamples = ExampleData.GetExamples(options); Assert.NotNull(intExamples); - intExamples.Should().NotBeEmpty(); + intExamples.ShouldNotBeEmpty(); } [Fact] @@ -104,9 +104,9 @@ public void SupportsIExampleDataProvider() examples = ExampleData.GetExamples(options); Assert.NotNull(examples); - examples.Should().NotBeEmpty(); - examples.Should().Contain(new TestData { Name = "foo" }); - examples.Should().Contain(new TestData { Name = "bar" }); + examples.ShouldNotBeEmpty(); + examples.ShouldContain(new TestData { Name = "foo" }); + examples.ShouldContain(new TestData { Name = "bar" }); } private sealed class ExampleStringProvider diff --git a/src/Altinn.Swashbuckle/test/Altinn.Swashbuckle.Tests/OpenApiExampleProviderTests.cs b/src/Altinn.Swashbuckle/test/Altinn.Swashbuckle.Tests/OpenApiExampleProviderTests.cs index 407c2f3..078d6a4 100644 --- a/src/Altinn.Swashbuckle/test/Altinn.Swashbuckle.Tests/OpenApiExampleProviderTests.cs +++ b/src/Altinn.Swashbuckle/test/Altinn.Swashbuckle.Tests/OpenApiExampleProviderTests.cs @@ -15,6 +15,6 @@ public void CanGetExample() var example = provider.GetExample(); Assert.NotNull(example); - example.Should().NotBeEmpty(); + example.ShouldNotBeEmpty(); } } diff --git a/src/Altinn.Urn/test/Altinn.Urn.SourceGenerator.IntegrationTests/Altinn.Urn.SourceGenerator.IntegrationTests.csproj b/src/Altinn.Urn/test/Altinn.Urn.SourceGenerator.IntegrationTests/Altinn.Urn.SourceGenerator.IntegrationTests.csproj index c29c9e0..bdab02a 100644 --- a/src/Altinn.Urn/test/Altinn.Urn.SourceGenerator.IntegrationTests/Altinn.Urn.SourceGenerator.IntegrationTests.csproj +++ b/src/Altinn.Urn/test/Altinn.Urn.SourceGenerator.IntegrationTests/Altinn.Urn.SourceGenerator.IntegrationTests.csproj @@ -3,7 +3,8 @@ false true - + v2 + - + @@ -23,4 +23,4 @@ - + \ No newline at end of file diff --git a/src/Altinn.Urn/test/Altinn.Urn.SourceGenerator.Tests/SourceGeneratorUtils.cs b/src/Altinn.Urn/test/Altinn.Urn.SourceGenerator.Tests/SourceGeneratorUtils.cs index fba1800..1320d8b 100644 --- a/src/Altinn.Urn/test/Altinn.Urn.SourceGenerator.Tests/SourceGeneratorUtils.cs +++ b/src/Altinn.Urn/test/Altinn.Urn.SourceGenerator.Tests/SourceGeneratorUtils.cs @@ -35,18 +35,18 @@ public static async Task VerifySourceGeneratorOutput(string source, DiagnosticDe if (expectedDiagnostics.Length == 0) { - result.Diagnostics.Should().BeEmpty(); + result.Diagnostics.ShouldBeEmpty(); return; } var remaining = new HashSet(expectedDiagnostics); foreach (var diagnostic in result.Diagnostics) { - expectedDiagnostics.Should().Contain(diagnostic.Descriptor); + expectedDiagnostics.ShouldContain(diagnostic.Descriptor); remaining.Remove(diagnostic.Descriptor); } - remaining.Should().BeEmpty("All expected exceptions should be present"); + remaining.ShouldBeEmpty("All expected exceptions should be present"); } private static readonly Lazy> BaseCompilation = new(async () => diff --git a/src/Altinn.Urn/test/Altinn.Urn.Swashbuckle.Tests/UrnExampleDataProviderResolverTests.cs b/src/Altinn.Urn/test/Altinn.Urn.Swashbuckle.Tests/UrnExampleDataProviderResolverTests.cs index 8f749ef..d520ecd 100644 --- a/src/Altinn.Urn/test/Altinn.Urn.Swashbuckle.Tests/UrnExampleDataProviderResolverTests.cs +++ b/src/Altinn.Urn/test/Altinn.Urn.Swashbuckle.Tests/UrnExampleDataProviderResolverTests.cs @@ -16,14 +16,14 @@ public void CanResolveUrnsVariants() var examples = ExampleData.GetExamples(options); Assert.NotNull(examples); - examples.Should().NotBeEmpty(); + examples.ShouldNotBeEmpty(); var examplesList = examples.ToList(); - examplesList.Should().HaveCount(intExamples.Count); + examplesList.Count.ShouldBe(intExamples.Count); for (var i = 0; i < intExamples.Count; i++) { - examplesList[i].Value.Should().Be(intExamples[i]); + examplesList[i].Value.ShouldBe(intExamples[i]); } } @@ -44,6 +44,6 @@ public void UrnExamplesAreBalanced() missing.Remove(example.UrnType); } - missing.Should().BeEmpty(because: "The first N examples of PersonUrn should have N different types"); + missing.ShouldBeEmpty(customMessage: "The first N examples of PersonUrn should have N different types"); } } diff --git a/src/Altinn.Urn/test/Altinn.Urn.Swashbuckle.Tests/UrnSwaggerFilterTests.cs b/src/Altinn.Urn/test/Altinn.Urn.Swashbuckle.Tests/UrnSwaggerFilterTests.cs index 19dcde7..fbf17c4 100644 --- a/src/Altinn.Urn/test/Altinn.Urn.Swashbuckle.Tests/UrnSwaggerFilterTests.cs +++ b/src/Altinn.Urn/test/Altinn.Urn.Swashbuckle.Tests/UrnSwaggerFilterTests.cs @@ -37,13 +37,12 @@ public void Apply_ForUrnVariantType_UpdateToUrnStringWithExample() { var schema = SchemaFor(); - schema.Type.Should().Be("string"); - schema.Format.Should().Be("urn"); - schema.Pattern.Should() - .NotBeNullOrEmpty() - .And.StartWith("^urn:altinn:party:uuid:"); + schema.Type.ShouldBe("string"); + schema.Format.ShouldBe("urn"); + schema.Pattern.ShouldNotBeNullOrEmpty(); + schema.Pattern.ShouldStartWith("^urn:altinn:party:uuid:"); - schema.Example.Should().NotBeNull(); + schema.Example.ShouldNotBeNull(); } [Fact] @@ -51,16 +50,16 @@ public void Apply_ForUrn_CreatesVariantsWithExamples() { var schema = SchemaFor(); - schema.OneOf.Should().NotBeNullOrEmpty() - .And.HaveCount(PersonUrn.Variants.Length); + schema.OneOf.ShouldNotBeNull(); + schema.OneOf.ShouldNotBeEmpty(); + schema.OneOf.Count.ShouldBe(PersonUrn.Variants.Length); foreach (var variant in schema.OneOf.Select(Resolve)) { - variant.Type.Should().Be("string"); - variant.Format.Should().Be("urn"); - variant.Pattern.Should() - .NotBeNullOrEmpty() - .And.StartWith("^urn:"); + variant.Type.ShouldBe("string"); + variant.Format.ShouldBe("urn"); + variant.Pattern.ShouldNotBeNullOrEmpty(); + variant.Pattern.ShouldStartWith("^urn:"); } } @@ -69,7 +68,7 @@ public void Apply_ForJsonTypeValueObjectUrn_CreatesDiscriminator() { var schema = SchemaFor>(); - schema.Discriminator.Should().NotBeNull(); + schema.Discriminator.ShouldNotBeNull(); } //private ISchemaFilter SchemaFilter => _sut; diff --git a/src/Altinn.Urn/test/Altinn.Urn.Tests/KeyValueUrnTests.cs b/src/Altinn.Urn/test/Altinn.Urn.Tests/KeyValueUrnTests.cs index a97036c..5050ca6 100644 --- a/src/Altinn.Urn/test/Altinn.Urn.Tests/KeyValueUrnTests.cs +++ b/src/Altinn.Urn/test/Altinn.Urn.Tests/KeyValueUrnTests.cs @@ -9,44 +9,44 @@ public class KeyValueUrnTests public void Create_ThrowsIf_Null() { Action act = () => KeyValueUrn.Create(null!, 0); - act.Should().Throw(); + act.ShouldThrow(); } [Fact] public void Create_ThrowsIf_ValueIndexNegative() { Action act = () => KeyValueUrn.Create("urn:example:123", -1); - act.Should().Throw(); + act.ShouldThrow(); } [Fact] public void Create_ThrowsIf_ValueIndexGreaterOrEqualToUrnLength() { Action act = () => KeyValueUrn.Create("urn:example:123", 15); - act.Should().Throw(); + act.ShouldThrow(); } [Fact] public void Create_ThrowsIf_ValueIndexLessOrEqualTo4() { Action act = () => KeyValueUrn.Create("urn:example:123", 4); - act.Should().Throw(); + act.ShouldThrow(); } [Fact] public void Create_ThrowsIf_UrnDoesNotStartWithUrn() { Action act = () => KeyValueUrn.Create("example:123", 5); - act.Should().Throw() - .WithMessage("Urn must start with 'urn:'.*"); + act.ShouldThrow() + .Message.ShouldStartWith("Urn must start with 'urn:'."); } [Fact] public void Create_ThrowsIf_ValueNotPrecededBySeparator() { Action act = () => KeyValueUrn.Create("urn:example123", 7); - act.Should().Throw() - .WithMessage("Urn value must be preceded by a ':' separator.*"); + act.ShouldThrow() + .Message.ShouldStartWith("Urn value must be preceded by a ':' separator."); } [Theory] @@ -54,8 +54,8 @@ public void Create_ThrowsIf_ValueNotPrecededBySeparator() public void Key_ReturnsExpected(string urn, int valueIndex, string expected) { var sut = KeyValueUrn.Create(urn, valueIndex); - sut.KeySpan.ToString().Should().Be(expected); - sut.KeyMemory.ToString().Should().Be(expected); + sut.KeySpan.ToString().ShouldBe(expected); + sut.KeyMemory.ToString().ShouldBe(expected); } [Theory] @@ -63,24 +63,24 @@ public void Key_ReturnsExpected(string urn, int valueIndex, string expected) public void Value_ReturnsExpected(string urn, int valueIndex, string expected) { var sut = KeyValueUrn.Create(urn, valueIndex); - sut.ValueSpan.ToString().Should().Be(expected); - sut.ValueMemory.ToString().Should().Be(expected); + sut.ValueSpan.ToString().ShouldBe(expected); + sut.ValueMemory.ToString().ShouldBe(expected); } [Fact] public void Urn_ReturnsExpected() { var sut = KeyValueUrn.Create("urn:example:123", 12); - sut.Urn.Should().Be("urn:example:123"); - sut.AsSpan().ToString().Should().Be("urn:example:123"); - sut.AsMemory().ToString().Should().Be("urn:example:123"); + sut.Urn.ShouldBe("urn:example:123"); + sut.AsSpan().ToString().ShouldBe("urn:example:123"); + sut.AsMemory().ToString().ShouldBe("urn:example:123"); } [Fact] public void HasValue_ReturnsTrue() { var sut = KeyValueUrn.Create("urn:example:123", 12); - sut.HasValue.Should().BeTrue(); + sut.HasValue.ShouldBeTrue(); } [Fact] @@ -88,8 +88,8 @@ public void Equals_ReturnsTrue_WhenEqual() { var sut1 = KeyValueUrn.Create("urn:example:123", 12); var sut2 = KeyValueUrn.Create("urn:example:123", 12); - sut1.Equals(sut2).Should().BeTrue(); - sut1.GetHashCode().Should().Be(sut2.GetHashCode()); + sut1.Equals(sut2).ShouldBeTrue(); + sut1.GetHashCode().ShouldBe(sut2.GetHashCode()); } [Fact] @@ -97,7 +97,7 @@ public void Equals_ReturnsFalse_WhenDifferent_Urn() { var sut1 = KeyValueUrn.Create("urn:example:123", 12); var sut2 = KeyValueUrn.Create("urn:example:456", 12); - sut1.Equals(sut2).Should().BeFalse(); + sut1.Equals(sut2).ShouldBeFalse(); } [Fact] @@ -105,17 +105,17 @@ public void Equals_ReturnsFalse_WhenDifferent_ValueIndex() { var sut1 = KeyValueUrn.Create("urn:ex:ample:123", 7); var sut2 = KeyValueUrn.Create("urn:ex:ample:123", 13); - sut1.Equals(sut2).Should().BeFalse(); + sut1.Equals(sut2).ShouldBeFalse(); } [Fact] public void ToString_ReturnsExpected() { var sut = KeyValueUrn.Create("urn:example:123", 12); - sut.ToString(null, null).Should().Be("urn:example:123"); - sut.ToString("P", null).Should().Be("example"); - sut.ToString("S", null).Should().Be("123"); - sut.ToString("V", null).Should().Be("123"); + sut.ToString(null, null).ShouldBe("urn:example:123"); + sut.ToString("P", null).ShouldBe("example"); + sut.ToString("S", null).ShouldBe("123"); + sut.ToString("V", null).ShouldBe("123"); } [Fact] @@ -127,12 +127,12 @@ public void TryFormat_ReturnsExpected() Check(sut, chars, ['P'], "example"); Check(sut, chars, ['S'], "123"); Check(sut, chars, ['V'], "123"); - sut.TryFormat([], out _, [], null).Should().BeFalse(); + sut.TryFormat([], out _, [], null).ShouldBeFalse(); static void Check(in KeyValueUrn sut, Span chard, ReadOnlySpan format, string expected) { - sut.TryFormat(chard, out var charsWritten, format, null).Should().BeTrue(); - chard[..charsWritten].ToString().Should().Be(expected); + sut.TryFormat(chard, out var charsWritten, format, null).ShouldBeTrue(); + chard[..charsWritten].ToString().ShouldBe(expected); } } @@ -142,13 +142,13 @@ public void TypeValueJsonConverter_RoundTrip() var json = """{"type":"urn:altinn:foo", "value":"1234"}"""; var obj = JsonSerializer.Deserialize(json); - obj.Value.KeySpan.ToString().Should().Be("altinn:foo"); - obj.Value.ValueSpan.ToString().Should().Be("1234"); - obj.ToString().Should().Be("urn:altinn:foo:1234"); + obj.Value.KeySpan.ToString().ShouldBe("altinn:foo"); + obj.Value.ValueSpan.ToString().ShouldBe("1234"); + obj.ToString().ShouldBe("urn:altinn:foo:1234"); var serialized = JsonSerializer.SerializeToDocument(obj); - serialized.RootElement.GetProperty("type").GetString().Should().Be("urn:altinn:foo"); - serialized.RootElement.GetProperty("value").GetString().Should().Be("1234"); + serialized.RootElement.GetProperty("type").GetString().ShouldBe("urn:altinn:foo"); + serialized.RootElement.GetProperty("value").GetString().ShouldBe("1234"); } [Fact] @@ -160,8 +160,8 @@ public void UrnJsonTypeValue_Equality() UrnJsonTypeValue obj1 = urn1; UrnJsonTypeValue obj2 = urn2; - (obj1 == obj2).Should().BeTrue(); - (obj1 != obj2).Should().BeFalse(); + (obj1 == obj2).ShouldBeTrue(); + (obj1 != obj2).ShouldBeFalse(); } [Fact] @@ -170,7 +170,7 @@ public void KeyValueUrn_IsSerializeable() var sut = KeyValueUrn.Create("urn:example:123", 12); var json = JsonSerializer.Serialize(sut); - json.Should().Be(@"""urn:example:123"""); + json.ShouldBe(@"""urn:example:123"""); } [Fact] @@ -179,7 +179,7 @@ public void KeyValueUrn_Deserialize_ShouldThrow() var json = @"""urn:example:123"""; Action act = () => JsonSerializer.Deserialize(json); - act.Should().Throw() - .Which.Message.Should().StartWith($"Deserialization of {nameof(KeyValueUrn)} is not supported."); + act.ShouldThrow() + .Message.ShouldStartWith($"Deserialization of {nameof(KeyValueUrn)} is not supported."); } }