Skip to content

Commit 7220c68

Browse files
committed
Add .Passing() tests for ContentTestBuilder
1 parent 0a7bab0 commit 7220c68

File tree

1 file changed

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

1 file changed

+55
-0
lines changed

test/MyTested.AspNetCore.Mvc.Controllers.ActionResults.Test/BuildersTests/ActionResultsTests/ContentTests/ContentTestBuilderTests.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.Net.Http.Headers;
66
using Setups;
77
using Setups.Controllers;
8+
using Utilities;
89
using Xunit;
910

1011
public class ContentTestBuilderTests
@@ -156,5 +157,59 @@ public void AndAlsoShouldWorkCorrectly()
156157
.AndAlso()
157158
.WithContentType(ContentType.ApplicationJson));
158159
}
160+
161+
162+
[Fact]
163+
public void PassingShouldCorrectlyRunItsAssertionFunction()
164+
{
165+
MyController<MvcController>
166+
.Instance()
167+
.Calling(c => c.ContentAction())
168+
.ShouldReturn()
169+
.Content(content => content
170+
.Passing(c => c.Content == "content"));
171+
}
172+
173+
[Fact]
174+
public void PassingShouldThrowAnExceptionOnAnIncorrectAssertion()
175+
{
176+
Test.AssertException<InvocationResultAssertionException>(
177+
() =>
178+
{
179+
MyController<MvcController>
180+
.Instance()
181+
.Calling(c => c.ContentAction())
182+
.ShouldReturn()
183+
.Content(content => content
184+
.Passing(c => c.Content == string.Empty));
185+
},
186+
$"When calling {nameof(MvcController.ContentAction)} " +
187+
$"action in {nameof(MvcController)} expected the ContentResult to pass the given predicate, but it failed.");
188+
}
189+
190+
[Fact]
191+
public void PassingShouldCorrectlyRunItsAssertionAction()
192+
{
193+
MyController<MvcController>
194+
.Instance()
195+
.Calling(c => c.ContentAction())
196+
.ShouldReturn()
197+
.Content(content => content
198+
.Passing(c =>
199+
{
200+
const string expectedContentBody = "content";
201+
var actualContentBody = c.Content;
202+
if (actualContentBody != expectedContentBody)
203+
{
204+
throw new InvalidAssertionException(
205+
string.Format("Expected {0} to have {1} equal to content, but it was {2}.",
206+
c.GetType().ToFriendlyTypeName(),
207+
nameof(c.Content),
208+
actualContentBody));
209+
};
210+
}));
211+
}
212+
213+
159214
}
160215
}

0 commit comments

Comments
 (0)