1 using Castle
.Igloo
.Mock
;
2 using Castle
.Igloo
.Scopes
.Web
;
3 using Castle
.MicroKernel
.SubSystems
.Configuration
;
4 using Castle
.Core
.Resource
;
6 using Castle
.Windsor
.Configuration
.Interpreters
;
7 using Igloo
.Clinic
.Domain
;
10 using Igloo
.Clinic
.Application
;
12 using Castle
.Igloo
.Controllers
;
14 using Castle
.Igloo
.Navigation
;
16 namespace Igloo
.Clinic
.Test
19 /// Summary description for Class1.
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
36 public void FixtureSetUp()
40 DefaultConfigurationStore store
= new DefaultConfigurationStore();
41 XmlInterpreter interpreter
= new XmlInterpreter(new ConfigResource());
42 interpreter
.ProcessResource(interpreter
.Source
, store
);
44 _container
= new WindsorContainer( interpreter
);
51 public void FixtureTearDown()
62 _sessionScope
= _container
.Resolve
<ISessionScope
>();
63 _pageScope
= _container
.Resolve
<IPageScope
>();
64 _requestScope
= _container
.Resolve
<IRequestScope
>();
71 public void TearDown()
73 _requestScope
.Flush();
75 _sessionScope
.Flush();
80 #region Test Controller
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
);
96 /// Test loading Embeded Resource
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
);
117 /// Test session context
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
);
141 /// Test session context
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
);