Skip to content

Commit 856fa85

Browse files
committed
Support for checking for non-existent temp data key.
1 parent efc89fe commit 856fa85

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

TestStack.FluentMVCTesting.Tests/ControllerExtensionsTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,5 +146,25 @@ public void Check_for_unexpected_non_existent_temp_data_property_when_supplied_w
146146
Assert.That(exception.Message, Is.EqualTo(string.Format(
147147
"Expected TempData to have a non-null value with key \"{0}\", but none found.", key)));
148148
}
149+
150+
[Test]
151+
public void Check_for_non_existent_temp_data_property()
152+
{
153+
_controller
154+
.ShouldNotHaveTempDataProperty("");
155+
}
156+
157+
[Test]
158+
public void Check_for_unexpected_existent_temp_data_property()
159+
{
160+
const string Key = "";
161+
_controller.TempData[Key] = "";
162+
163+
var exception = Assert.Throws<TempDataAssertionException>(() =>
164+
_controller.ShouldNotHaveTempDataProperty(Key));
165+
166+
Assert.That(exception.Message, Is.EqualTo(string.Format(
167+
"Expected TempData to have no value with key \"{0}\", but found one.", Key)));
168+
}
149169
}
150170
}

TestStack.FluentMvcTesting/ControllerExtensions.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,19 @@ public static TempDataResultTest ShouldHaveTempDataProperty<TValue>(this Control
104104

105105
return new TempDataResultTest(controller);
106106
}
107+
108+
public static TempDataResultTest ShouldNotHaveTempDataProperty(this Controller controller, string key)
109+
{
110+
var actual = controller.TempData[key];
111+
112+
if (actual != null)
113+
{
114+
throw new TempDataAssertionException(string.Format(
115+
"Expected TempData to have no value with key \"{0}\", but found one.", key));
116+
}
117+
118+
return new TempDataResultTest(controller);
119+
}
120+
107121
}
108122
}

0 commit comments

Comments
 (0)