@@ -34,6 +34,9 @@ public class TopicControllerTest {
3434 | PRIVATE VARIABLES
3535 \-------------------------------------------------------------------------------------------------------------------------*/
3636 ITopicRepository _topicRepository = null ;
37+ RouteData _routeData = new RouteData ( ) ;
38+ Uri _uri = new Uri ( "http://localhost/Web/Web_0/Web_0_1/Web_0_1_1" ) ;
39+ Topic _topic = null ;
3740
3841 /*==========================================================================================================================
3942 | CONSTRUCTOR
@@ -45,10 +48,12 @@ public class TopicControllerTest {
4548 /// This uses the <see cref="FakeTopicRepository"/> to provide data, and then <see cref="CachedTopicRepository"/> to
4649 /// manage the in-memory representation of the data. While this introduces some overhead to the tests, the latter is a
4750 /// relatively lightweight façade to any <see cref="ITopicRepository"/>, and prevents the need to duplicate logic for
48- /// crawling the object graph.
51+ /// crawling the object graph. In addition, it initializes a shared <see cref="Topic"/> reference to use for the various
52+ /// tests.
4953 /// </remarks>
5054 public TopicControllerTest ( ) {
51- _topicRepository = new CachedTopicRepository ( new FakeTopicRepository ( ) ) ;
55+ _topicRepository = new CachedTopicRepository ( new FakeTopicRepository ( ) ) ;
56+ _topic = _topicRepository . Load ( "Root:Web:Web_0:Web_0_1:Web_0_1_1" ) ;
5257 }
5358
5459 /*==========================================================================================================================
@@ -60,15 +65,11 @@ public TopicControllerTest() {
6065 [ TestMethod ]
6166 public async Task TopicController_IndexTestAsync ( ) {
6267
63- var routes = new RouteData ( ) ;
64- var uri = new Uri ( "http://localhost/Web/Web_0/Web_0_1/Web_0_1_1" ) ;
65- var topic = _topicRepository . Load ( "Root:Web:Web_0:Web_0_1:Web_0_1_1" ) ;
66-
67- var topicRoutingService = new MvcTopicRoutingService ( _topicRepository , uri , routes ) ;
68+ var topicRoutingService = new MvcTopicRoutingService ( _topicRepository , _uri , _routeData ) ;
6869 var mappingService = new TopicMappingService ( _topicRepository , new FakeViewModelLookupService ( ) ) ;
6970
7071 var controller = new TopicController ( _topicRepository , topicRoutingService , mappingService ) ;
71- var result = await controller . IndexAsync ( topic . GetWebPath ( ) ) as TopicViewResult ;
72+ var result = await controller . IndexAsync ( _topic . GetWebPath ( ) ) as TopicViewResult ;
7273 var model = result . Model as PageTopicViewModel ;
7374
7475 Assert . IsNotNull ( model ) ;
@@ -201,22 +202,18 @@ public void SitemapController_IndexTest() {
201202 [ TestMethod ]
202203 public async Task LayoutController_MenuTest ( ) {
203204
204- var routes = new RouteData ( ) ;
205- var uri = new Uri ( "http://localhost/Web/Web_0/Web_0_1/Web_0_1_1" ) ;
206- var topic = _topicRepository . Load ( "Root:Web:Web_0:Web_0_1:Web_0_1_1" ) ;
207-
208- var topicRoutingService = new MvcTopicRoutingService ( _topicRepository , uri , routes ) ;
205+ var topicRoutingService = new MvcTopicRoutingService ( _topicRepository , _uri , _routeData ) ;
209206 var mappingService = new TopicMappingService ( _topicRepository , new FakeViewModelLookupService ( ) ) ;
210207
211208 var controller = new LayoutController ( _topicRepository , topicRoutingService , mappingService ) ;
212209 var result = await controller . Menu ( ) as PartialViewResult ;
213210 var model = result . Model as NavigationViewModel < NavigationTopicViewModel > ;
214211
215212 Assert . IsNotNull ( model ) ;
216- Assert . AreEqual < string > ( topic . GetUniqueKey ( ) , model . CurrentKey ) ;
213+ Assert . AreEqual < string > ( _topic . GetUniqueKey ( ) , model . CurrentKey ) ;
217214 Assert . AreEqual < string > ( "Root:Web" , model . NavigationRoot . UniqueKey ) ;
218- Assert . AreEqual < int > ( 3 , model . NavigationRoot . Children . Count ( ) ) ;
219- Assert . IsTrue ( model . NavigationRoot . IsSelected ( topic . GetUniqueKey ( ) ) ) ;
215+ Assert . AreEqual < int > ( 2 , model . NavigationRoot . Children . Count ( ) ) ;
216+ Assert . IsTrue ( model . NavigationRoot . IsSelected ( _topic . GetUniqueKey ( ) ) ) ;
220217
221218 }
222219
0 commit comments