Skip to content

Consistent error messages #55

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

Merged
merged 2 commits into from
Apr 8, 2015
Merged
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
12 changes: 12 additions & 0 deletions BREAKING_CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ You can read the original problem specification and discussion [here](https://g

If your project has been impacted by this particular breaking change, you might consider reevaluate the correctness of the affected tests.

## Error Messages

Some error messages surrounded actual values in double quotes. Others surrounded the values in single quotes. In version 3.0.0 *all* values are surrounded in single quotes.

### Reason

Consistency.

### Fix

Amend all effected tests to expect single quotes instead of double quotes.

# Version 2.0.0

## ShouldRenderFileStream Method
Expand Down
56 changes: 28 additions & 28 deletions TestStack.FluentMVCTesting.Tests/ControllerExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ public void Check_for_unexpected_non_existent_temp_data_property()
const string key = "";

var exception = Assert.Throws<TempDataAssertionException>(() =>
_controller.ShouldHaveTempDataProperty(key));
Assert.That(exception.Message, Is.EqualTo(string.Format(
"Expected TempData to have a non-null value with key \"{0}\", but none found.", key)));
}
[Test]
_controller.ShouldHaveTempDataProperty(key));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the diff so big? Is there whitespace changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think so. I will double check if you cannot. I am working on #54 at the moment.


Assert.That(exception.Message, Is.EqualTo(string.Format(
"Expected TempData to have a non-null value with key '{0}', but none found.", key)));
}

[Test]
public void Check_for_existent_temp_data_property_and_check_value()
{
const string key = "";
Expand All @@ -82,13 +82,13 @@ public void Check_for_existent_temp_data_property_and_check_invalid_value()
const int expectedValue = 1;
_controller.TempData[key] = actualValue;

var exception = Assert.Throws<TempDataAssertionException>(() =>
_controller.ShouldHaveTempDataProperty(key, expectedValue));
Assert.That(exception.Message, Is.EqualTo(string.Format("Expected value for key \"{0}\" to be \"{1}\", but instead found \"{2}\"", key, expectedValue, actualValue)));
}
[Test]
var exception = Assert.Throws<TempDataAssertionException>(() =>
_controller.ShouldHaveTempDataProperty(key, expectedValue));

Assert.That(exception.Message, Is.EqualTo(string.Format("Expected value for key '{0}' to be '{1}', but instead found '{2}'", key, expectedValue, actualValue)));
}

[Test]
public void Check_for_existent_temp_data_property_and_check_invalid_value_of_different_types()
{
const string key = "";
Expand Down Expand Up @@ -141,13 +141,13 @@ public void Check_for_unexpected_non_existent_temp_data_property_when_supplied_w
const string key = "";

var exception = Assert.Throws<TempDataAssertionException>(() =>
_controller.ShouldHaveTempDataProperty<int>(key, x => x == 0));
Assert.That(exception.Message, Is.EqualTo(string.Format(
"Expected TempData to have a non-null value with key \"{0}\", but none found.", key)));
}
[Test]
_controller.ShouldHaveTempDataProperty<int>(key, x => x == 0));

Assert.That(exception.Message, Is.EqualTo(string.Format(
"Expected TempData to have a non-null value with key '{0}', but none found.", key)));
}

[Test]
public void Check_for_non_existent_temp_data_property()
{
_controller
Expand All @@ -161,10 +161,10 @@ public void Check_for_unexpected_existent_temp_data_property()
_controller.TempData[Key] = "";

var exception = Assert.Throws<TempDataAssertionException>(() =>
_controller.ShouldNotHaveTempDataProperty(Key));
Assert.That(exception.Message, Is.EqualTo(string.Format(
"Expected TempData to have no value with key \"{0}\", but found one.", Key)));
}
}
}
_controller.ShouldNotHaveTempDataProperty(Key));

Assert.That(exception.Message, Is.EqualTo(string.Format(
"Expected TempData to have no value with key '{0}', but found one.", Key)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void Check_for_file_content_result_and_check_invalid_textual_contents()
var exception = Assert.Throws<ActionResultAssertionException>(() =>
_controller.WithCallTo(c => c.TextualFile()).ShouldRenderFileContents(contents));

Assert.That(exception.Message, Is.EqualTo(string.Format("Expected file contents to be \"{0}\", but instead was \"{1}\".", contents, ControllerResultTestController.TextualFileContent)));
Assert.That(exception.Message, Is.EqualTo(string.Format("Expected file contents to be '{0}', but instead was '{1}'.", contents, ControllerResultTestController.TextualFileContent)));
}

[Test]
Expand Down Expand Up @@ -309,7 +309,7 @@ public void Check_for_file_stream_result_and_check_invalid_textual_content()
var exception = Assert.Throws<ActionResultAssertionException>(() =>
_controller.WithCallTo(c => c.TextualStream()).ShouldRenderFileStream(contents));

Assert.That(exception.Message, Is.EqualTo(string.Format("Expected file contents to be \"{0}\", but instead was \"{1}\".", contents, ControllerResultTestController.TextualFileContent)));
Assert.That(exception.Message, Is.EqualTo(string.Format("Expected file contents to be '{0}', but instead was '{1}'.", contents, ControllerResultTestController.TextualFileContent)));
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void Check_for_content_result_and_check_invalid_content()

var exception = Assert.Throws<ActionResultAssertionException>(() => _controller.WithCallTo(c => c.Content()).ShouldReturnContent(content));

Assert.That(exception.Message, Is.EqualTo(string.Format("Expected content to be \"{0}\", but instead was \"{1}\".", content, ControllerResultTestController.TextualContent)));
Assert.That(exception.Message, Is.EqualTo(string.Format("Expected content to be '{0}', but instead was '{1}'.", content, ControllerResultTestController.TextualContent)));
}

[Test]
Expand All @@ -42,7 +42,7 @@ public void Check_for_content_result_and_check_content_and_check_invalid_content

var exception = Assert.Throws<ActionResultAssertionException>(() => _controller.WithCallTo(c => c.Content()).ShouldReturnContent(ControllerResultTestController.TextualContent, contentType));

Assert.That(exception.Message, Is.EqualTo(string.Format("Expected content type to be \"{0}\", but instead was \"{1}\".", contentType, ControllerResultTestController.ContentType)));
Assert.That(exception.Message, Is.EqualTo(string.Format("Expected content type to be '{0}', but instead was '{1}'.", contentType, ControllerResultTestController.ContentType)));
}

[Test]
Expand Down
8 changes: 4 additions & 4 deletions TestStack.FluentMVCTesting.Tests/TempDataResultTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void Check_for_unexpected_non_existent_temp_data_property()
_tempDataTest.AndShouldHaveTempDataProperty(key));

Assert.That(exception.Message, Is.EqualTo(string.Format(
"Expected TempData to have a non-null value with key \"{0}\", but none found.", key)));
"Expected TempData to have a non-null value with key '{0}', but none found.", key)));
}

[Test]
Expand All @@ -59,7 +59,7 @@ public void Check_for_existent_temp_data_property_and_check_invalid_value()
var exception = Assert.Throws<TempDataAssertionException>(() =>
_tempDataTest.AndShouldHaveTempDataProperty(key, expectedValue));

Assert.That(exception.Message, Is.EqualTo(string.Format("Expected value for key \"{0}\" to be \"{1}\", but instead found \"{2}\"", key, expectedValue, actualValue)));
Assert.That(exception.Message, Is.EqualTo(string.Format("Expected value for key '{0}' to be '{1}', but instead found '{2}'", key, expectedValue, actualValue)));
}

[Test]
Expand Down Expand Up @@ -117,7 +117,7 @@ public void Check_for_non_existent_temp_data_property_when_supplied_with_predica
_tempDataTest.AndShouldHaveTempDataProperty<int>(key, x => x == 0));

Assert.That(exception.Message, Is.EqualTo(string.Format(
"Expected TempData to have a non-null value with key \"{0}\", but none found.", key)));
"Expected TempData to have a non-null value with key '{0}', but none found.", key)));
}

[Test]
Expand All @@ -137,7 +137,7 @@ public void Check_for_unexpected_existent_temp_data_property()
_tempDataTest.AndShouldNotHaveTempDataProperty(Key));

Assert.That(exception.Message, Is.EqualTo(string.Format(
"Expected TempData to have no value with key \"{0}\", but found one.", Key)));
"Expected TempData to have no value with key '{0}', but found one.", Key)));
}

[Test]
Expand Down
56 changes: 28 additions & 28 deletions TestStack.FluentMvcTesting/ControllerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,40 +64,40 @@ public static TempDataResultTest ShouldHaveTempDataProperty(this ControllerBase
{
var actual = controller.TempData[key];

if (actual == null)
{
throw new TempDataAssertionException(string.Format(
"Expected TempData to have a non-null value with key \"{0}\", but none found.", key));
}
if (value != null && actual.GetType() != value.GetType())
if (actual == null)
{
throw new TempDataAssertionException(string.Format(
"Expected TempData to have a non-null value with key '{0}', but none found.", key));
}

if (value != null && actual.GetType() != value.GetType())
{
throw new TempDataAssertionException(string.Format(
"Expected value to be of type {0}, but instead was {1}.",
value.GetType().FullName,
actual.GetType().FullName));
}

if (value != null && !value.Equals(actual))
{
throw new TempDataAssertionException(string.Format(
"Expected value for key \"{0}\" to be \"{1}\", but instead found \"{2}\"", key, value, actual));
}
return new TempDataResultTest(controller);
if (value != null && !value.Equals(actual))
{
throw new TempDataAssertionException(string.Format(
"Expected value for key '{0}' to be '{1}', but instead found '{2}'", key, value, actual));
}

return new TempDataResultTest(controller);
}

public static TempDataResultTest ShouldHaveTempDataProperty<TValue>(this ControllerBase controller, string key, Func<TValue, bool> predicate)
{
var actual = controller.TempData[key];

if (actual == null)
{
throw new TempDataAssertionException(string.Format(
"Expected TempData to have a non-null value with key \"{0}\", but none found.", key));
}
if (!predicate((TValue)actual))
if (actual == null)
{
throw new TempDataAssertionException(string.Format(
"Expected TempData to have a non-null value with key '{0}', but none found.", key));
}

if (!predicate((TValue)actual))
{
throw new TempDataAssertionException("Expected view model to pass the given condition, but it failed.");
}
Expand All @@ -109,13 +109,13 @@ public static TempDataResultTest ShouldNotHaveTempDataProperty(this ControllerBa
{
var actual = controller.TempData[key];

if (actual != null)
{
throw new TempDataAssertionException(string.Format(
"Expected TempData to have no value with key \"{0}\", but found one.", key));
}
return new TempDataResultTest(controller);
if (actual != null)
{
throw new TempDataAssertionException(string.Format(
"Expected TempData to have no value with key '{0}', but found one.", key));
}

return new TempDataResultTest(controller);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public FileContentResult ShouldRenderFileContents(string contents, string conten
if (contents != reconstitutedText)
{
throw new ActionResultAssertionException(string.Format(
"Expected file contents to be \"{0}\", but instead was \"{1}\".",
"Expected file contents to be '{0}', but instead was '{1}'.",
contents,
reconstitutedText));
}
Expand Down Expand Up @@ -121,7 +121,7 @@ public FileStreamResult ShouldRenderFileStream(string contents, string contentTy
if (contents != reconstitutedText)
{
throw new ActionResultAssertionException(string.Format(
"Expected file contents to be \"{0}\", but instead was \"{1}\".",
"Expected file contents to be '{0}', but instead was '{1}'.",
contents,
reconstitutedText));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ public ContentResult ShouldReturnContent(string content = null, string contentTy
if (contentType != null && contentType != contentResult.ContentType)
{
throw new ActionResultAssertionException(string.Format(
"Expected content type to be \"{0}\", but instead was \"{1}\".",
"Expected content type to be '{0}', but instead was '{1}'.",
contentType,
contentResult.ContentType));
}

if (content != null && content != contentResult.Content)
{
throw new ActionResultAssertionException(string.Format(
"Expected content to be \"{0}\", but instead was \"{1}\".",
"Expected content to be '{0}', but instead was '{1}'.",
content,
contentResult.Content));
}
Expand Down