Skip to content
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
24 changes: 22 additions & 2 deletions TestStack.FluentMVCTesting.Tests/ControllerExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void Check_for_existent_temp_data_property()
}

[Test]
public void Check_for_non_existent_temp_data_property()
public void Check_for_unexpected_non_existent_temp_data_property()
{
const string key = "";

Expand Down Expand Up @@ -136,7 +136,7 @@ public void Check_for_existent_temp_data_property_and_check_value_using_invalid_
}

[Test]
public void Check_for_non_existent_temp_data_property_when_supplied_with_predicate()
public void Check_for_unexpected_non_existent_temp_data_property_when_supplied_with_predicate()
{
const string key = "";

Expand All @@ -146,5 +146,25 @@ public void Check_for_non_existent_temp_data_property_when_supplied_with_predica
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
.ShouldNotHaveTempDataProperty("");
}

[Test]
public void Check_for_unexpected_existent_temp_data_property()
{
const string Key = "";
_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)));
}
}
}
14 changes: 14 additions & 0 deletions TestStack.FluentMvcTesting/ControllerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,19 @@ public static TempDataResultTest ShouldHaveTempDataProperty<TValue>(this Control

return new TempDataResultTest(controller);
}

public static TempDataResultTest ShouldNotHaveTempDataProperty(this Controller controller, string key)
{
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);
}

}
}