| | | 1 | | //======================================================================= |
| | | 2 | | // FixedStructAssertions.cs |
| | | 3 | | //======================================================================= |
| | | 4 | | // MIT License, Copyright (c) 2024-present David Oravsky (mrdav30) |
| | | 5 | | // See LICENSE file in the project root for full license information. |
| | | 6 | | //======================================================================= |
| | | 7 | | |
| | | 8 | | using FluentAssertions; |
| | | 9 | | using FluentAssertions.Execution; |
| | | 10 | | using FluentAssertions.Numeric; |
| | | 11 | | |
| | | 12 | | namespace FixedMathSharp.Assertions; |
| | | 13 | | |
| | | 14 | | public abstract class FixedStructAssertions<TSubject, TAssertions> |
| | | 15 | | where TAssertions : FixedStructAssertions<TSubject, TAssertions> |
| | | 16 | | { |
| | 79 | 17 | | protected FixedStructAssertions(TSubject value) |
| | | 18 | | { |
| | 79 | 19 | | Subject = value; |
| | 79 | 20 | | CurrentAssertionChain = AssertionChain.GetOrCreate(); |
| | 79 | 21 | | } |
| | | 22 | | |
| | | 23 | | protected TSubject Subject { get; } |
| | | 24 | | |
| | | 25 | | protected AssertionChain CurrentAssertionChain { get; } |
| | | 26 | | |
| | | 27 | | protected abstract string Identifier { get; } |
| | | 28 | | |
| | | 29 | | public AndConstraint<TAssertions> Be(TSubject expected, string because = "", params object[] becauseArgs) |
| | | 30 | | { |
| | 8 | 31 | | CurrentAssertionChain |
| | 8 | 32 | | .ForCondition(Equals(Subject, expected)) |
| | 8 | 33 | | .BecauseOf(because, becauseArgs) |
| | 8 | 34 | | .FailWith("Expected " + Identifier + " to equal {0}{reason}, but found {1}.", expected, Subject); |
| | | 35 | | |
| | 4 | 36 | | return new AndConstraint<TAssertions>((TAssertions)this); |
| | | 37 | | } |
| | | 38 | | |
| | | 39 | | public AndConstraint<TAssertions> NotBe(TSubject unexpected, string because = "", params object[] becauseArgs) |
| | | 40 | | { |
| | 6 | 41 | | CurrentAssertionChain |
| | 6 | 42 | | .ForCondition(!Equals(Subject, unexpected)) |
| | 6 | 43 | | .BecauseOf(because, becauseArgs) |
| | 6 | 44 | | .FailWith("Expected " + Identifier + " not to equal {0}{reason}, but found {1}.", unexpected, Subject); |
| | | 45 | | |
| | 3 | 46 | | return new AndConstraint<TAssertions>((TAssertions)this); |
| | | 47 | | } |
| | | 48 | | } |