11using System ;
2+ using FluentAssertions . Mvc . Tests . Helpers ;
23using Microsoft . AspNetCore . Mvc ;
34using Xunit ;
45
56namespace FluentAssertions . AspNetCore . Mvc . Tests
67{
78 public class LocalRedirectObjectResultAssertions_Tests
89 {
10+ public const string Reason = FailureMessageHelper . Reason ;
11+ public readonly static object [ ] ReasonArgs = FailureMessageHelper . ReasonArgs ;
912 private const string TestLocalUrl = "localUrl" ;
1013
1114 [ Fact ]
1215 public void WithLocalUrl_GivenExpectedLocalUrl_ShouldPass ( )
1316 {
1417 var result = new TestController ( ) . LocalRedirect ( TestLocalUrl ) ;
18+
1519 result . Should ( ) . BeLocalRedirectResult ( ) . WithLocalUrl ( TestLocalUrl ) ;
1620 }
1721
@@ -21,16 +25,18 @@ public void WithLocalUrl_GivenUnexpectedLocalUrl_ShouldFail()
2125 const string actualLocalUrl = TestLocalUrl ;
2226 const string expectedLocalUrl = "otherUrl" ;
2327 ActionResult result = new LocalRedirectResult ( TestLocalUrl ) ;
28+ var failureMessage = FailureMessageHelper . ExpectedContextToBeXButY ( "LocalRedirectResult.LocalUrl" , expectedLocalUrl , actualLocalUrl ) ;
29+
30+ Action a = ( ) => result . Should ( ) . BeLocalRedirectResult ( ) . WithLocalUrl ( expectedLocalUrl , Reason , ReasonArgs ) ;
2431
25- var failureMessage = string . Format ( FailureMessages . CommonFailMessage , "LocalRedirectResult.LocalUrl" , expectedLocalUrl , actualLocalUrl ) ;
26- Action a = ( ) => result . Should ( ) . BeLocalRedirectResult ( ) . WithLocalUrl ( expectedLocalUrl ) ;
2732 a . Should ( ) . Throw < Exception > ( ) . WithMessage ( failureMessage ) ;
2833 }
2934
3035 [ Fact ]
3136 public void WithPermanent_GivenExpectedPermanent_ShouldPass ( )
3237 {
3338 var result = new TestController ( ) . LocalRedirectPermanent ( TestLocalUrl ) ;
39+
3440 result . Should ( ) . BeLocalRedirectResult ( ) . WithPermanent ( true ) ;
3541 }
3642
@@ -39,18 +45,19 @@ public void WithPermanent_GivenUnexpectedPermanent_ShouldFail()
3945 {
4046 var actualPermanent = true ;
4147 var expectedPermanent = false ;
42-
4348 ActionResult result = new LocalRedirectResult ( TestLocalUrl ) { Permanent = actualPermanent } ;
49+ var failureMessage = FailureMessageHelper . ExpectedContextToBeXButY ( "LocalRedirectResult.Permanent" , expectedPermanent , actualPermanent ) ;
50+
51+ Action a = ( ) => result . Should ( ) . BeLocalRedirectResult ( ) . WithPermanent ( expectedPermanent , Reason , ReasonArgs ) ;
4452
45- var failureMessage = $ "Expected LocalRedirectResult.Permanent to be { expectedPermanent } but was { actualPermanent } ";
46- Action a = ( ) => result . Should ( ) . BeLocalRedirectResult ( ) . WithPermanent ( expectedPermanent ) ;
4753 a . Should ( ) . Throw < Exception > ( ) . WithMessage ( failureMessage ) ;
4854 }
4955
5056 [ Fact ]
5157 public void WithPreserveMethod_GivenExpectedPreserveMethod_ShouldPass ( )
5258 {
5359 var result = new TestController ( ) . LocalRedirectPreserveMethod ( TestLocalUrl ) ;
60+
5461 result . Should ( ) . BeLocalRedirectResult ( ) . WithPreserveMethod ( true ) ;
5562 }
5663
@@ -59,18 +66,19 @@ public void WithPreserveMethod_GivenUnexpectedPreserveMethod_ShouldFail()
5966 {
6067 var actualPreserveMethod = true ;
6168 var expectedPreserveMethod = false ;
62-
6369 ActionResult result = new LocalRedirectResult ( TestLocalUrl ) { PreserveMethod = actualPreserveMethod } ;
70+ var failureMessage = FailureMessageHelper . ExpectedContextToBeXButY ( "LocalRedirectResult.PreserveMethod" , expectedPreserveMethod , actualPreserveMethod ) ;
71+
72+ Action a = ( ) => result . Should ( ) . BeLocalRedirectResult ( ) . WithPreserveMethod ( expectedPreserveMethod , Reason , ReasonArgs ) ;
6473
65- var failureMessage = $ "Expected LocalRedirectResult.PreserveMethod to be { expectedPreserveMethod } but was { actualPreserveMethod } ";
66- Action a = ( ) => result . Should ( ) . BeLocalRedirectResult ( ) . WithPreserveMethod ( expectedPreserveMethod ) ;
6774 a . Should ( ) . Throw < Exception > ( ) . WithMessage ( failureMessage ) ;
6875 }
6976
7077 [ Fact ]
7178 public void WithPreserveMethod_GivenExpectedPermanentPreserveMethod_ShouldPass ( )
7279 {
7380 var result = new TestController ( ) . LocalRedirectPermanentPreserveMethod ( TestLocalUrl ) ;
81+
7482 result . Should ( ) . BeLocalRedirectResult ( ) . WithPermanent ( true ) . WithPreserveMethod ( true ) ;
7583 }
7684 }
0 commit comments