Skip to content

Commit a6288d9

Browse files
committed
Add .Passing() tests for FileTestBuilder
1 parent 7220c68 commit a6288d9

File tree

1 file changed

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

1 file changed

+54
-0
lines changed

test/MyTested.AspNetCore.Mvc.Controllers.ActionResults.Test/BuildersTests/ActionResultsTests/FileTests/FileTestBuilderTests.cs

Lines changed: 54 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 FileTestBuilderTests
@@ -199,5 +200,58 @@ public void AndAlsoShouldWorkCorrectly()
199200
.AndAlso()
200201
.WithContentType(ContentType.ApplicationJson));
201202
}
203+
204+
205+
[Fact]
206+
public void PassingShouldCorrectlyRunItsAssertionFunction()
207+
{
208+
MyController<MvcController>
209+
.Instance()
210+
.Calling(c => c.FileWithVirtualPath())
211+
.ShouldReturn()
212+
.File(file => file
213+
.Passing(f => f.FileName == "/Test"));
214+
}
215+
216+
[Fact]
217+
public void PassingShouldThrowAnExceptionOnAnIncorrectAssertion()
218+
{
219+
Test.AssertException<InvocationResultAssertionException>(
220+
() =>
221+
{
222+
MyController<MvcController>
223+
.Instance()
224+
.Calling(c => c.FileWithVirtualPath())
225+
.ShouldReturn()
226+
.File(file => file
227+
.Passing(f => f.FileName == string.Empty));
228+
},
229+
$"When calling {nameof(MvcController.FileWithVirtualPath)} " +
230+
$"action in {nameof(MvcController)} expected the VirtualFileResult to pass the given predicate, but it failed.");
231+
}
232+
233+
[Fact]
234+
public void PassingShouldCorrectlyRunItsAssertionAction()
235+
{
236+
MyController<MvcController>
237+
.Instance()
238+
.Calling(c => c.FileWithVirtualPath())
239+
.ShouldReturn()
240+
.File(file => file
241+
.Passing(f =>
242+
{
243+
const string expectedFileName = "/Test";
244+
var actualFileName = f.FileName;
245+
if (actualFileName != expectedFileName)
246+
{
247+
throw new InvalidAssertionException(
248+
string.Format("Expected {0} to have {1} equal to {2}, but it was {3}.",
249+
f.GetType().ToFriendlyTypeName(),
250+
nameof(f.FileName),
251+
expectedFileName,
252+
actualFileName));
253+
};
254+
}));
255+
}
202256
}
203257
}

0 commit comments

Comments
 (0)