@@ -10,11 +10,6 @@ namespace FluentAssertions.Mvc3
1010{
1111 public class RedirectToRouteAssertions : ReferenceTypeAssertions < RedirectToRouteResult , RedirectToRouteAssertions >
1212 {
13- public class Constants
14- {
15- public const string CommonFailMessage = "Expected RedirectResult.{0} to be '{1}' but was '{2}'" ;
16- }
17-
1813 public RedirectToRouteAssertions ( RedirectToRouteResult subject )
1914 {
2015 Subject = subject ;
@@ -29,10 +24,9 @@ public RedirectToRouteAssertions WithPermanent(bool expectedPermanent)
2924 public RedirectToRouteAssertions WithPermanent ( bool expectedPermanent , string reason , params object [ ] reasonArgs )
3025 {
3126 Execute . Verification
32- . ForCondition ( expectedPermanent == Subject . Permanent )
3327 . BecauseOf ( reason , reasonArgs )
34- . FailWith ( Constants . CommonFailMessage , "Permanent" , expectedPermanent , Subject . Permanent ) ;
35-
28+ . ForCondition ( expectedPermanent == Subject . Permanent )
29+ . FailWith ( "Expected RedirectToRoute.Permanent to be {0}{reason}, but found {1}" , expectedPermanent , Subject . Permanent ) ;
3630 return this ;
3731 }
3832
@@ -45,13 +39,25 @@ public RedirectToRouteAssertions WithRouteName(string expectedRouteName)
4539 public RedirectToRouteAssertions WithRouteName ( string expectedRouteName , string reason , params object [ ] reasonArgs )
4640 {
4741 Execute . Verification
48- . ForCondition ( string . Equals ( expectedRouteName , Subject . RouteName , StringComparison . InvariantCultureIgnoreCase ) )
4942 . BecauseOf ( reason , reasonArgs )
50- . FailWith ( Constants . CommonFailMessage , "RouteName" , expectedRouteName , Subject . Permanent ) ;
43+ . ForCondition ( string . Equals ( expectedRouteName , Subject . RouteName , StringComparison . InvariantCultureIgnoreCase ) )
44+ . FailWith ( "Expected RedirectToRoute.RouteName to be {0}{reason}, but found {1}" , expectedRouteName , Subject . RouteName ) ;
5145
5246 return this ;
5347 }
5448
49+ public RedirectToRouteAssertions WithRouteValue ( string key , object expectedValue )
50+ {
51+ WithRouteValue ( key , expectedValue , string . Empty , null ) ;
52+ return this ;
53+ }
54+
55+ public RedirectToRouteAssertions WithRouteValue ( string key , object expectedValue , string reason , params object [ ] reasonArgs )
56+ {
57+ Subject . RouteValues . Should ( ) . Contain ( new KeyValuePair < string , object > ( key , expectedValue ) , reason , reasonArgs ) ;
58+ return this ;
59+ }
60+
5561 public RedirectToRouteAssertions WithController ( string expectedControllerName )
5662 {
5763 WithController ( expectedControllerName , string . Empty , null ) ;
@@ -60,27 +66,31 @@ public RedirectToRouteAssertions WithController(string expectedControllerName)
6066
6167 public RedirectToRouteAssertions WithController ( string expectedControllerName , string reason , params object [ ] reasonArgs )
6268 {
63- //Subject.RouteValues[""]
64-
69+ WithRouteValue ( "Controller" , expectedControllerName , reason , reasonArgs ) ;
6570 return this ;
6671 }
6772
68- public RedirectToRouteAssertions WithRouteValue ( string key , object expectedValue )
73+ public RedirectToRouteAssertions WithAction ( string expectedAction )
6974 {
70- WithRouteValue ( key , expectedValue , string . Empty , null ) ;
75+ WithAction ( expectedAction , string . Empty , null ) ;
7176 return this ;
7277 }
7378
74- public RedirectToRouteAssertions WithRouteValue ( string key , object expectedValue , string reason , params object [ ] reasonArgs )
79+ public RedirectToRouteAssertions WithAction ( string expectedArea , string reason , params object [ ] reasonArgs )
7580 {
76- Execute . Verification
77- . ForCondition ( Subject . RouteValues . ContainsKey ( key ) )
78- . BecauseOf ( reason , reasonArgs )
79- . FailWith ( string . Format ( "RedirectResult.RouteValues does not contain key '{0}'" , key ) ) ;
80-
81- var actualValue = Subject . RouteValues [ key ] ;
82- actualValue . Should ( ) . Be ( expectedValue ) ;
81+ WithRouteValue ( "Action" , expectedArea , reason , reasonArgs ) ;
82+ return this ;
83+ }
8384
85+ public RedirectToRouteAssertions WithArea ( string expectedAction )
86+ {
87+ WithArea ( expectedAction , string . Empty , null ) ;
88+ return this ;
89+ }
90+
91+ public RedirectToRouteAssertions WithArea ( string expectedArea , string reason , params object [ ] reasonArgs )
92+ {
93+ WithRouteValue ( "Area" , expectedArea , reason , reasonArgs ) ;
8494 return this ;
8595 }
8696 }
0 commit comments