@@ -126,23 +126,24 @@ public void RedirectController_TopicRedirect_ReturnsRedirectResult() {
126
126
/// <summary>
127
127
/// Triggers the index action of the <see cref="SitemapController.Index()" /> action.
128
128
/// </summary>
129
- /// <remarks>
130
- /// Because the <see cref="SitemapController.Index()"/> method references the <see cref="Controller.Response"/> property,
131
- /// which is not set during unit testing, this test is <i>expected</i> to throw an exception. This is not ideal. In the
132
- /// future, this may be modified to instead use a mock <see cref="ControllerContext"/> for a more sophisticated test.
133
- /// </remarks>
134
129
[ TestMethod ]
135
- [ ExpectedException ( typeof ( NullReferenceException ) , AllowDerivedTypes = false ) ]
136
130
public void SitemapController_Index_ReturnsSitemapXml ( ) {
137
131
138
- var controller = new SitemapController ( _topicRepository ) ;
139
- var result = controller . Index ( ) as ViewResult ;
140
- var model = result . Model as string ;
132
+ var actionContext = new ActionContext {
133
+ HttpContext = new DefaultHttpContext ( ) ,
134
+ RouteData = new RouteData ( ) ,
135
+ ActionDescriptor = new ControllerActionDescriptor ( )
136
+ } ;
137
+ var controller = new SitemapController ( _topicRepository ) {
138
+ ControllerContext = new ControllerContext ( actionContext )
139
+ } ;
140
+ var result = controller . Index ( ) as ContentResult ;
141
+ var model = result . Content as string ;
141
142
142
143
controller . Dispose ( ) ;
143
144
144
145
Assert . IsNotNull ( model ) ;
145
- Assert . IsTrue ( model . StartsWith ( "<?xml version=\" 1.0\" encoding=\" utf-16 \" ?>" ) ) ;
146
+ Assert . IsTrue ( model . StartsWith ( "<?xml version=\" 1.0\" encoding=\" utf-8 \" standalone= \" no \" ?>" ) ) ;
146
147
Assert . IsTrue ( model . Contains ( "/Web/Web_1/Web_1_1/Web_1_1_1/</loc>" ) ) ;
147
148
148
149
}
0 commit comments