1
- using System ;
2
- using System . Diagnostics ;
3
- using FluentAssertions . Execution ;
4
- using FluentAssertions . Primitives ;
1
+ using FluentAssertions . Execution ;
5
2
using Microsoft . AspNetCore . Mvc ;
3
+ using System ;
4
+ using System . Diagnostics ;
6
5
7
6
namespace FluentAssertions . AspNetCore . Mvc
8
7
{
9
8
/// <summary>
10
9
/// Contains a number of methods to assert that a <see cref="CreatedAtActionResult"/> is in the expected state.
11
10
/// </summary>
12
11
[ DebuggerNonUserCode ]
13
- public class CreatedAtActionResultAssertions : ObjectAssertions
12
+ public class CreatedAtActionResultAssertions : ObjectResultAssertionsBase < CreatedAtActionResult , CreatedAtActionResultAssertions >
14
13
{
15
14
/// <summary>
16
15
/// Initializes a new instance of the <see cref="CreatedAtActionResultAssertions" /> class.
@@ -30,7 +29,7 @@ public CreatedAtActionResultAssertions(CreatedAtActionResult subject) : base(sub
30
29
/// </param>
31
30
public CreatedAtActionResultAssertions WithActionName ( string expectedActionName , string reason = "" , params object [ ] reasonArgs )
32
31
{
33
- string actualActionName = ( Subject as CreatedAtActionResult ) ? . ActionName ;
32
+ string actualActionName = ObjectResultSubject . ActionName ;
34
33
35
34
Execute . Assertion
36
35
. ForCondition ( string . Equals ( actualActionName , expectedActionName , StringComparison . OrdinalIgnoreCase ) )
@@ -54,7 +53,7 @@ public CreatedAtActionResultAssertions WithActionName(string expectedActionName,
54
53
/// </param>
55
54
public CreatedAtActionResultAssertions WithControllerName ( string expectedControllerName , string reason = "" , params object [ ] reasonArgs )
56
55
{
57
- string actualControllerName = ( Subject as CreatedAtActionResult ) ? . ControllerName ;
56
+ string actualControllerName = ObjectResultSubject . ControllerName ;
58
57
59
58
Execute . Assertion
60
59
. ForCondition ( string . Equals ( actualControllerName , expectedControllerName , StringComparison . OrdinalIgnoreCase ) )
@@ -79,35 +78,12 @@ public CreatedAtActionResultAssertions WithControllerName(string expectedControl
79
78
/// </param>
80
79
public CreatedAtActionResultAssertions WithRouteValue ( string key , object expectedValue , string reason = "" , params object [ ] reasonArgs )
81
80
{
82
- var subjectTyped = Subject as CreatedAtActionResult ;
81
+ var actualRouteValues = ObjectResultSubject . RouteValues ;
83
82
84
- AssertionHelpers . AssertStringObjectDictionary ( subjectTyped . RouteValues , "CreatedAtActionResult.RouteValues" ,
83
+ AssertionHelpers . AssertStringObjectDictionary ( actualRouteValues , "CreatedAtActionResult.RouteValues" ,
85
84
key , expectedValue , reason , reasonArgs ) ;
86
85
87
86
return this ;
88
87
}
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
- }
112
88
}
113
89
}
0 commit comments