From 9e7380eee358b2721b30fea87ca146d909f21b64 Mon Sep 17 00:00:00 2001 From: Marcin Celej Date: Sat, 3 Feb 2024 17:57:17 +0100 Subject: [PATCH] #28: Synergy.Contracts: Added Fail.IfWhitespace(text) method --- ...of.Synergy.Contracts.DotNet6_0.verified.md | 2 +- ...of.Synergy.Contracts.DotNet7_0.verified.md | 2 +- ...of.Synergy.Contracts.DotNet8_0.verified.md | 2 +- .../Failures/FailStringTest.cs | Bin 15720 -> 16068 bytes .../Synergy.Contracts/Failures/FailString.cs | 12 +++++++++--- Web/Synergy.Web.Api.Testing/TestServer.cs | 2 +- 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Contracts/Synergy.Contracts.Test/Architecture/Public/Api.of.Synergy.Contracts.DotNet6_0.verified.md b/Contracts/Synergy.Contracts.Test/Architecture/Public/Api.of.Synergy.Contracts.DotNet6_0.verified.md index ff41e1f..0172b4f 100644 --- a/Contracts/Synergy.Contracts.Test/Architecture/Public/Api.of.Synergy.Contracts.DotNet6_0.verified.md +++ b/Contracts/Synergy.Contracts.Test/Architecture/Public/Api.of.Synergy.Contracts.DotNet6_0.verified.md @@ -223,7 +223,7 @@ ) : void [AssertionMethod, ContractAnnotation] - Fail.IfWhitespace( value: string [CanBeNull, AssertionCondition], - name: string [NotNull, NotNull] + name: string? [Nullable, CallerArgumentExpression, Optional] ) : void [AssertionMethod, ContractAnnotation] - Fail.NotNull( value: T? [CanBeNull, AssertionCondition, NoEnumeration], diff --git a/Contracts/Synergy.Contracts.Test/Architecture/Public/Api.of.Synergy.Contracts.DotNet7_0.verified.md b/Contracts/Synergy.Contracts.Test/Architecture/Public/Api.of.Synergy.Contracts.DotNet7_0.verified.md index ff41e1f..0172b4f 100644 --- a/Contracts/Synergy.Contracts.Test/Architecture/Public/Api.of.Synergy.Contracts.DotNet7_0.verified.md +++ b/Contracts/Synergy.Contracts.Test/Architecture/Public/Api.of.Synergy.Contracts.DotNet7_0.verified.md @@ -223,7 +223,7 @@ ) : void [AssertionMethod, ContractAnnotation] - Fail.IfWhitespace( value: string [CanBeNull, AssertionCondition], - name: string [NotNull, NotNull] + name: string? [Nullable, CallerArgumentExpression, Optional] ) : void [AssertionMethod, ContractAnnotation] - Fail.NotNull( value: T? [CanBeNull, AssertionCondition, NoEnumeration], diff --git a/Contracts/Synergy.Contracts.Test/Architecture/Public/Api.of.Synergy.Contracts.DotNet8_0.verified.md b/Contracts/Synergy.Contracts.Test/Architecture/Public/Api.of.Synergy.Contracts.DotNet8_0.verified.md index ff41e1f..0172b4f 100644 --- a/Contracts/Synergy.Contracts.Test/Architecture/Public/Api.of.Synergy.Contracts.DotNet8_0.verified.md +++ b/Contracts/Synergy.Contracts.Test/Architecture/Public/Api.of.Synergy.Contracts.DotNet8_0.verified.md @@ -223,7 +223,7 @@ ) : void [AssertionMethod, ContractAnnotation] - Fail.IfWhitespace( value: string [CanBeNull, AssertionCondition], - name: string [NotNull, NotNull] + name: string? [Nullable, CallerArgumentExpression, Optional] ) : void [AssertionMethod, ContractAnnotation] - Fail.NotNull( value: T? [CanBeNull, AssertionCondition, NoEnumeration], diff --git a/Contracts/Synergy.Contracts.Test/Failures/FailStringTest.cs b/Contracts/Synergy.Contracts.Test/Failures/FailStringTest.cs index 8de21a3927416a15d76ce20612a12176e203e9d0..dc324612217b01ca819221e127eb61238b479ea9 100644 GIT binary patch delta 53 zcmaD+b)UYTREy!r_+zg{|TvZr#|W?9YUq5yy|5hVZs diff --git a/Contracts/Synergy.Contracts/Failures/FailString.cs b/Contracts/Synergy.Contracts/Failures/FailString.cs index 927c3eb..ea2bafe 100644 --- a/Contracts/Synergy.Contracts/Failures/FailString.cs +++ b/Contracts/Synergy.Contracts/Failures/FailString.cs @@ -137,9 +137,15 @@ string name [AssertionMethod] [ContractAnnotation("value: null => halt")] public static void IfWhitespace( - [CanBeNull, AssertionCondition(AssertionConditionType.IS_NOT_NULL)] string value, - [NotNull] [System.Diagnostics.CodeAnalysis.NotNull] string name - ) + [CanBeNull, AssertionCondition(AssertionConditionType.IS_NOT_NULL)] + string value, +#if NET6_0_OR_GREATER + [System.Runtime.CompilerServices.CallerArgumentExpression("value")] + string? name = null +#else + string name +#endif + ) { Fail.RequiresArgumentName(name); Fail.IfWhitespace(value, Violation.WhenWhitespace(name)); diff --git a/Web/Synergy.Web.Api.Testing/TestServer.cs b/Web/Synergy.Web.Api.Testing/TestServer.cs index 46512b2..efd0f67 100644 --- a/Web/Synergy.Web.Api.Testing/TestServer.cs +++ b/Web/Synergy.Web.Api.Testing/TestServer.cs @@ -117,7 +117,7 @@ protected virtual HttpRequestMessage CreateHttpRequest( private Uri PrepareRequestUri(string path, object? parameterToGet = null) { - Fail.IfWhitespace(path, nameof(path)); + Fail.IfWhitespace(path); var uriBuilder = new UriBuilder {