|
5 | 5 | using Microsoft.Net.Http.Headers;
|
6 | 6 | using Setups;
|
7 | 7 | using Setups.Controllers;
|
| 8 | + using Utilities; |
8 | 9 | using Xunit;
|
9 | 10 |
|
10 | 11 | public class ContentTestBuilderTests
|
@@ -156,5 +157,59 @@ public void AndAlsoShouldWorkCorrectly()
|
156 | 157 | .AndAlso()
|
157 | 158 | .WithContentType(ContentType.ApplicationJson));
|
158 | 159 | }
|
| 160 | + |
| 161 | + |
| 162 | + [Fact] |
| 163 | + public void PassingShouldCorrectlyRunItsAssertionFunction() |
| 164 | + { |
| 165 | + MyController<MvcController> |
| 166 | + .Instance() |
| 167 | + .Calling(c => c.ContentAction()) |
| 168 | + .ShouldReturn() |
| 169 | + .Content(content => content |
| 170 | + .Passing(c => c.Content == "content")); |
| 171 | + } |
| 172 | + |
| 173 | + [Fact] |
| 174 | + public void PassingShouldThrowAnExceptionOnAnIncorrectAssertion() |
| 175 | + { |
| 176 | + Test.AssertException<InvocationResultAssertionException>( |
| 177 | + () => |
| 178 | + { |
| 179 | + MyController<MvcController> |
| 180 | + .Instance() |
| 181 | + .Calling(c => c.ContentAction()) |
| 182 | + .ShouldReturn() |
| 183 | + .Content(content => content |
| 184 | + .Passing(c => c.Content == string.Empty)); |
| 185 | + }, |
| 186 | + $"When calling {nameof(MvcController.ContentAction)} " + |
| 187 | + $"action in {nameof(MvcController)} expected the ContentResult to pass the given predicate, but it failed."); |
| 188 | + } |
| 189 | + |
| 190 | + [Fact] |
| 191 | + public void PassingShouldCorrectlyRunItsAssertionAction() |
| 192 | + { |
| 193 | + MyController<MvcController> |
| 194 | + .Instance() |
| 195 | + .Calling(c => c.ContentAction()) |
| 196 | + .ShouldReturn() |
| 197 | + .Content(content => content |
| 198 | + .Passing(c => |
| 199 | + { |
| 200 | + const string expectedContentBody = "content"; |
| 201 | + var actualContentBody = c.Content; |
| 202 | + if (actualContentBody != expectedContentBody) |
| 203 | + { |
| 204 | + throw new InvalidAssertionException( |
| 205 | + string.Format("Expected {0} to have {1} equal to content, but it was {2}.", |
| 206 | + c.GetType().ToFriendlyTypeName(), |
| 207 | + nameof(c.Content), |
| 208 | + actualContentBody)); |
| 209 | + }; |
| 210 | + })); |
| 211 | + } |
| 212 | + |
| 213 | + |
159 | 214 | }
|
160 | 215 | }
|
0 commit comments