@@ -70,6 +70,8 @@ public void WithRouteValue_GivenExpected_ShouldPass()
70
70
[ Test ]
71
71
public void WithRouteValue_GivenUnexpected_ShouldFail ( )
72
72
{
73
+ var subjectIdentifier = GetSubjectIdentifier ( ) ;
74
+
73
75
ActionResult result = new RedirectToRouteResult ( "" , new RouteValueDictionary (
74
76
new
75
77
{
@@ -80,7 +82,7 @@ public void WithRouteValue_GivenUnexpected_ShouldFail()
80
82
. BeRedirectToRouteResult ( )
81
83
. WithRouteValue ( "Id" , "11" ) ;
82
84
a . Should ( ) . Throw < Exception > ( )
83
- . WithMessage ( "Expected Subject.RouteValues to contain value \" 11\" at key \" Id\" , but found \" 22\" ." ) ;
85
+ . WithMessage ( $ "Expected { subjectIdentifier } to contain value \" 11\" at key \" Id\" , but found \" 22\" .") ;
84
86
}
85
87
86
88
[ Test ]
@@ -100,6 +102,8 @@ public void WithController_GivenExpected_ShouldPass()
100
102
[ Test ]
101
103
public void WithController_GivenUnexpected_ShouldFail ( )
102
104
{
105
+ var subjectIdentifier = GetSubjectIdentifier ( ) ;
106
+
103
107
ActionResult result = new RedirectToRouteResult ( "" , new RouteValueDictionary (
104
108
new
105
109
{
@@ -110,7 +114,7 @@ public void WithController_GivenUnexpected_ShouldFail()
110
114
. BeRedirectToRouteResult ( )
111
115
. WithController ( "xyz" ) ;
112
116
a . Should ( ) . Throw < Exception > ( )
113
- . WithMessage ( "Expected Subject.RouteValues to contain value \" xyz\" at key \" Controller\" , but found \" home\" ." ) ;
117
+ . WithMessage ( $ "Expected { subjectIdentifier } to contain value \" xyz\" at key \" Controller\" , but found \" home\" .") ;
114
118
}
115
119
116
120
[ Test ]
@@ -130,6 +134,8 @@ public void WithAction_GivenExpected_ShouldPass()
130
134
[ Test ]
131
135
public void WithAction_GivenUnexpected_ShouldFail ( )
132
136
{
137
+ var subjectIdentifier = GetSubjectIdentifier ( ) ;
138
+
133
139
ActionResult result = new RedirectToRouteResult ( "" , new RouteValueDictionary (
134
140
new
135
141
{
@@ -140,7 +146,7 @@ public void WithAction_GivenUnexpected_ShouldFail()
140
146
. BeRedirectToRouteResult ( )
141
147
. WithAction ( "xyz" ) ;
142
148
a . Should ( ) . Throw < Exception > ( )
143
- . WithMessage ( "Expected Subject.RouteValues to contain value \" xyz\" at key \" Action\" , but found \" index\" ." ) ;
149
+ . WithMessage ( $ "Expected { subjectIdentifier } to contain value \" xyz\" at key \" Action\" , but found \" index\" .") ;
144
150
}
145
151
146
152
[ Test ]
@@ -160,6 +166,8 @@ public void WithArea_GivenExpected_ShouldPass()
160
166
[ Test ]
161
167
public void WithArea_GivenUnexpected_ShouldFail ( )
162
168
{
169
+ var subjectIdentifier = GetSubjectIdentifier ( ) ;
170
+
163
171
ActionResult result = new RedirectToRouteResult ( "" , new RouteValueDictionary (
164
172
new
165
173
{
@@ -170,7 +178,29 @@ public void WithArea_GivenUnexpected_ShouldFail()
170
178
. BeRedirectToRouteResult ( )
171
179
. WithArea ( "xyz" ) ;
172
180
a . Should ( ) . Throw < Exception > ( )
173
- . WithMessage ( "Expected Subject.RouteValues to contain value \" xyz\" at key \" Area\" , but found \" accounts\" ." ) ;
181
+ . WithMessage ( $ "Expected { subjectIdentifier } to contain value \" xyz\" at key \" Area\" , but found \" accounts\" .") ;
182
+ }
183
+
184
+ /// <summary>
185
+ /// Gets the expected subject identifier for the failure message
186
+ /// </summary>
187
+ /// <remarks>
188
+ /// The Fluent Assertions library will attempt to determine the name of the subject from the stack trace.
189
+ /// This requires the Unit Tests to be compiled in DEBUG mode in order for it to work successfully.
190
+ /// If it cannot determne the Subject's Identity, it will fall back to a generic value.
191
+ /// This method is an attempt to cope with the different build configurations
192
+ /// ref: http://fluentassertions.com/documentation.html#subject-identification
193
+ /// </remarks>
194
+ /// <returns></returns>
195
+ private static string GetSubjectIdentifier ( )
196
+ {
197
+ var subjectIdentifier = "dictionary" ;
198
+ #if DEBUG
199
+ subjectIdentifier = "Subject.RouteValues" ;
200
+ #endif
201
+ return subjectIdentifier ;
174
202
}
203
+
204
+
175
205
}
176
206
}
0 commit comments