99namespace FluentAssertions . Mvc3
1010{
1111 [ DebuggerNonUserCode ]
12- public abstract class ViewResultBaseAssertions < T > : ReferenceTypeAssertions < T , ViewResultBaseAssertions < T > >
12+ public abstract class ViewResultBaseAssertions < T > : ObjectAssertions
1313 where T : ViewResultBase
1414 {
15- public ViewResultBaseAssertions ( ViewResultBase subject )
15+ public ViewResultBaseAssertions ( ViewResultBase subject ) : base ( subject )
1616 {
1717 Subject = ( T ) subject ;
1818 }
@@ -25,10 +25,12 @@ public ViewResultBaseAssertions<T> WithViewName(string expectedViewName)
2525
2626 public ViewResultBaseAssertions < T > WithViewName ( string expectedViewName , string reason , params object [ ] reasonArgs )
2727 {
28+ string actualViewName = ( Subject as ViewResultBase ) . ViewName ;
29+
2830 Execute . Verification
29- . ForCondition ( string . Equals ( expectedViewName , Subject . ViewName , StringComparison . InvariantCultureIgnoreCase ) )
31+ . ForCondition ( string . Equals ( expectedViewName , actualViewName , StringComparison . InvariantCultureIgnoreCase ) )
3032 . BecauseOf ( reason , reasonArgs )
31- . FailWith ( "Expected ViewName to be '{0}' but was '{1}'" , expectedViewName , Subject . ViewName ) ;
33+ . FailWith ( "Expected ViewName to be '{0}' but was '{1}'" , expectedViewName , actualViewName ) ;
3234 return this ;
3335 }
3436
@@ -40,12 +42,14 @@ public ViewResultBaseAssertions<T> WithViewData(string key, object expectedValue
4042
4143 public ViewResultBaseAssertions < T > WithViewData ( string key , object expectedValue , string reason , params object [ ] reasonArgs )
4244 {
45+ ViewDataDictionary actualViewData = ( Subject as ViewResultBase ) . ViewData ;
46+
4347 Execute . Verification
44- . ForCondition ( Subject . ViewData . ContainsKey ( key ) )
48+ . ForCondition ( actualViewData . ContainsKey ( key ) )
4549 . BecauseOf ( reason , reasonArgs )
4650 . FailWith ( "ViewData does not contain key of '{0}'" , key ) ;
4751
48- Subject . ViewData [ key ] . Should ( ) . Be ( expectedValue ) ;
52+ actualViewData [ key ] . Should ( ) . Be ( expectedValue ) ;
4953
5054 return this ;
5155 }
@@ -58,12 +62,14 @@ public ViewResultBaseAssertions<T> WithTempData(string key, object expectedValue
5862
5963 public ViewResultBaseAssertions < T > WithTempData ( string key , object expectedValue , string reason , params object [ ] reasonArgs )
6064 {
65+ TempDataDictionary actualTempData = ( Subject as ViewResultBase ) . TempData ;
66+
6167 Execute . Verification
62- . ForCondition ( Subject . TempData . ContainsKey ( key ) )
68+ . ForCondition ( actualTempData . ContainsKey ( key ) )
6369 . BecauseOf ( reason , reasonArgs )
6470 . FailWith ( "TempData does not contain key of '{0}'" , key ) ;
6571
66- Subject . TempData [ key ] . Should ( ) . Be ( expectedValue ) ;
72+ actualTempData [ key ] . Should ( ) . Be ( expectedValue ) ;
6773
6874 return this ;
6975 }
@@ -72,17 +78,20 @@ public object Model
7278 {
7379 get
7480 {
75- return Subject . Model ;
81+ var model = ( Subject as ViewResult ) . Model ;
82+ return model ;
7683 }
7784 }
7885
7986 public TModel ModelAs < TModel > ( )
8087 {
88+ object model = ( Subject as ViewResultBase ) . Model ;
89+
8190 Execute . Verification
82- . ForCondition ( Subject . Model is TModel )
83- . FailWith ( "Expected Model to be of type '{0}' but was '{1}'" , typeof ( TModel ) . Name , Subject . Model . GetType ( ) . Name ) ;
91+ . ForCondition ( model is TModel )
92+ . FailWith ( "Expected Model to be of type '{0}' but was '{1}'" , typeof ( TModel ) . Name , model . GetType ( ) . Name ) ;
8493
85- return ( TModel ) Subject . Model ;
94+ return ( TModel ) model ;
8695 }
8796 }
8897}
0 commit comments