@@ -7,6 +7,8 @@ namespace FluentAssertions.AspNetCore.Mvc.Tests
7
7
{
8
8
public class CreatedResultAssertions_Tests
9
9
{
10
+ public const string Reason = FailureMessageHelper . Reason ;
11
+ public readonly static object [ ] ReasonArgs = FailureMessageHelper . ReasonArgs ;
10
12
private const string TestValue = "testValue" ;
11
13
12
14
private const string TestUriAsString = "http://localhost:5000" ;
@@ -19,78 +21,85 @@ public class CreatedResultAssertions_Tests
19
21
public void Value_GivenExpectedValue_ShouldPass ( )
20
22
{
21
23
var result = new TestController ( ) . Created ( TestUri , TestValue ) ;
22
- result . Should ( ) . BeCreatedResult ( ) . Value . Should ( ) . Be ( TestValue ) ;
23
- }
24
24
25
- [ Fact ]
26
- public void Value_GivenUnexpectedValue_ShouldFail ( )
27
- {
28
- var result = new TestController ( ) . Created ( TestUri , TestValue ) ;
29
- Action a = ( ) => result . Should ( ) . BeCreatedResult ( ) . Value . Should ( ) . Be ( "xyx" ) ;
30
- a . Should ( ) . Throw < Exception > ( ) ;
25
+ result . Should ( ) . BeCreatedResult ( ) . Value . Should ( ) . BeSameAs ( TestValue ) ;
31
26
}
32
27
33
28
[ Fact ]
34
29
public void ValueAs_GivenExpectedValue_ShouldPass ( )
35
30
{
36
31
var result = new TestController ( ) . Created ( TestUri , TestValue ) ;
32
+
37
33
result . Should ( ) . BeCreatedResult ( ) . ValueAs < string > ( ) . Should ( ) . Be ( TestValue ) ;
38
34
}
39
35
40
36
[ Fact ]
41
37
public void ValueAs_GivenUnexpectedValue_ShouldFail ( )
42
38
{
43
39
var result = new TestController ( ) . Created ( TestUri , TestValue ) ;
44
- Action a = ( ) => result . Should ( ) . BeCreatedResult ( ) . ValueAs < string > ( ) . Should ( ) . Be ( "xyx" ) ;
40
+
41
+ Action a = ( ) => result . Should ( ) . BeCreatedResult ( ) . ValueAs < string > ( ) . Should ( ) . Be ( "xyx" , Reason , ReasonArgs ) ;
42
+
45
43
a . Should ( ) . Throw < Exception > ( ) ;
46
44
}
47
45
48
46
[ Fact ]
49
47
public void ValueAs_GivenWrongType_ShouldFail ( )
50
48
{
51
49
var result = new TestController ( ) . Created ( TestUri , TestValue ) ;
52
- Action a = ( ) => result . Should ( ) . BeCreatedResult ( ) . ValueAs < int > ( ) . Should ( ) . Be ( 2 ) ;
53
- a . Should ( ) . Throw < Exception > ( ) ;
50
+ var failureMessage = FailureMessageHelper . ExpectedContextTypeXButFoundY ( "CreatedResult.Value" , typeof ( int ) . FullName , typeof ( string ) . FullName ) ;
51
+
52
+ Action a = ( ) => result . Should ( ) . BeCreatedResult ( ) . ValueAs < int > ( ) . Should ( ) . Be ( 2 , Reason , ReasonArgs ) ;
53
+
54
+ a . Should ( ) . Throw < Exception > ( ) . WithMessage ( failureMessage ) ;
54
55
}
55
56
56
57
[ Fact ]
57
58
public void ValueAs_Null_ShouldFail ( )
58
59
{
59
60
ActionResult result = new CreatedResult ( TestUri , null ) ;
60
- var failureMessage = FailureMessageHelper . Format ( FailureMessages . CommonNullWasSuppliedFailMessage , "CreatedResult.Value" , typeof ( object ) . Name ) ;
61
+ var failureMessage = FailureMessageHelper . ExpectedContextTypeXButFoundNull ( "CreatedResult.Value" , typeof ( object ) . FullName ) ;
62
+
61
63
Action a = ( ) => result . Should ( ) . BeCreatedResult ( ) . ValueAs < object > ( ) ;
64
+
62
65
a . Should ( ) . Throw < Exception > ( ) . WithMessage ( failureMessage ) ;
63
66
}
64
67
65
68
[ Fact ]
66
69
public void WithUri_GivenExpectedUri_ShouldPass ( )
67
70
{
68
71
var result = new TestController ( ) . Created ( TestUri , TestValue ) ;
69
- Action a = ( ) => result . Should ( ) . BeCreatedResult ( ) . WithUri ( TestUri ) ;
72
+
73
+ result . Should ( ) . BeCreatedResult ( ) . WithUri ( TestUri ) ;
70
74
}
71
75
72
76
[ Fact ]
73
77
public void WithUri_GivenWrongUri_ShouldFail ( )
74
78
{
75
79
var result = new TestController ( ) . Created ( TestWrongUri , TestValue ) ;
76
- Action a = ( ) => result . Should ( ) . BeCreatedResult ( ) . WithUri ( TestUri ) ;
77
- var failureMessage = FailureMessageHelper . Format ( FailureMessages . CommonFailMessage , "CreatedResult.Uri" , TestUri . ToString ( ) , TestWrongUri . ToString ( ) ) ;
80
+ var failureMessage = FailureMessageHelper . ExpectedContextToBeXButY ( "CreatedResult.Uri" , TestUri , TestWrongUri ) ;
81
+
82
+ Action a = ( ) => result . Should ( ) . BeCreatedResult ( ) . WithUri ( TestUri , Reason , ReasonArgs ) ;
83
+
78
84
a . Should ( ) . Throw < Exception > ( ) . WithMessage ( failureMessage ) ;
79
85
}
80
86
81
87
[ Fact ]
82
88
public void WithUri_GivenExpectedUriAsString_ShouldPass ( )
83
89
{
84
90
var result = new TestController ( ) . Created ( TestUriAsString , TestValue ) ;
85
- Action a = ( ) => result . Should ( ) . BeCreatedResult ( ) . WithUri ( TestUriAsString ) ;
91
+
92
+ result . Should ( ) . BeCreatedResult ( ) . WithUri ( TestUriAsString ) ;
86
93
}
87
94
88
95
[ Fact ]
89
96
public void WithUri_GivenWrongUriAsString_ShouldFail ( )
90
97
{
91
98
var result = new TestController ( ) . Created ( TestWrongUriAsString , TestValue ) ;
92
- Action a = ( ) => result . Should ( ) . BeCreatedResult ( ) . WithUri ( TestUriAsString ) ;
93
- var failureMessage = FailureMessageHelper . Format ( FailureMessages . CommonFailMessage , "CreatedResult.Uri" , TestUriAsString , TestWrongUriAsString ) ;
99
+ var failureMessage = FailureMessageHelper . ExpectedContextToBeXButY ( "CreatedResult.Uri" , TestUriAsString , TestWrongUriAsString ) ;
100
+
101
+ Action a = ( ) => result . Should ( ) . BeCreatedResult ( ) . WithUri ( TestUriAsString , Reason , ReasonArgs ) ;
102
+
94
103
a . Should ( ) . Throw < Exception > ( ) . WithMessage ( failureMessage ) ;
95
104
}
96
105
}
0 commit comments