|
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 FileTestBuilderTests
|
@@ -199,5 +200,58 @@ public void AndAlsoShouldWorkCorrectly()
|
199 | 200 | .AndAlso()
|
200 | 201 | .WithContentType(ContentType.ApplicationJson));
|
201 | 202 | }
|
| 203 | + |
| 204 | + |
| 205 | + [Fact] |
| 206 | + public void PassingShouldCorrectlyRunItsAssertionFunction() |
| 207 | + { |
| 208 | + MyController<MvcController> |
| 209 | + .Instance() |
| 210 | + .Calling(c => c.FileWithVirtualPath()) |
| 211 | + .ShouldReturn() |
| 212 | + .File(file => file |
| 213 | + .Passing(f => f.FileName == "/Test")); |
| 214 | + } |
| 215 | + |
| 216 | + [Fact] |
| 217 | + public void PassingShouldThrowAnExceptionOnAnIncorrectAssertion() |
| 218 | + { |
| 219 | + Test.AssertException<InvocationResultAssertionException>( |
| 220 | + () => |
| 221 | + { |
| 222 | + MyController<MvcController> |
| 223 | + .Instance() |
| 224 | + .Calling(c => c.FileWithVirtualPath()) |
| 225 | + .ShouldReturn() |
| 226 | + .File(file => file |
| 227 | + .Passing(f => f.FileName == string.Empty)); |
| 228 | + }, |
| 229 | + $"When calling {nameof(MvcController.FileWithVirtualPath)} " + |
| 230 | + $"action in {nameof(MvcController)} expected the VirtualFileResult to pass the given predicate, but it failed."); |
| 231 | + } |
| 232 | + |
| 233 | + [Fact] |
| 234 | + public void PassingShouldCorrectlyRunItsAssertionAction() |
| 235 | + { |
| 236 | + MyController<MvcController> |
| 237 | + .Instance() |
| 238 | + .Calling(c => c.FileWithVirtualPath()) |
| 239 | + .ShouldReturn() |
| 240 | + .File(file => file |
| 241 | + .Passing(f => |
| 242 | + { |
| 243 | + const string expectedFileName = "/Test"; |
| 244 | + var actualFileName = f.FileName; |
| 245 | + if (actualFileName != expectedFileName) |
| 246 | + { |
| 247 | + throw new InvalidAssertionException( |
| 248 | + string.Format("Expected {0} to have {1} equal to {2}, but it was {3}.", |
| 249 | + f.GetType().ToFriendlyTypeName(), |
| 250 | + nameof(f.FileName), |
| 251 | + expectedFileName, |
| 252 | + actualFileName)); |
| 253 | + }; |
| 254 | + })); |
| 255 | + } |
202 | 256 | }
|
203 | 257 | }
|
0 commit comments