Skip to content

Commit bc4f9db

Browse files
committed
Add .Passing() tests for ForbidTestBuilder
1 parent a6288d9 commit bc4f9db

File tree

1 file changed

+53
-0
lines changed
  • test/MyTested.AspNetCore.Mvc.Controllers.ActionResults.Test/BuildersTests/ActionResultsTests/ForbidTests

1 file changed

+53
-0
lines changed

test/MyTested.AspNetCore.Mvc.Controllers.ActionResults.Test/BuildersTests/ActionResultsTests/ForbidTests/ForbidTestBuilderTests.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Exceptions;
55
using Setups;
66
using Setups.Controllers;
7+
using Utilities;
78
using Xunit;
89

910
public class ForbidTestBuilderTests
@@ -136,5 +137,57 @@ public void AndAlsoShouldWorkCorrectly()
136137
.AndAlso()
137138
.ContainingAuthenticationScheme(AuthenticationScheme.NTLM));
138139
}
140+
141+
[Fact]
142+
public void PassingShouldCorrectlyRunItsAssertionFunction()
143+
{
144+
MyController<MvcController>
145+
.Instance()
146+
.Calling(c => c.ForbidWithAuthenticationSchemes())
147+
.ShouldReturn()
148+
.Forbid(forbid => forbid
149+
.Passing(f => f.AuthenticationSchemes?.Count == 2));
150+
}
151+
152+
[Fact]
153+
public void PassingShouldThrowAnExceptionOnAnIncorrectAssertion()
154+
{
155+
Test.AssertException<InvocationResultAssertionException>(
156+
() =>
157+
{
158+
MyController<MvcController>
159+
.Instance()
160+
.Calling(c => c.ForbidWithAuthenticationSchemes())
161+
.ShouldReturn()
162+
.Forbid(forbid => forbid
163+
.Passing(f => f.AuthenticationSchemes?.Count == 0));
164+
},
165+
$"When calling {nameof(MvcController.ForbidWithAuthenticationSchemes)} " +
166+
$"action in {nameof(MvcController)} expected the ForbidResult to pass the given predicate, but it failed.");
167+
}
168+
169+
[Fact]
170+
public void PassingShouldCorrectlyRunItsAssertionAction()
171+
{
172+
MyController<MvcController>
173+
.Instance()
174+
.Calling(c => c.ForbidWithAuthenticationSchemes())
175+
.ShouldReturn()
176+
.Forbid(forbid => forbid
177+
.Passing(f =>
178+
{
179+
const int expectedAuthSchemesCount = 2;
180+
var actualAuthSchemesCount = f.AuthenticationSchemes?.Count;
181+
if (actualAuthSchemesCount != expectedAuthSchemesCount)
182+
{
183+
throw new InvalidAssertionException(
184+
string.Format("Expected {0} to have {1} {2}, but it was {3}.",
185+
f.GetType().ToFriendlyTypeName(),
186+
expectedAuthSchemesCount,
187+
nameof(f.AuthenticationSchemes),
188+
actualAuthSchemesCount));
189+
};
190+
}));
191+
}
139192
}
140193
}

0 commit comments

Comments
 (0)