Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Issue 40 #41

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ TestResult.xml
[Pp]ackages/
*.nupkg
/.vs
_ReSharper.Caches
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public ViewResultBaseAssertions<T> WithViewData(string key, object expectedValue
var actualValue = actualViewData[key];

Execute.Assertion
.ForCondition(actualValue.Equals(expectedValue))
.ForCondition(object.Equals(actualValue, expectedValue))
.BecauseOf(reason, reasonArgs)
.FailWith(FailureMessages.ViewResultBase_ViewData_HaveValue, key, expectedValue, actualValue);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace FluentAssertions.Mvc.Tests.Helpers
static class FailureMessageHelper
{
public static string Format(string message, params string[] args)
{
var formattedArg = args.Select(x => String.Format("\"{0}\"", x)).ToArray();
{
var formattedArg = args.Select(x => (object)(x == null ? "<null>" : string.Format("\"{0}\"", x))).ToArray();

return String.Format(message, formattedArg);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,31 @@ public void WithViewData_GivenUnexpectedValue_ShouldFail()
.WithMessage(failureMessage);
}

[Test]
public void WithViewData_GivenUnexpectedValue_ActualValueIsNull_ShouldFail()
{
var key = "key1";
const object actualValue = null;
var expectedValue = "abc";
var failureMessage = FailureMessageHelper.Format(FailureMessages.ViewResultBase_ViewData_HaveValue, key, expectedValue, null);

#if NETCOREAPP1_0
var result = new TestController().ViewWithOneViewDataWhereValueIsNull(); // Where is TestController defined?
#else
ActionResult result = new ViewResult
{
ViewData = new ViewDataDictionary { { key, actualValue } }
};
#endif

Action a = () => result.Should().BeViewResult().WithViewData(key, expectedValue);

a.Should()
.Throw<Exception>()
.WithMessage(failureMessage)
.And.Should().NotBeOfType<NullReferenceException>();
}

[Test]
public void WithViewData_GivenUnexpectedKey_ShouldFail()
{
Expand Down