|
1 | 1 | using System;
|
| 2 | +using System.Linq; |
2 | 3 | using FluentAssertions;
|
3 | 4 | using FluentAssertions.Execution;
|
4 | 5 | using FluentAssertions.Primitives;
|
@@ -42,6 +43,35 @@ public AndWhichConstraint<ResultAssertions, Result> BeSuccess(string because = "
|
42 | 43 | return new AndWhichConstraint<ResultAssertions, Result>(this, Subject);
|
43 | 44 | }
|
44 | 45 |
|
| 46 | + public AndWhichConstraint<ResultAssertions, Result> HaveReason(string message, string because = "", params object[] becauseArgs) |
| 47 | + { |
| 48 | + Execute.Assertion |
| 49 | + .BecauseOf(because, becauseArgs) |
| 50 | + .Given(() => Subject.Reasons) |
| 51 | + .ForCondition(reasons => reasons.Any(reason => reason.Message.Contains(message))) |
| 52 | + .FailWith("Expected result to contain reason with message containing {0}, but found reasons '{1}'", message, Subject.Reasons); |
| 53 | + |
| 54 | + return new AndWhichConstraint<ResultAssertions, Result>(this, Subject); |
| 55 | + } |
| 56 | + |
| 57 | + public AndWhichConstraint<ResultAssertions, Result> HaveReason<TReason>(string message, string because = "", params object[] becauseArgs) where TReason : IReason |
| 58 | + { |
| 59 | + Execute.Assertion |
| 60 | + .BecauseOf(because, becauseArgs) |
| 61 | + .Given(() => Subject.Reasons.OfType<TReason>()) |
| 62 | + .ForCondition(reasons => reasons.Any(reason => reason.Message.Contains(message))) |
| 63 | + .FailWith("Expected result to contain reason of type {0} with message containing {1}, but found reasons '{2}'", typeof(TReason).Name, message, Subject.Reasons); |
| 64 | + |
| 65 | + return new AndWhichConstraint<ResultAssertions, Result>(this, Subject); |
| 66 | + } |
| 67 | + |
| 68 | + public AndWhichConstraint<ResultAssertions, Result> HaveReason(IReason reason, string because = "", params object[] becauseArgs) |
| 69 | + { |
| 70 | + Subject.Reasons.Should().ContainEquivalentOf(reason, because, becauseArgs); |
| 71 | + |
| 72 | + return new AndWhichConstraint<ResultAssertions, Result>(this, Subject); |
| 73 | + } |
| 74 | + |
45 | 75 | public AndConstraint<ResultAssertions> Satisfy(Action<Result> action)
|
46 | 76 | {
|
47 | 77 | action(Subject);
|
@@ -86,6 +116,35 @@ public AndWhichConstraint<ResultAssertions<T>, Result<T>> BeSuccess(string becau
|
86 | 116 | return new AndWhichConstraint<ResultAssertions<T>, Result<T>>(this, Subject);
|
87 | 117 | }
|
88 | 118 |
|
| 119 | + public AndWhichConstraint<ResultAssertions<T>, Result<T>> HaveReason(string message, string because = "", params object[] becauseArgs) |
| 120 | + { |
| 121 | + Execute.Assertion |
| 122 | + .BecauseOf(because, becauseArgs) |
| 123 | + .Given(() => Subject.Reasons) |
| 124 | + .ForCondition(reasons => reasons.Any(reason => reason.Message.Contains(message))) |
| 125 | + .FailWith("Expected result to contain reason with message containing {0}, but found reasons '{1}'", message, Subject.Reasons); |
| 126 | + |
| 127 | + return new AndWhichConstraint<ResultAssertions<T>, Result<T>>(this, Subject); |
| 128 | + } |
| 129 | + |
| 130 | + public AndWhichConstraint<ResultAssertions<T>, Result<T>> HaveReason<TReason>(string message, string because = "", params object[] becauseArgs) where TReason : IReason |
| 131 | + { |
| 132 | + Execute.Assertion |
| 133 | + .BecauseOf(because, becauseArgs) |
| 134 | + .Given(() => Subject.Reasons.OfType<TReason>()) |
| 135 | + .ForCondition(reasons => reasons.Any(reason => reason.Message.Contains(message))) |
| 136 | + .FailWith("Expected result to contain reason of type {0} with message containing {1}, but found reasons '{2}'", typeof(TReason).Name, message, Subject.Reasons); |
| 137 | + |
| 138 | + return new AndWhichConstraint<ResultAssertions<T>, Result<T>>(this, Subject); |
| 139 | + } |
| 140 | + |
| 141 | + public AndWhichConstraint<ResultAssertions<T>, Result<T>> HaveReason(IReason reason, string because = "", params object[] becauseArgs) |
| 142 | + { |
| 143 | + Subject.Reasons.Should().ContainEquivalentOf(reason, because, becauseArgs); |
| 144 | + |
| 145 | + return new AndWhichConstraint<ResultAssertions<T>, Result<T>>(this, Subject); |
| 146 | + } |
| 147 | + |
89 | 148 | public AndConstraint<ResultAssertions<T>> HaveValue(T expectedValue, string because = "", params object[] becauseArgs)
|
90 | 149 | {
|
91 | 150 | Execute.Assertion
|
|
0 commit comments