@@ -7,6 +7,8 @@ namespace FluentAssertions.AspNetCore.Mvc.Tests
77{
88 public class CreatedResultAssertions_Tests
99 {
10+ public const string Reason = FailureMessageHelper . Reason ;
11+ public readonly static object [ ] ReasonArgs = FailureMessageHelper . ReasonArgs ;
1012 private const string TestValue = "testValue" ;
1113
1214 private const string TestUriAsString = "http://localhost:5000" ;
@@ -19,78 +21,85 @@ public class CreatedResultAssertions_Tests
1921 public void Value_GivenExpectedValue_ShouldPass ( )
2022 {
2123 var result = new TestController ( ) . Created ( TestUri , TestValue ) ;
22- result . Should ( ) . BeCreatedResult ( ) . Value . Should ( ) . Be ( TestValue ) ;
23- }
2424
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 ) ;
3126 }
3227
3328 [ Fact ]
3429 public void ValueAs_GivenExpectedValue_ShouldPass ( )
3530 {
3631 var result = new TestController ( ) . Created ( TestUri , TestValue ) ;
32+
3733 result . Should ( ) . BeCreatedResult ( ) . ValueAs < string > ( ) . Should ( ) . Be ( TestValue ) ;
3834 }
3935
4036 [ Fact ]
4137 public void ValueAs_GivenUnexpectedValue_ShouldFail ( )
4238 {
4339 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+
4543 a . Should ( ) . Throw < Exception > ( ) ;
4644 }
4745
4846 [ Fact ]
4947 public void ValueAs_GivenWrongType_ShouldFail ( )
5048 {
5149 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 ) ;
5455 }
5556
5657 [ Fact ]
5758 public void ValueAs_Null_ShouldFail ( )
5859 {
5960 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+
6163 Action a = ( ) => result . Should ( ) . BeCreatedResult ( ) . ValueAs < object > ( ) ;
64+
6265 a . Should ( ) . Throw < Exception > ( ) . WithMessage ( failureMessage ) ;
6366 }
6467
6568 [ Fact ]
6669 public void WithUri_GivenExpectedUri_ShouldPass ( )
6770 {
6871 var result = new TestController ( ) . Created ( TestUri , TestValue ) ;
69- Action a = ( ) => result . Should ( ) . BeCreatedResult ( ) . WithUri ( TestUri ) ;
72+
73+ result . Should ( ) . BeCreatedResult ( ) . WithUri ( TestUri ) ;
7074 }
7175
7276 [ Fact ]
7377 public void WithUri_GivenWrongUri_ShouldFail ( )
7478 {
7579 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+
7884 a . Should ( ) . Throw < Exception > ( ) . WithMessage ( failureMessage ) ;
7985 }
8086
8187 [ Fact ]
8288 public void WithUri_GivenExpectedUriAsString_ShouldPass ( )
8389 {
8490 var result = new TestController ( ) . Created ( TestUriAsString , TestValue ) ;
85- Action a = ( ) => result . Should ( ) . BeCreatedResult ( ) . WithUri ( TestUriAsString ) ;
91+
92+ result . Should ( ) . BeCreatedResult ( ) . WithUri ( TestUriAsString ) ;
8693 }
8794
8895 [ Fact ]
8996 public void WithUri_GivenWrongUriAsString_ShouldFail ( )
9097 {
9198 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+
94103 a . Should ( ) . Throw < Exception > ( ) . WithMessage ( failureMessage ) ;
95104 }
96105 }
0 commit comments