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 827aa62..fb09467 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 @@ -119,8 +119,8 @@ ) : void [AssertionMethod, ContractAnnotation] - Fail.IfEmpty( value: DateTime, - name: string [NotNull, NotNull] - ) : void [AssertionMethod] + name: string? [CallerArgumentExpression, Optional] + ) : void [NullableContext, AssertionMethod] - Fail.IfEmpty( value: Guid, message: Violation 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 9a40594..bd8ccb1 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 @@ -119,8 +119,8 @@ ) : void [AssertionMethod, ContractAnnotation] - Fail.IfEmpty( value: DateTime, - name: string [NotNull, NotNull] - ) : void [AssertionMethod] + name: string? [CallerArgumentExpression, Optional] + ) : void [NullableContext, AssertionMethod] - Fail.IfEmpty( value: Guid, message: Violation 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 9a40594..bd8ccb1 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 @@ -119,8 +119,8 @@ ) : void [AssertionMethod, ContractAnnotation] - Fail.IfEmpty( value: DateTime, - name: string [NotNull, NotNull] - ) : void [AssertionMethod] + name: string? [CallerArgumentExpression, Optional] + ) : void [NullableContext, AssertionMethod] - Fail.IfEmpty( value: Guid, message: Violation diff --git a/Contracts/Synergy.Contracts.Test/Failures/FailDateTimeTest.cs b/Contracts/Synergy.Contracts.Test/Failures/FailDateTimeTest.cs index 8208c3c..0331f54 100644 --- a/Contracts/Synergy.Contracts.Test/Failures/FailDateTimeTest.cs +++ b/Contracts/Synergy.Contracts.Test/Failures/FailDateTimeTest.cs @@ -210,11 +210,27 @@ public void IfDateEmpty() Assert.That(exception.Message, Is.EqualTo("'minDate' is empty = 01/01/0001 00:00:00")); } + [Test] + public void IfDateEmptyCallerArgumentExpression() + { + // ARRANGE + DateTime minDate = DateTime.MinValue; + + // ACT + var exception = Assert.Throws( + () => Fail.IfEmpty(minDate) + ); + + // ASSERT + Assert.That(exception.Message, Is.EqualTo("'minDate' is empty = 01/01/0001 00:00:00")); + } + [Test] public void IfDateEmptySuccess() { // ACT Fail.IfEmpty(DateTime.Today, nameof(DateTime.Today)); + Fail.IfEmpty(DateTime.Today); } #endregion diff --git a/Contracts/Synergy.Contracts/Failures/FailDateTime.cs b/Contracts/Synergy.Contracts/Failures/FailDateTime.cs index 14f0c7a..c6d9fde 100644 --- a/Contracts/Synergy.Contracts/Failures/FailDateTime.cs +++ b/Contracts/Synergy.Contracts/Failures/FailDateTime.cs @@ -140,7 +140,15 @@ string name /// DateTime to check /// Name of the checked argument / parameter. [AssertionMethod] - public static void IfEmpty(DateTime value, [NotNull] [System.Diagnostics.CodeAnalysis.NotNull] string name) + public static void IfEmpty( + DateTime value, +#if NET6_0_OR_GREATER + [System.Runtime.CompilerServices.CallerArgumentExpression("value")] + string? name = null +#else + string name +#endif + ) { if (value == DateTime.MinValue) throw Fail.Because(Violation.WhenDateTimeIsEmpty(name, value));