-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathRouteValueDictionaryExtension.cs
More file actions
36 lines (29 loc) · 1.19 KB
/
RouteValueDictionaryExtension.cs
File metadata and controls
36 lines (29 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System.Web.Routing;
namespace TestStack.FluentMVCTesting
{
public static class RouteValueDictionaryExtension
{
public static RouteValueDictionary WithRouteValue(this RouteValueDictionary dict, string key)
{
if (!dict.ContainsKey(key))
{
throw new MissingRouteValueException(string.Format("No value {0} in the route dictionary", key));
}
return dict;
}
public static RouteValueDictionary WithRouteValue<T>(this RouteValueDictionary dict, string key, T value)
{
dict.WithRouteValue(key);
var actualValue = dict[key];
if (!(actualValue is T))
{
throw new ValueTypeMismatchException(string.Format("Invalid type of Value with key {0} \r\n expected {1} \r\n but got {2}", key, value.GetType(), actualValue.GetType()));
}
if (!Equals(actualValue, value))
{
throw new InvalidRouteValueException(string.Format("Invalid value for key {0} \r\n expected {1} \r\n but got {2} in the route dictionary",key ,value, actualValue));
}
return dict;
}
}
}