1
1
using System ;
2
+ using FluentAssertions . Mvc . Tests . Helpers ;
2
3
using Microsoft . AspNetCore . Mvc ;
3
4
using Xunit ;
4
5
5
6
namespace FluentAssertions . AspNetCore . Mvc . Tests
6
7
{
7
8
public class LocalRedirectObjectResultAssertions_Tests
8
9
{
10
+ public const string Reason = FailureMessageHelper . Reason ;
11
+ public readonly static object [ ] ReasonArgs = FailureMessageHelper . ReasonArgs ;
9
12
private const string TestLocalUrl = "localUrl" ;
10
13
11
14
[ Fact ]
12
15
public void WithLocalUrl_GivenExpectedLocalUrl_ShouldPass ( )
13
16
{
14
17
var result = new TestController ( ) . LocalRedirect ( TestLocalUrl ) ;
18
+
15
19
result . Should ( ) . BeLocalRedirectResult ( ) . WithLocalUrl ( TestLocalUrl ) ;
16
20
}
17
21
@@ -21,16 +25,18 @@ public void WithLocalUrl_GivenUnexpectedLocalUrl_ShouldFail()
21
25
const string actualLocalUrl = TestLocalUrl ;
22
26
const string expectedLocalUrl = "otherUrl" ;
23
27
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 ) ;
24
31
25
- var failureMessage = string . Format ( FailureMessages . CommonFailMessage , "LocalRedirectResult.LocalUrl" , expectedLocalUrl , actualLocalUrl ) ;
26
- Action a = ( ) => result . Should ( ) . BeLocalRedirectResult ( ) . WithLocalUrl ( expectedLocalUrl ) ;
27
32
a . Should ( ) . Throw < Exception > ( ) . WithMessage ( failureMessage ) ;
28
33
}
29
34
30
35
[ Fact ]
31
36
public void WithPermanent_GivenExpectedPermanent_ShouldPass ( )
32
37
{
33
38
var result = new TestController ( ) . LocalRedirectPermanent ( TestLocalUrl ) ;
39
+
34
40
result . Should ( ) . BeLocalRedirectResult ( ) . WithPermanent ( true ) ;
35
41
}
36
42
@@ -39,18 +45,19 @@ public void WithPermanent_GivenUnexpectedPermanent_ShouldFail()
39
45
{
40
46
var actualPermanent = true ;
41
47
var expectedPermanent = false ;
42
-
43
48
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 ) ;
44
52
45
- var failureMessage = $ "Expected LocalRedirectResult.Permanent to be { expectedPermanent } but was { actualPermanent } ";
46
- Action a = ( ) => result . Should ( ) . BeLocalRedirectResult ( ) . WithPermanent ( expectedPermanent ) ;
47
53
a . Should ( ) . Throw < Exception > ( ) . WithMessage ( failureMessage ) ;
48
54
}
49
55
50
56
[ Fact ]
51
57
public void WithPreserveMethod_GivenExpectedPreserveMethod_ShouldPass ( )
52
58
{
53
59
var result = new TestController ( ) . LocalRedirectPreserveMethod ( TestLocalUrl ) ;
60
+
54
61
result . Should ( ) . BeLocalRedirectResult ( ) . WithPreserveMethod ( true ) ;
55
62
}
56
63
@@ -59,18 +66,19 @@ public void WithPreserveMethod_GivenUnexpectedPreserveMethod_ShouldFail()
59
66
{
60
67
var actualPreserveMethod = true ;
61
68
var expectedPreserveMethod = false ;
62
-
63
69
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 ) ;
64
73
65
- var failureMessage = $ "Expected LocalRedirectResult.PreserveMethod to be { expectedPreserveMethod } but was { actualPreserveMethod } ";
66
- Action a = ( ) => result . Should ( ) . BeLocalRedirectResult ( ) . WithPreserveMethod ( expectedPreserveMethod ) ;
67
74
a . Should ( ) . Throw < Exception > ( ) . WithMessage ( failureMessage ) ;
68
75
}
69
76
70
77
[ Fact ]
71
78
public void WithPreserveMethod_GivenExpectedPermanentPreserveMethod_ShouldPass ( )
72
79
{
73
80
var result = new TestController ( ) . LocalRedirectPermanentPreserveMethod ( TestLocalUrl ) ;
81
+
74
82
result . Should ( ) . BeLocalRedirectResult ( ) . WithPermanent ( true ) . WithPreserveMethod ( true ) ;
75
83
}
76
84
}
0 commit comments