|
4 | 4 | using Exceptions;
|
5 | 5 | using Setups;
|
6 | 6 | using Setups.Controllers;
|
| 7 | + using Utilities; |
7 | 8 | using Xunit;
|
8 | 9 |
|
9 | 10 | public class ForbidTestBuilderTests
|
@@ -136,5 +137,57 @@ public void AndAlsoShouldWorkCorrectly()
|
136 | 137 | .AndAlso()
|
137 | 138 | .ContainingAuthenticationScheme(AuthenticationScheme.NTLM));
|
138 | 139 | }
|
| 140 | + |
| 141 | + [Fact] |
| 142 | + public void PassingShouldCorrectlyRunItsAssertionFunction() |
| 143 | + { |
| 144 | + MyController<MvcController> |
| 145 | + .Instance() |
| 146 | + .Calling(c => c.ForbidWithAuthenticationSchemes()) |
| 147 | + .ShouldReturn() |
| 148 | + .Forbid(forbid => forbid |
| 149 | + .Passing(f => f.AuthenticationSchemes?.Count == 2)); |
| 150 | + } |
| 151 | + |
| 152 | + [Fact] |
| 153 | + public void PassingShouldThrowAnExceptionOnAnIncorrectAssertion() |
| 154 | + { |
| 155 | + Test.AssertException<InvocationResultAssertionException>( |
| 156 | + () => |
| 157 | + { |
| 158 | + MyController<MvcController> |
| 159 | + .Instance() |
| 160 | + .Calling(c => c.ForbidWithAuthenticationSchemes()) |
| 161 | + .ShouldReturn() |
| 162 | + .Forbid(forbid => forbid |
| 163 | + .Passing(f => f.AuthenticationSchemes?.Count == 0)); |
| 164 | + }, |
| 165 | + $"When calling {nameof(MvcController.ForbidWithAuthenticationSchemes)} " + |
| 166 | + $"action in {nameof(MvcController)} expected the ForbidResult to pass the given predicate, but it failed."); |
| 167 | + } |
| 168 | + |
| 169 | + [Fact] |
| 170 | + public void PassingShouldCorrectlyRunItsAssertionAction() |
| 171 | + { |
| 172 | + MyController<MvcController> |
| 173 | + .Instance() |
| 174 | + .Calling(c => c.ForbidWithAuthenticationSchemes()) |
| 175 | + .ShouldReturn() |
| 176 | + .Forbid(forbid => forbid |
| 177 | + .Passing(f => |
| 178 | + { |
| 179 | + const int expectedAuthSchemesCount = 2; |
| 180 | + var actualAuthSchemesCount = f.AuthenticationSchemes?.Count; |
| 181 | + if (actualAuthSchemesCount != expectedAuthSchemesCount) |
| 182 | + { |
| 183 | + throw new InvalidAssertionException( |
| 184 | + string.Format("Expected {0} to have {1} {2}, but it was {3}.", |
| 185 | + f.GetType().ToFriendlyTypeName(), |
| 186 | + expectedAuthSchemesCount, |
| 187 | + nameof(f.AuthenticationSchemes), |
| 188 | + actualAuthSchemesCount)); |
| 189 | + }; |
| 190 | + })); |
| 191 | + } |
139 | 192 | }
|
140 | 193 | }
|
0 commit comments