diff --git a/TestStack.FluentMVCTesting.Tests/ControllerExtensionsTests.cs b/TestStack.FluentMVCTesting.Tests/ControllerExtensionsTests.cs index 21cd3b8..6c0d07d 100644 --- a/TestStack.FluentMVCTesting.Tests/ControllerExtensionsTests.cs +++ b/TestStack.FluentMVCTesting.Tests/ControllerExtensionsTests.cs @@ -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 = ""; @@ -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 = ""; @@ -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(() => + _controller.ShouldNotHaveTempDataProperty(Key)); + + Assert.That(exception.Message, Is.EqualTo(string.Format( + "Expected TempData to have no value with key \"{0}\", but found one.", Key))); + } } } diff --git a/TestStack.FluentMvcTesting/ControllerExtensions.cs b/TestStack.FluentMvcTesting/ControllerExtensions.cs index efad62b..55835d6 100644 --- a/TestStack.FluentMvcTesting/ControllerExtensions.cs +++ b/TestStack.FluentMvcTesting/ControllerExtensions.cs @@ -104,5 +104,19 @@ public static TempDataResultTest ShouldHaveTempDataProperty(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); + } + } }