@@ -70,6 +70,8 @@ public void WithRouteValue_GivenExpected_ShouldPass()
7070 [ Test ]
7171 public void WithRouteValue_GivenUnexpected_ShouldFail ( )
7272 {
73+ var subjectIdentifier = GetSubjectIdentifier ( ) ;
74+
7375 ActionResult result = new RedirectToRouteResult ( "" , new RouteValueDictionary (
7476 new
7577 {
@@ -80,7 +82,7 @@ public void WithRouteValue_GivenUnexpected_ShouldFail()
8082 . BeRedirectToRouteResult ( )
8183 . WithRouteValue ( "Id" , "11" ) ;
8284 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\" .") ;
8486 }
8587
8688 [ Test ]
@@ -100,6 +102,8 @@ public void WithController_GivenExpected_ShouldPass()
100102 [ Test ]
101103 public void WithController_GivenUnexpected_ShouldFail ( )
102104 {
105+ var subjectIdentifier = GetSubjectIdentifier ( ) ;
106+
103107 ActionResult result = new RedirectToRouteResult ( "" , new RouteValueDictionary (
104108 new
105109 {
@@ -110,7 +114,7 @@ public void WithController_GivenUnexpected_ShouldFail()
110114 . BeRedirectToRouteResult ( )
111115 . WithController ( "xyz" ) ;
112116 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\" .") ;
114118 }
115119
116120 [ Test ]
@@ -130,6 +134,8 @@ public void WithAction_GivenExpected_ShouldPass()
130134 [ Test ]
131135 public void WithAction_GivenUnexpected_ShouldFail ( )
132136 {
137+ var subjectIdentifier = GetSubjectIdentifier ( ) ;
138+
133139 ActionResult result = new RedirectToRouteResult ( "" , new RouteValueDictionary (
134140 new
135141 {
@@ -140,7 +146,7 @@ public void WithAction_GivenUnexpected_ShouldFail()
140146 . BeRedirectToRouteResult ( )
141147 . WithAction ( "xyz" ) ;
142148 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\" .") ;
144150 }
145151
146152 [ Test ]
@@ -160,6 +166,8 @@ public void WithArea_GivenExpected_ShouldPass()
160166 [ Test ]
161167 public void WithArea_GivenUnexpected_ShouldFail ( )
162168 {
169+ var subjectIdentifier = GetSubjectIdentifier ( ) ;
170+
163171 ActionResult result = new RedirectToRouteResult ( "" , new RouteValueDictionary (
164172 new
165173 {
@@ -170,7 +178,29 @@ public void WithArea_GivenUnexpected_ShouldFail()
170178 . BeRedirectToRouteResult ( )
171179 . WithArea ( "xyz" ) ;
172180 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 ;
174202 }
203+
204+
175205 }
176206}
0 commit comments