Skip to content

Commit c700542

Browse files
committed
Made implementation adhere to DRY.
1 parent 3e440d8 commit c700542

File tree

1 file changed

+2
-35
lines changed

1 file changed

+2
-35
lines changed

TestStack.FluentMvcTesting/TempDataResultTest.cs

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,13 @@ public TempDataResultTest(ControllerBase controller)
1414

1515
public TempDataResultTest AndShouldHaveTempDataProperty(string key, object value = null)
1616
{
17-
var actual = _controller.TempData[key];
18-
19-
if (actual == null)
20-
{
21-
throw new TempDataAssertionException(string.Format(
22-
"Expected TempData to have a non-null value with key \"{0}\", but none found.", key));
23-
}
24-
25-
if (value != null && actual.GetType() != value.GetType())
26-
{
27-
throw new TempDataAssertionException(string.Format(
28-
"Expected value to be of type {0}, but instead was {1}.",
29-
value.GetType().FullName,
30-
actual.GetType().FullName));
31-
}
32-
33-
if (value != null && !value.Equals(actual))
34-
{
35-
throw new TempDataAssertionException(string.Format(
36-
"Expected value for key \"{0}\" to be \"{1}\", but instead found \"{2}\"", key, value, actual));
37-
}
38-
17+
_controller.ShouldHaveTempDataProperty(key, value);
3918
return this;
4019
}
4120

4221
public TempDataResultTest AndShouldHaveTempDataProperty<TValue>(string key, Func<TValue, bool> predicate)
4322
{
44-
var actual = _controller.TempData[key];
45-
46-
if (actual == null)
47-
{
48-
throw new TempDataAssertionException(string.Format(
49-
"Expected TempData to have a non-null value with key \"{0}\", but none found.", key));
50-
}
51-
52-
if (!predicate((TValue)actual))
53-
{
54-
throw new TempDataAssertionException("Expected view model to pass the given condition, but it failed.");
55-
}
56-
23+
_controller.ShouldHaveTempDataProperty(key, predicate);
5724
return this;
5825
}
5926
}

0 commit comments

Comments
 (0)