Skip to content

Commit a916640

Browse files
committed
Tweak to prevent confusing NRE from surfacing.
1 parent 1ebe99c commit a916640

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

TestStack.FluentMVCTesting.Tests/ControllerResultTestTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,14 @@ public void Check_for_content_result_and_check_invalid_content_and_check_invalid
844844
Assert.That(exception.Message.Contains("content type"));
845845
}
846846

847+
[Test]
848+
public void Emit_readable_error_message_when_the_actual_content_encoding_has_not_been_specified()
849+
{
850+
var exception = Assert.Throws<ActionResultAssertionException>(() => _controller.WithCallTo(c => c.ContentWithoutEncodingSpecified()).ShouldReturnContent(encoding: ControllerResultTestController.TextualContentEncoding));
851+
852+
Assert.That(exception.Message, Is.EqualTo(string.Format("Expected encoding to be equal to {0}, but instead was null.", ControllerResultTestController.TextualContentEncoding.EncodingName)));
853+
}
854+
847855
#endregion
848856
}
849857
}

TestStack.FluentMVCTesting.Tests/TestControllers/ControllerResultTestController.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,11 @@ public ActionResult Content()
237237
return Content(TextualContent, ContentType, TextualContentEncoding);
238238
}
239239

240+
public ActionResult ContentWithoutEncodingSpecified()
241+
{
242+
return Content(TextualContent, ContentType);
243+
}
244+
240245
#endregion
241246
}
242247

TestStack.FluentMvcTesting/ControllerResultTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ public ContentResult ShouldReturnContent(string content = null, string contentTy
425425
throw new ActionResultAssertionException(string.Format(
426426
"Expected encoding to be equal to {0}, but instead was {1}.",
427427
encoding.EncodingName,
428-
contentResult.ContentEncoding.EncodingName));
428+
contentResult.ContentEncoding != null ? contentResult.ContentEncoding.EncodingName : @"null"));
429429
}
430430

431431
return contentResult;

0 commit comments

Comments
 (0)