Added ability to order the execution of dictionary adapter behaviors.
[castle.git] / Experiments / Castle.Igloo / Igloo.Clinic.Test / ControllerTest.cs
blob9d1f8e3d36bf5a5cf68a6ec20fe4ccbe9d84c28d
1 using Castle.Igloo.Mock;
2 using Castle.Igloo.Scopes.Web;
3 using Castle.MicroKernel.SubSystems.Configuration;
4 using Castle.Core.Resource;
5 using Castle.Windsor;
6 using Castle.Windsor.Configuration.Interpreters;
7 using Igloo.Clinic.Domain;
8 using NUnit.Framework;
10 using Igloo.Clinic.Application;
12 using Castle.Igloo.Controllers;
13 using Castle.Igloo;
14 using Castle.Igloo.Navigation;
16 namespace Igloo.Clinic.Test
18 /// <summary>
19 /// Summary description for Class1.
20 /// </summary>
21 [TestFixture]
22 public class ControllerTest
24 private WindsorContainer _container;
26 private IRequestScope _requestScope = null;
27 private ISessionScope _sessionScope = null;
28 private IPageScope _pageScope = null;
30 #region SetUp & TearDown
32 /// <summary>
33 /// SetUp
34 /// </summary>
35 [TestFixtureSetUp]
36 public void FixtureSetUp()
38 _container = null;
40 DefaultConfigurationStore store = new DefaultConfigurationStore();
41 XmlInterpreter interpreter = new XmlInterpreter(new ConfigResource());
42 interpreter.ProcessResource(interpreter.Source, store);
44 _container = new WindsorContainer( interpreter );
47 /// <summary>
48 /// TearDown
49 /// </summary>
50 [TestFixtureTearDown]
51 public void FixtureTearDown()
53 _container.Dispose();
56 /// <summary>
57 /// SetUp
58 /// </summary>
59 [SetUp]
60 public void SetUp()
62 _sessionScope = _container.Resolve<ISessionScope>();
63 _pageScope = _container.Resolve<IPageScope>();
64 _requestScope = _container.Resolve<IRequestScope>();
67 /// <summary>
68 /// TearDown
69 /// </summary>
70 [TearDown]
71 public void TearDown()
73 _requestScope.Flush();
74 _pageScope.Flush();
75 _sessionScope.Flush();
78 #endregion
80 #region Test Controller
82 /// <summary>
83 /// Test Container
84 /// </summary>
85 [Test]
86 public void TestContainer()
88 IController controller = _container.Resolve<IController>("Login.Controller");
89 Assert.IsNotNull(controller);
91 controller = _container.Resolve<IController>("Patient.Controller");
92 Assert.IsNotNull(controller);
95 /// <summary>
96 /// Test loading Embeded Resource
97 /// </summary>
98 [Test]
99 public void TestNavigation()
101 LoginController controller = _container.Resolve<LoginController>();
103 Assert.IsNotNull(controller);
104 Assert.IsNotNull(controller.NavigationState);
106 controller.NavigationState.CurrentView = "login";
107 controller.NavigationState.Action = "login";
109 controller.Validate("no", "xxxx");
111 Assert.AreEqual("login", controller.NavigationState.PreviousView);
112 Assert.AreEqual("login", controller.NavigationState.CurrentView);
113 Assert.AreEqual("index", controller.NavigationState.NextView);
116 /// <summary>
117 /// Test session context
118 /// </summary>
119 [Test]
120 public void TestSessionContext_Login()
122 LoginController controller = _container.Resolve<LoginController>();
124 Assert.IsNotNull(controller);
126 controller.NavigationState.CurrentView = "login";
127 controller.NavigationState.Action = "login";
129 Assert.IsTrue(controller.Validate("no", "xxxx"));
131 Assert.IsTrue(_sessionScope.Contains("doctor"));
132 object doctor = _sessionScope["doctor"];
133 Assert.IsNotNull(doctor);
135 Assert.IsInstanceOfType(typeof(Doctor), doctor);
136 Doctor doc = (Doctor)doctor;
137 Assert.AreEqual("NO", doc.Name);
140 /// <summary>
141 /// Test session context
142 /// </summary>
143 [Test]
144 public void TestSessionContext_NoLogin()
146 LoginController controller = _container.Resolve<LoginController>();
148 Assert.IsNotNull(controller);
150 controller.NavigationState.CurrentView = "login";
151 controller.NavigationState.Action = "login";
153 Assert.IsFalse(controller.Validate("Ali Baba and the Forty Thieves", "xxxx"));
155 Assert.IsFalse(_sessionScope.Contains("doctor"));
157 FlashMessages messages = _requestScope[FlashMessages.FLASH_MESSAGES] as FlashMessages;
159 Assert.IsTrue(messages.ContainsKey("unknown"));
161 Assert.AreEqual("login", controller.NavigationState.PreviousView);
162 Assert.AreEqual("login", controller.NavigationState.CurrentView);
163 Assert.AreEqual("login", controller.NavigationState.NextView);
167 #endregion