Skip to content

Commit

Permalink
#28: Synergy.Contracts: Added sth.AsOrFail<string>() method
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcinCelej committed Feb 3, 2024
1 parent e4de427 commit da2fd39
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Technical Debt for Synergy.Contracts

Total: 15
Total: 14

## [BusinessDocumentation.cs](../../Requirements/BusinessDocumentation.cs)
- TODO: Marcin Celej [from: Marcin Celej on: 08-04-2023]: check that and probably convert docs int tt
Expand All @@ -14,7 +14,6 @@ Total: 15
- TODO:mace (from:mace @ 22-10-2016): variable.FailIfTrue(message)

## [FailCast.cs](../../../Synergy.Contracts/Failures/FailCast.cs)
- TODO:mace (from:mace @ 22-10-2016): Add [AssertionCondition] below
- TODO:mace (from:mace @ 22-10-2016): public static void Fail.IfArgumentNotCastable<T>([CanBeNull, AssertionCondition(conditionType: AssertionConditionType.IS_NOT_NULL)] string argumentValue)

## [FailCollection.cs](../../../Synergy.Contracts/Failures/FailCollection.cs)
Expand Down
2 changes: 1 addition & 1 deletion Contracts/Synergy.Contracts.Test/Failures/FailCastTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void AsOrFail()
);

// ASSERT
Assert.That(exception.Message, Is.EqualTo("Expected object of type 'System.String' but was 'System.Object'"));
Assert.That(exception.Message, Is.EqualTo("Expected someObjectButSurelyNotString of type 'System.String' but was 'System.Object'"));
}

[Test]
Expand Down
2 changes: 0 additions & 2 deletions Contracts/Synergy.Contracts/Failures/FailBoolean.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ static partial class Fail

#region Fail.IfFalse


/// <summary>
/// Throws exception when checked value is <see langword="false" />.
/// </summary>
Expand All @@ -30,7 +29,6 @@ public static void IfFalse(

#region Fail.IfTrue


/// <summary>
/// Throws exception when checked value is <see langword="true" />.
/// </summary>
Expand Down
10 changes: 8 additions & 2 deletions Contracts/Synergy.Contracts/Failures/FailCast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace Synergy.Contracts
{
// TODO:mace (from:mace @ 22-10-2016): Add [AssertionCondition] below
static partial class Fail
{
// TODO:mace (from:mace @ 22-10-2016): public static void Fail.IfArgumentNotCastable<T>([CanBeNull, AssertionCondition(conditionType: AssertionConditionType.IS_NOT_NULL)] string argumentValue)
Expand All @@ -19,7 +18,14 @@ static partial class Fail
[CanBeNull]
[AssertionMethod]
[ContractAnnotation("value: null => null; value: notnull => notnull")]
public static T AsOrFail<T>([CanBeNull] [NoEnumeration] this object value, [CanBeNull] string name = null)
public static T AsOrFail<T>(
[CanBeNull] [NoEnumeration] this object value,
#if NET6_0_OR_GREATER
[System.Runtime.CompilerServices.CallerArgumentExpression("value")] string? name = null
#else
string name
#endif
)
{
Fail.IfNotCastable<T>(value, Violation.WhenCannotCast<T>(name ?? "object", value));

Expand Down

0 comments on commit da2fd39

Please sign in to comment.