Skip to content

Commit 11c1eb1

Browse files
committed
Add .Passing() tests for NotFoundTestBuilder
1 parent 4aa5233 commit 11c1eb1

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

test/MyTested.AspNetCore.Mvc.Controllers.ActionResults.Test/BuildersTests/ActionResultsTests/NotFoundTests/NotFoundTestBuilderTests.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Setups;
99
using Setups.Common;
1010
using Setups.Controllers;
11+
using Utilities;
1112
using Xunit;
1213

1314
public class NotFoundTestBuilderTests
@@ -426,5 +427,58 @@ public void AndAlsoShouldWorkCorrectly()
426427
TestObjectFactory.GetOutputFormatter(),
427428
new CustomOutputFormatter()));
428429
}
430+
431+
432+
[Fact]
433+
public void PassingShouldCorrectlyRunItsAssertionFunction()
434+
{
435+
MyController<MvcController>
436+
.Instance()
437+
.Calling(c => c.FullHttpNotFoundAction())
438+
.ShouldReturn()
439+
.NotFound(notFound => notFound
440+
.Passing(nf => nf.Formatters?.Count == 2));
441+
}
442+
443+
[Fact]
444+
public void PassingShouldThrowAnExceptionOnAnIncorrectAssertion()
445+
{
446+
Test.AssertException<InvocationResultAssertionException>(
447+
() =>
448+
{
449+
MyController<MvcController>
450+
.Instance()
451+
.Calling(c => c.FullHttpNotFoundAction())
452+
.ShouldReturn()
453+
.NotFound(notFound => notFound
454+
.Passing(nf => nf.Formatters?.Count == 0));
455+
},
456+
$"When calling {nameof(MvcController.FullHttpNotFoundAction)} " +
457+
$"action in {nameof(MvcController)} expected the NotFoundObjectResult to pass the given predicate, but it failed.");
458+
}
459+
460+
[Fact]
461+
public void PassingShouldCorrectlyRunItsAssertionAction()
462+
{
463+
MyController<MvcController>
464+
.Instance()
465+
.Calling(c => c.FullHttpNotFoundAction())
466+
.ShouldReturn()
467+
.NotFound(notFound => notFound
468+
.Passing(nf =>
469+
{
470+
const int actualFormattersCount = 2;
471+
var expectedFormattersCount = nf.Formatters?.Count;
472+
if (expectedFormattersCount != actualFormattersCount)
473+
{
474+
throw new InvalidAssertionException(
475+
string.Format("Expected {0} to have {1} {2}, but it has {3}.",
476+
nf.GetType().ToFriendlyTypeName(),
477+
actualFormattersCount,
478+
nameof(nf.Formatters),
479+
expectedFormattersCount));
480+
};
481+
}));
482+
}
429483
}
430484
}

0 commit comments

Comments
 (0)