3 files changed +44
-3
lines changed Original file line number Diff line number Diff line change @@ -25,8 +25,8 @@ public void GetActionResultOfT_OnFalse_Returns_Data()
25
25
26
26
var result = controller . GetActionResultOfT ( model , returnError ) ;
27
27
28
- result . Should ( ) . BeConvertibleTo < ObjectResult > ( )
29
- . And . Value . Should ( ) . BeSameAs ( model ) ;
28
+ result . Should ( ) . BeObjectResult ( )
29
+ . Value . Should ( ) . Be ( model ) ;
30
30
}
31
31
32
32
[ Fact ]
Original file line number Diff line number Diff line change @@ -79,6 +79,25 @@ public AndWhichConstraint<ActionResultAssertions<TValue>, TActionResult> BeConve
79
79
80
80
return new AndWhichConstraint < ActionResultAssertions < TValue > , TActionResult > ( this , ( TActionResult ) convertResult ) ;
81
81
}
82
+
83
+ /// <summary>
84
+ /// Asserts that the <see cref="ActionResult{TValue}.Result"/> is type of <see cref="ObjectResult"/>.
85
+ /// </summary>
86
+ /// <param name="reason">
87
+ /// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
88
+ /// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
89
+ /// </param>
90
+ /// <param name="reasonArgs">
91
+ /// Zero or more objects to format using the placeholders in <paramref name="reason"/>.
92
+ /// </param>
93
+ [ CustomAssertion ]
94
+ public ObjectResultAssertions BeObjectResult ( string reason = "" , params object [ ] reasonArgs )
95
+ {
96
+ var result = BeConvertibleTo < ObjectResult > ( reason , reasonArgs ) . Which ;
97
+
98
+ return new ObjectResultAssertions ( result ) ;
99
+ }
100
+
101
+ #endregion Public Methods
82
102
}
83
- #endregion Public Methods
84
103
}
Original file line number Diff line number Diff line change @@ -72,6 +72,28 @@ public void BeConvertibleTo_ShouldBeTheConvertedObject()
72
72
73
73
actual . Should ( ) . BeSameAs ( expectation ) ;
74
74
}
75
+
76
+ [ Fact ]
77
+ public void BeObjectResult_GivenActionResultWithObjectResult_ShouldPass ( )
78
+ {
79
+ var result = new ActionResult < object > ( new object ( ) ) ;
80
+
81
+ result . Should ( ) . BeObjectResult ( Reason , ReasonArgs ) ;
82
+ }
83
+
84
+ [ Fact ]
85
+ public void BeObjectResult_GivenActionResultWithNotObjectResult_ShouldFail ( )
86
+ {
87
+ var result = new ActionResult < object > ( new BadRequestObjectResult ( new object ( ) ) ) ;
88
+ var failureMessage = FailureMessageHelper . ExpectedContextToBeConvertible (
89
+ "result" , typeof ( ObjectResult ) . FullName , typeof ( BadRequestObjectResult ) . FullName ) ;
90
+
91
+ Action action = ( ) => result . Should ( ) . BeObjectResult ( Reason , ReasonArgs ) ;
92
+
93
+ action . Should ( ) . Throw < Exception > ( )
94
+ . WithMessage ( failureMessage ) ;
95
+ }
96
+
75
97
#endregion Public Methods
76
98
}
77
99
}
0 commit comments