Skip to content

Commit 2d260e1

Browse files
committed
Add .Passing() tests for RedirectTestBuilder
1 parent ce7624f commit 2d260e1

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/RedirectTests/RedirectTestBuilderTests.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Setups;
77
using Setups.Common;
88
using Setups.Controllers;
9+
using Utilities;
910
using Xunit;
1011

1112
public class RedirectTestBuilderTests
@@ -541,5 +542,58 @@ public void AndAlsoShouldWorkCorrectly()
541542
.AndAlso()
542543
.ToController("MyController"));
543544
}
545+
546+
547+
[Fact]
548+
public void PassingShouldCorrectlyRunItsAssertionFunction()
549+
{
550+
MyController<MvcController>
551+
.Instance()
552+
.Calling(c => c.RedirectToActionResult())
553+
.ShouldReturn()
554+
.Redirect(redirect => redirect
555+
.Passing(r => r.ActionName == "MyAction"));
556+
}
557+
558+
[Fact]
559+
public void PassingShouldThrowAnExceptionOnAnIncorrectAssertion()
560+
{
561+
Test.AssertException<InvocationResultAssertionException>(
562+
() =>
563+
{
564+
MyController<MvcController>
565+
.Instance()
566+
.Calling(c => c.RedirectToActionResult())
567+
.ShouldReturn()
568+
.Redirect(redirect => redirect
569+
.Passing(r => r.ActionName == string.Empty));
570+
},
571+
$"When calling {nameof(MvcController.RedirectToActionResult)} " +
572+
$"action in {nameof(MvcController)} expected the RedirectToActionResult to pass the given predicate, but it failed.");
573+
}
574+
575+
[Fact]
576+
public void PassingShouldCorrectlyRunItsAssertionAction()
577+
{
578+
MyController<MvcController>
579+
.Instance()
580+
.Calling(c => c.RedirectToActionResult())
581+
.ShouldReturn()
582+
.Redirect(redirect => redirect
583+
.Passing(r =>
584+
{
585+
const string expectedActionName = "MyAction";
586+
var actualActionName = r.ActionName;
587+
if (actualActionName != expectedActionName)
588+
{
589+
throw new InvalidAssertionException(
590+
string.Format("Expected {0} to have {1} equal to {2}, but it was {3}.",
591+
r.GetType().ToFriendlyTypeName(),
592+
nameof(r.ActionName),
593+
expectedActionName,
594+
actualActionName));
595+
};
596+
}));
597+
}
544598
}
545599
}

0 commit comments

Comments
 (0)