1- using System ;
2- using System . Diagnostics ;
3- using FluentAssertions . Execution ;
4- using FluentAssertions . Primitives ;
1+ using FluentAssertions . Execution ;
52using Microsoft . AspNetCore . Mvc ;
3+ using System ;
4+ using System . Diagnostics ;
65
76namespace FluentAssertions . AspNetCore . Mvc
87{
98 /// <summary>
109 /// Contains a number of methods to assert that a <see cref="CreatedAtActionResult"/> is in the expected state.
1110 /// </summary>
1211 [ DebuggerNonUserCode ]
13- public class CreatedAtActionResultAssertions : ObjectAssertions
12+ public class CreatedAtActionResultAssertions : ObjectResultAssertionsBase < CreatedAtActionResult , CreatedAtActionResultAssertions >
1413 {
1514 /// <summary>
1615 /// Initializes a new instance of the <see cref="CreatedAtActionResultAssertions" /> class.
@@ -30,7 +29,7 @@ public CreatedAtActionResultAssertions(CreatedAtActionResult subject) : base(sub
3029 /// </param>
3130 public CreatedAtActionResultAssertions WithActionName ( string expectedActionName , string reason = "" , params object [ ] reasonArgs )
3231 {
33- string actualActionName = ( Subject as CreatedAtActionResult ) ? . ActionName ;
32+ string actualActionName = ObjectResultSubject . ActionName ;
3433
3534 Execute . Assertion
3635 . ForCondition ( string . Equals ( actualActionName , expectedActionName , StringComparison . OrdinalIgnoreCase ) )
@@ -54,7 +53,7 @@ public CreatedAtActionResultAssertions WithActionName(string expectedActionName,
5453 /// </param>
5554 public CreatedAtActionResultAssertions WithControllerName ( string expectedControllerName , string reason = "" , params object [ ] reasonArgs )
5655 {
57- string actualControllerName = ( Subject as CreatedAtActionResult ) ? . ControllerName ;
56+ string actualControllerName = ObjectResultSubject . ControllerName ;
5857
5958 Execute . Assertion
6059 . ForCondition ( string . Equals ( actualControllerName , expectedControllerName , StringComparison . OrdinalIgnoreCase ) )
@@ -79,35 +78,12 @@ public CreatedAtActionResultAssertions WithControllerName(string expectedControl
7978 /// </param>
8079 public CreatedAtActionResultAssertions WithRouteValue ( string key , object expectedValue , string reason = "" , params object [ ] reasonArgs )
8180 {
82- var subjectTyped = Subject as CreatedAtActionResult ;
81+ var actualRouteValues = ObjectResultSubject . RouteValues ;
8382
84- AssertionHelpers . AssertStringObjectDictionary ( subjectTyped . RouteValues , "CreatedAtActionResult.RouteValues" ,
83+ AssertionHelpers . AssertStringObjectDictionary ( actualRouteValues , "CreatedAtActionResult.RouteValues" ,
8584 key , expectedValue , reason , reasonArgs ) ;
8685
8786 return this ;
8887 }
89-
90- /// <summary>
91- /// Asserts the value is of the expected type.
92- /// </summary>
93- /// <typeparam name="TValue">The expected type.</typeparam>
94- /// <returns>The typed value.</returns>
95- public TValue ValueAs < TValue > ( )
96- {
97- var subjectTyped = Subject as CreatedAtActionResult ;
98- var value = subjectTyped . Value ;
99-
100- if ( value == null )
101- Execute . Assertion
102- . WithDefaultIdentifier ( "CreatedAtActionResult.Value" )
103- . FailWith ( FailureMessages . CommonNullWasSuppliedFailMessage , typeof ( TValue ) ) ;
104-
105- Execute . Assertion
106- . ForCondition ( value is TValue )
107- . WithDefaultIdentifier ( "CreatedAtActionResult.Value" )
108- . FailWith ( FailureMessages . CommonTypeFailMessage , typeof ( TValue ) , value . GetType ( ) ) ;
109-
110- return ( TValue ) value ;
111- }
11288 }
11389}
0 commit comments