Skip to content

Commit

Permalink
#28: Synergy.Contracts: Added text.OrFailIfWhiteSpace() method
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcinCelej committed Feb 3, 2024
1 parent 0290bc2 commit b8cad60
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@
name: string [NotNull, NotNull]
) : string [Extension, CanBeNull, AssertionMethod, ContractAnnotation]
- Fail.OrFailIfWhiteSpace(
value: string? [Nullable, AssertionCondition, NoEnumeration],
name: string [NotNull, NotNull, CallerArgumentExpression, Optional]
) : string [Extension, NotNull, AssertionMethod, ContractAnnotation]
value: string? [AssertionCondition, NoEnumeration],
name: string? [CallerArgumentExpression, Optional]
) : string [NullableContext, Extension, NotNull, AssertionMethod, ContractAnnotation]

## Requirements.Business (abstract class)
- Business.Requires(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@
name: string [NotNull, NotNull]
) : string [Extension, CanBeNull, AssertionMethod, ContractAnnotation]
- Fail.OrFailIfWhiteSpace(
value: string? [Nullable, AssertionCondition, NoEnumeration],
name: string [NotNull, NotNull]
) : string [Extension, NotNull, AssertionMethod, ContractAnnotation]
value: string? [AssertionCondition, NoEnumeration],
name: string? [CallerArgumentExpression, Optional]
) : string [NullableContext, Extension, NotNull, AssertionMethod, ContractAnnotation]

## Requirements.Business (abstract class)
- Business.Requires(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@
name: string [NotNull, NotNull]
) : string [Extension, CanBeNull, AssertionMethod, ContractAnnotation]
- Fail.OrFailIfWhiteSpace(
value: string? [Nullable, AssertionCondition, NoEnumeration],
name: string [NotNull, NotNull]
) : string [Extension, NotNull, AssertionMethod, ContractAnnotation]
value: string? [AssertionCondition, NoEnumeration],
name: string? [CallerArgumentExpression, Optional]
) : string [NullableContext, Extension, NotNull, AssertionMethod, ContractAnnotation]

## Requirements.Business (abstract class)
- Business.Requires(
Expand Down
Binary file modified Contracts/Synergy.Contracts.Test/Failures/FailStringTest.cs
Binary file not shown.
17 changes: 10 additions & 7 deletions Contracts/Synergy.Contracts/Failures/FailString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,19 @@ string argumentName
/// <param name="value">Value to check against nullability and white space.</param>
/// <param name="name">Name of the checked argument / parameter to check.</param>
/// <returns>Exactly the same value as provided to this method.</returns>
[NotNull] [return: System.Diagnostics.CodeAnalysis.NotNull]
[NotNull]
[return: System.Diagnostics.CodeAnalysis.NotNull]
[AssertionMethod]
[ContractAnnotation("value: null => halt; value: notnull => notnull")]
public static string OrFailIfWhiteSpace(
[AssertionCondition(AssertionConditionType.IS_NOT_NULL)] [NoEnumeration] this string? value,
#if NET6_0
[NotNull] [System.Diagnostics.CodeAnalysis.NotNull][System.Runtime.CompilerServices.CallerArgumentExpression("value")] string name = ""
[AssertionCondition(AssertionConditionType.IS_NOT_NULL)] [NoEnumeration]
this string? value,
#if NET6_0_OR_GREATER
[System.Runtime.CompilerServices.CallerArgumentExpression("value")] string? name = null
#else
[NotNull] [System.Diagnostics.CodeAnalysis.NotNull] string name
string name
#endif
)
)
{
Fail.RequiresArgumentName(name);

Expand All @@ -136,7 +138,8 @@ [NotNull] [System.Diagnostics.CodeAnalysis.NotNull] string name
[ContractAnnotation("value: null => halt")]
public static void IfWhitespace(
[CanBeNull, AssertionCondition(AssertionConditionType.IS_NOT_NULL)] string value,
[NotNull] [System.Diagnostics.CodeAnalysis.NotNull] string name)
[NotNull] [System.Diagnostics.CodeAnalysis.NotNull] string name
)
{
Fail.RequiresArgumentName(name);
Fail.IfWhitespace(value, Violation.WhenWhitespace(name));
Expand Down
4 changes: 2 additions & 2 deletions Web/Synergy.Web.Api.Testing/Assertions/Assertion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public abstract class Assertion : IAssertion

public IAssertion Expected(string expected)
{
ExpectedResult = expected.OrFailIfWhiteSpace(nameof(expected));
ExpectedResult = expected.OrFailIfWhiteSpace();
return this;
}

Expand All @@ -27,7 +27,7 @@ public struct Result

public Result([NotNull] string message)
{
Message = message.OrFailIfWhiteSpace(nameof(message)).Trim();
Message = message.OrFailIfWhiteSpace().Trim();
}

public static Result Ok => new Result(OkMessage);
Expand Down
2 changes: 1 addition & 1 deletion Web/Synergy.Web.Api.Testing/HttpOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ internal void Assert(IEnumerable<IAssertion> assertions)

internal void SetDescription([NotNull] string details)
{
Description = details.OrFailIfWhiteSpace(nameof(details));
Description = details.OrFailIfWhiteSpace();
}
}
}
2 changes: 1 addition & 1 deletion Web/Synergy.Web.Api.Testing/HttpOperationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static class HttpOperationExtensions
public static TOperation Details<TOperation>(this TOperation operation, string details)
where TOperation : HttpOperation
{
operation.SetDescription(details.OrFailIfWhiteSpace(nameof(details)));
operation.SetDescription(details.OrFailIfWhiteSpace());
return operation;
}

Expand Down

0 comments on commit b8cad60

Please sign in to comment.