1 using Castle
.MicroKernel
.SubSystems
.Configuration
;
2 using Castle
.Core
.Resource
;
3 using Castle
.MVC
.Test
.Presentation
;
5 using Castle
.Windsor
.Configuration
.Interpreters
;
8 namespace Castle
.MVC
.Test
11 /// Summary description for Class1.
14 public class ControllerTest
16 private WindsorContainer _container
;
17 private HomeController _homeController
= null;
18 private MyApplicationState _state
= null;
20 #region SetUp & TearDown
29 _homeController
= null;
33 // _container = new WindsorContainer( new XmlInterpreter( new AppDomainConfigSource("castle")),
34 // new XmlInterpreter( "test.config" )
37 DefaultConfigurationStore store
= new DefaultConfigurationStore();
38 XmlInterpreter interpreter
= new XmlInterpreter(new ConfigResource());
39 interpreter
.ProcessResource(interpreter
.Source
, store
);
41 _container
= new WindsorContainer( interpreter
);
43 //-- Config by Code for test
44 // _container = new WindsorContainer(new DefaultConfigurationStore());
46 // MutableConfiguration confignode = new MutableConfiguration("facility");
48 // IConfiguration assembyView = confignode.Children.Add(new MutableConfiguration("assembyView"));
50 // _container.Kernel.ConfigurationStore.AddFacilityConfiguration("MVCFacility", confignode);
51 // _container.AddFacility("MVCFacility", new MVCFacility());
53 // _container.AddComponent( "state", typeof(IState),typeof(MyApplicationState));
54 // _container.AddComponent( "navigator", typeof(INavigator), typeof(DefaultNavigator));
55 // _container.AddComponent( "viewManager", typeof(IViewManager), typeof(MockViewManager));
56 // _container.AddComponent( "statePersister", typeof(IStatePersister), typeof(MemoryStatePersister));
59 // _container.AddComponent( "HomeController", typeof(HomeController) );
60 // _container.AddComponent( "AccountController", typeof(AccountController) );
63 // _container.AddComponent( "ServiceA", typeof(IServiceA), typeof(ServiceA));
66 _homeController
= _container
["HomeController"] as HomeController
;
67 _state
= _homeController
.State
as MyApplicationState
;
82 #region Test Controller
88 public void TestContainer()
90 object controller
= _container
["HomeController"];
91 Assert
.IsTrue(controller
.GetType()==typeof(HomeController
));
92 controller
= _container
["AccountController"];
93 Assert
.IsTrue(controller
.GetType()==typeof(AccountController
));
95 IServiceA serviceA
= _container
[typeof(IServiceA
)] as IServiceA
;
96 serviceA
.MyMethodNotcached("Gilles");
101 /// Test loading Embeded Resource
104 public void TestController()
106 _state
.CurrentView
= "index";
107 _state
.Command
= "GoToPage2";
108 _homeController
.Login("email", "pass");
110 Assert
.IsTrue(_state
.PreviousView
=="index");
111 Assert
.IsTrue(_state
.CurrentView
=="page2");
115 /// Test custom state
118 public void TestState()
120 _state
.CurrentView
= "index";
121 _state
.Command
= "GoToPage2";
122 _state
.SomeSessionString
= "toto";
123 _homeController
.Login("email", "pass");
125 Assert
.IsTrue(_state
.SomeSessionString
=="toto");