Skip to content

Commit 4aa5233

Browse files
committed
Add .Passing() tests for LocalRedirectTestBuilder
1 parent bc4f9db commit 4aa5233

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/LocalRedirectTests/LocalRedirectTestBuilderTests.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 LocalRedirectTestBuilderTests
@@ -251,5 +252,58 @@ public void AndAlsoShouldWorkCorrectly()
251252
.AndAlso()
252253
.ToUrl("/local/test"));
253254
}
255+
256+
257+
[Fact]
258+
public void PassingShouldCorrectlyRunItsAssertionFunction()
259+
{
260+
MyController<MvcController>
261+
.Instance()
262+
.Calling(c => c.LocalRedirectAction())
263+
.ShouldReturn()
264+
.LocalRedirect(localRedirect => localRedirect
265+
.Passing(lr => lr.Url == "/local/test"));
266+
}
267+
268+
[Fact]
269+
public void PassingShouldThrowAnExceptionOnAnIncorrectAssertion()
270+
{
271+
Test.AssertException<InvocationResultAssertionException>(
272+
() =>
273+
{
274+
MyController<MvcController>
275+
.Instance()
276+
.Calling(c => c.LocalRedirectAction())
277+
.ShouldReturn()
278+
.LocalRedirect(localRedirect => localRedirect
279+
.Passing(lr => lr.Url == string.Empty));
280+
},
281+
$"When calling {nameof(MvcController.LocalRedirectAction)} " +
282+
$"action in {nameof(MvcController)} expected the LocalRedirectResult to pass the given predicate, but it failed.");
283+
}
284+
285+
[Fact]
286+
public void PassingShouldCorrectlyRunItsAssertionAction()
287+
{
288+
MyController<MvcController>
289+
.Instance()
290+
.Calling(c => c.LocalRedirectAction())
291+
.ShouldReturn()
292+
.LocalRedirect(localRedirect => localRedirect
293+
.Passing(lr =>
294+
{
295+
const string expectedRedirect = "/local/test";
296+
var actualRedirect = lr.Url;
297+
if (expectedRedirect != actualRedirect)
298+
{
299+
throw new InvalidAssertionException(
300+
string.Format("Expected {0} to have {1} equal to {2}, but it was {3}.",
301+
lr.GetType().ToFriendlyTypeName(),
302+
nameof(lr.Url),
303+
expectedRedirect,
304+
actualRedirect));
305+
};
306+
}));
307+
}
254308
}
255309
}

0 commit comments

Comments
 (0)