From efc89fe58c8c88f2c2d072655cb0cca0ed9f0394 Mon Sep 17 00:00:00 2001 From: ByteBlast Date: Mon, 22 Sep 2014 06:24:04 +0100 Subject: [PATCH 1/2] Resolved forseen test name conflicts. --- TestStack.FluentMVCTesting.Tests/ControllerExtensionsTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TestStack.FluentMVCTesting.Tests/ControllerExtensionsTests.cs b/TestStack.FluentMVCTesting.Tests/ControllerExtensionsTests.cs index 21cd3b8..f4f20cb 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 = ""; From 856fa85931e7329bfe5cff45760a44f103931ef5 Mon Sep 17 00:00:00 2001 From: ByteBlast Date: Mon, 22 Sep 2014 06:45:51 +0100 Subject: [PATCH 2/2] Support for checking for non-existent temp data key. --- .../ControllerExtensionsTests.cs | 20 +++++++++++++++++++ .../ControllerExtensions.cs | 14 +++++++++++++ 2 files changed, 34 insertions(+) diff --git a/TestStack.FluentMVCTesting.Tests/ControllerExtensionsTests.cs b/TestStack.FluentMVCTesting.Tests/ControllerExtensionsTests.cs index f4f20cb..6c0d07d 100644 --- a/TestStack.FluentMVCTesting.Tests/ControllerExtensionsTests.cs +++ b/TestStack.FluentMVCTesting.Tests/ControllerExtensionsTests.cs @@ -146,5 +146,25 @@ public void Check_for_unexpected_non_existent_temp_data_property_when_supplied_w 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); + } + } }