Fixing an issue with output parameters that are of type IntPtr
[castle.git] / Experiments / Attic / MVC / Castle.MVC.Test / ControllerTest.cs
blob7059af0f35be38c5cef82b05c8e08fdfb57ac6fe
1 using Castle.MicroKernel.SubSystems.Configuration;
2 using Castle.Core.Resource;
3 using Castle.MVC.Test.Presentation;
4 using Castle.Windsor;
5 using Castle.Windsor.Configuration.Interpreters;
6 using NUnit.Framework;
8 namespace Castle.MVC.Test
10 /// <summary>
11 /// Summary description for Class1.
12 /// </summary>
13 [TestFixture]
14 public class ControllerTest
16 private WindsorContainer _container;
17 private HomeController _homeController = null;
18 private MyApplicationState _state = null;
20 #region SetUp & TearDown
22 /// <summary>
23 /// SetUp
24 /// </summary>
25 [SetUp]
26 public void SetUp()
28 _container = null;
29 _homeController = null;
30 _state = null;
32 // Config by file
33 // _container = new WindsorContainer( new XmlInterpreter( new AppDomainConfigSource("castle")),
34 // new XmlInterpreter( "test.config" )
35 // );
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));
58 // // controllers
59 // _container.AddComponent( "HomeController", typeof(HomeController) );
60 // _container.AddComponent( "AccountController", typeof(AccountController) );
62 // // components
63 // _container.AddComponent( "ServiceA", typeof(IServiceA), typeof(ServiceA));
66 _homeController = _container["HomeController"] as HomeController;
67 _state = _homeController.State as MyApplicationState;
71 /// <summary>
72 /// TearDown
73 /// </summary>
74 [TearDown]
75 public void Dispose()
77 _container.Dispose();
80 #endregion
82 #region Test Controller
84 /// <summary>
85 /// Test Container
86 /// </summary>
87 [Test]
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");
100 /// <summary>
101 /// Test loading Embeded Resource
102 /// </summary>
103 [Test]
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");
114 /// <summary>
115 /// Test custom state
116 /// </summary>
117 [Test]
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");
128 #endregion