@@ -126,23 +126,24 @@ public void RedirectController_TopicRedirect_ReturnsRedirectResult() {
126126 /// <summary>
127127 /// Triggers the index action of the <see cref="SitemapController.Index()" /> action.
128128 /// </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>
134129 [ TestMethod ]
135- [ ExpectedException ( typeof ( NullReferenceException ) , AllowDerivedTypes = false ) ]
136130 public void SitemapController_Index_ReturnsSitemapXml ( ) {
137131
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 ;
141142
142143 controller . Dispose ( ) ;
143144
144145 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 \" ?>" ) ) ;
146147 Assert . IsTrue ( model . Contains ( "/Web/Web_1/Web_1_1/Web_1_1_1/</loc>" ) ) ;
147148
148149 }
0 commit comments