Fixing an issue with output parameters that are of type IntPtr
[castle.git] / MonoRail / Castle.MonoRail.Framework / Test / MockServices.cs
blob95f8862f084bc1f9173e5421da6ec58128a260e9
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.MonoRail.Framework.Test
17 using System;
18 using System.Collections.Generic;
19 using System.ComponentModel.Design;
20 using Castle.Components.Common.EmailSender;
21 using Castle.Components.Validator;
22 using Providers;
23 using Resources;
24 using Services;
26 /// <summary>
27 /// Pendent
28 /// </summary>
29 public class MockServices : IMonoRailServices, IServiceContainer
31 private IUrlTokenizer urlTokenizer;
32 private IUrlBuilder urlBuilder;
33 private ICacheProvider cacheProvider;
34 private IEngineContextFactory engineContextFactory;
35 private IControllerFactory controllerFactory;
36 private IControllerContextFactory controllerContextFactory;
37 private IControllerTree controllerTree;
38 private IViewSourceLoader viewSourceLoader;
39 private IFilterFactory filterFactory;
40 private IControllerDescriptorProvider controllerDescriptorProvider;
41 private IViewEngineManager viewEngineManager;
42 private IValidatorRegistry validatorRegistry;
43 private IActionSelector actionSelector;
44 private IScaffoldingSupport scaffoldSupport;
45 private IJSONSerializer jsonSerializer;
46 private IStaticResourceRegistry staticResourceRegistry;
47 private IEmailTemplateService emailTemplateService;
48 private IEmailSender emailSender;
49 private IResourceFactory resourceFactory;
50 private ExtensionManager extensionManager;
51 private readonly Dictionary<Type, object> service2Impl = new Dictionary<Type, object>();
52 private IServiceInitializer serviceInitializer;
53 private IHelperFactory helperFactory;
55 /// <summary>
56 /// Initializes a new instance of the <see cref="MockServices"/> class with default mock services.
57 /// </summary>
58 public MockServices() : this(new DefaultUrlBuilder(new MockServerUtility(), new MockRoutingEngine()),
59 new DefaultFilterFactory(),
60 new ViewEngineManagerStub(),
61 new DefaultActionSelector())
65 /// <summary>
66 /// Initializes a new instance of the <see cref="MockServices"/> class.
67 /// </summary>
68 /// <param name="urlBuilder">The URL builder.</param>
69 /// <param name="filterFactory">The filter factory.</param>
70 /// <param name="viewEngineManager">The view engine manager.</param>
71 /// <param name="actionSelector">The action selector.</param>
72 public MockServices(IUrlBuilder urlBuilder, IFilterFactory filterFactory, IViewEngineManager viewEngineManager,
73 IActionSelector actionSelector)
75 this.urlBuilder = urlBuilder;
76 this.filterFactory = filterFactory;
77 this.viewEngineManager = viewEngineManager;
78 this.actionSelector = actionSelector;
80 controllerTree = new DefaultControllerTree();
81 controllerFactory = new DefaultControllerFactory(controllerTree);
82 staticResourceRegistry = new DefaultStaticResourceRegistry();
84 controllerContextFactory = new DefaultControllerContextFactory();
86 controllerDescriptorProvider = new DefaultControllerDescriptorProvider(
87 new DefaultHelperDescriptorProvider(),
88 new DefaultFilterDescriptorProvider(),
89 new DefaultLayoutDescriptorProvider(),
90 new DefaultRescueDescriptorProvider(),
91 new DefaultResourceDescriptorProvider(),
92 new DefaultTransformFilterDescriptorProvider(),
93 new DefaultReturnBinderDescriptorProvider());
95 resourceFactory = new DefaultResourceFactory();
96 scaffoldSupport = new MockScaffoldingSupport();
97 cacheProvider = new MockCacheProvider();
98 helperFactory = new DefaultHelperFactory();
99 serviceInitializer = new DefaultServiceInitializer();
101 extensionManager = new ExtensionManager(this);
103 validatorRegistry = new CachedValidationRegistry();
105 jsonSerializer = new NewtonsoftJSONSerializer();
108 #region IServiceContainer
110 /// <summary>
111 /// Adds the specified service to the service container.
112 /// </summary>
113 /// <param name="serviceType">The type of service to add.</param>
114 /// <param name="serviceInstance">An instance of the service type to add. This object must implement or inherit from the type indicated by the <paramref name="serviceType"/> parameter.</param>
115 public void AddService(Type serviceType, object serviceInstance)
117 service2Impl[serviceType] = serviceInstance;
120 /// <summary>
121 /// Adds the specified service to the service container, and optionally promotes the service to any parent service containers.
122 /// </summary>
123 /// <param name="serviceType">The type of service to add.</param>
124 /// <param name="serviceInstance">An instance of the service type to add. This object must implement or inherit from the type indicated by the <paramref name="serviceType"/> parameter.</param>
125 /// <param name="promote">true to promote this request to any parent service containers; otherwise, false.</param>
126 public void AddService(Type serviceType, object serviceInstance, bool promote)
128 throw new NotImplementedException();
131 /// <summary>
132 /// Adds the specified service to the service container.
133 /// </summary>
134 /// <param name="serviceType">The type of service to add.</param>
135 /// <param name="callback">A callback object that is used to create the service. This allows a service to be declared as available, but delays the creation of the object until the service is requested.</param>
136 public void AddService(Type serviceType, ServiceCreatorCallback callback)
138 throw new NotImplementedException();
141 /// <summary>
142 /// Adds the specified service to the service container, and optionally promotes the service to parent service containers.
143 /// </summary>
144 /// <param name="serviceType">The type of service to add.</param>
145 /// <param name="callback">A callback object that is used to create the service. This allows a service to be declared as available, but delays the creation of the object until the service is requested.</param>
146 /// <param name="promote">true to promote this request to any parent service containers; otherwise, false.</param>
147 public void AddService(Type serviceType, ServiceCreatorCallback callback, bool promote)
149 throw new NotImplementedException();
152 /// <summary>
153 /// Removes the specified service type from the service container.
154 /// </summary>
155 /// <param name="serviceType">The type of service to remove.</param>
156 public void RemoveService(Type serviceType)
158 throw new NotImplementedException();
161 /// <summary>
162 /// Removes the specified service type from the service container, and optionally promotes the service to parent service containers.
163 /// </summary>
164 /// <param name="serviceType">The type of service to remove.</param>
165 /// <param name="promote">true to promote this request to any parent service containers; otherwise, false.</param>
166 public void RemoveService(Type serviceType, bool promote)
168 throw new NotImplementedException();
171 #endregion
173 /// <summary>
174 /// Gets or sets the URL tokenizer.
175 /// </summary>
176 /// <value>The URL tokenizer.</value>
177 public IUrlTokenizer UrlTokenizer
179 get { return urlTokenizer; }
180 set { urlTokenizer = value; }
183 /// <summary>
184 /// Gets or sets the URL builder.
185 /// </summary>
186 /// <value>The URL builder.</value>
187 public IUrlBuilder UrlBuilder
189 get { return urlBuilder; }
190 set { urlBuilder = value; }
193 /// <summary>
194 /// Gets or sets the cache provider.
195 /// </summary>
196 /// <value>The cache provider.</value>
197 public ICacheProvider CacheProvider
199 get { return cacheProvider; }
200 set { cacheProvider = value; }
203 /// <summary>
204 /// Gets or sets the engine context factory.
205 /// </summary>
206 /// <value>The engine context factory.</value>
207 public IEngineContextFactory EngineContextFactory
209 get { return engineContextFactory; }
210 set { engineContextFactory = value; }
213 /// <summary>
214 /// Gets or sets the controller factory.
215 /// </summary>
216 /// <value>The controller factory.</value>
217 public IControllerFactory ControllerFactory
219 get { return controllerFactory; }
220 set { controllerFactory = value; }
223 /// <summary>
224 /// Gets or sets the controller context factory.
225 /// </summary>
226 /// <value>The controller context factory.</value>
227 public IControllerContextFactory ControllerContextFactory
229 get { return controllerContextFactory; }
230 set { controllerContextFactory = value; }
233 /// <summary>
234 /// Gets or sets the controller tree.
235 /// </summary>
236 /// <value>The controller tree.</value>
237 public IControllerTree ControllerTree
239 get { return controllerTree; }
240 set { controllerTree = value; }
243 /// <summary>
244 /// Gets or sets the view source loader.
245 /// </summary>
246 /// <value>The view source loader.</value>
247 public IViewSourceLoader ViewSourceLoader
249 get { return viewSourceLoader; }
250 set { viewSourceLoader = value; }
253 /// <summary>
254 /// Gets or sets the filter factory.
255 /// </summary>
256 /// <value>The filter factory.</value>
257 public IFilterFactory FilterFactory
259 get { return filterFactory; }
260 set { filterFactory = value; }
263 /// <summary>
264 /// Gets or sets the controller descriptor provider.
265 /// </summary>
266 /// <value>The controller descriptor provider.</value>
267 public IControllerDescriptorProvider ControllerDescriptorProvider
269 get { return controllerDescriptorProvider; }
270 set { controllerDescriptorProvider = value; }
273 /// <summary>
274 /// Gets or sets the view engine manager.
275 /// </summary>
276 /// <value>The view engine manager.</value>
277 public IViewEngineManager ViewEngineManager
279 get { return viewEngineManager; }
280 set { viewEngineManager = value; }
283 /// <summary>
284 /// Gets or sets the validator registry.
285 /// </summary>
286 /// <value>The validator registry.</value>
287 public IValidatorRegistry ValidatorRegistry
289 get { return validatorRegistry; }
290 set { validatorRegistry = value; }
293 /// <summary>
294 /// Gets or sets the action selector.
295 /// </summary>
296 /// <value>The action selector.</value>
297 public IActionSelector ActionSelector
299 get { return actionSelector; }
300 set { actionSelector = value; }
303 /// <summary>
304 /// Gets or sets the scaffold support.
305 /// </summary>
306 /// <value>The scaffold support.</value>
307 public IScaffoldingSupport ScaffoldSupport
309 get { return scaffoldSupport; }
310 set { scaffoldSupport = value; }
313 /// <summary>
314 /// Gets or sets the JSON serializer.
315 /// </summary>
316 /// <value>The JSON serializer.</value>
317 public IJSONSerializer JSONSerializer
319 get { return jsonSerializer; }
320 set { jsonSerializer = value; }
323 /// <summary>
324 /// Gets or sets the static resource registry service.
325 /// </summary>
326 /// <value>The static resource registry.</value>
327 public IStaticResourceRegistry StaticResourceRegistry
329 get { return staticResourceRegistry; }
330 set { staticResourceRegistry = value; }
333 /// <summary>
334 /// Gets or sets the email template service.
335 /// </summary>
336 /// <value>The email template service.</value>
337 public IEmailTemplateService EmailTemplateService
339 get { return emailTemplateService; }
340 set { emailTemplateService = value; }
343 /// <summary>
344 /// Gets or sets the email sender.
345 /// </summary>
346 /// <value>The email sender.</value>
347 public IEmailSender EmailSender
349 get { return emailSender; }
350 set { emailSender = value; }
353 /// <summary>
354 /// Gets or sets the resource factory.
355 /// </summary>
356 /// <value>The resource factory.</value>
357 public IResourceFactory ResourceFactory
359 get { return resourceFactory; }
360 set { resourceFactory = value; }
363 /// <summary>
364 /// Gets or sets the service initializer.
365 /// </summary>
366 /// <value>The service initializer.</value>
367 public IServiceInitializer ServiceInitializer
369 get { return serviceInitializer; }
370 set { serviceInitializer = value; }
373 /// <summary>
374 /// Gets or sets the helper factory.
375 /// </summary>
376 /// <value>The helper factory.</value>
377 public IHelperFactory HelperFactory
379 get { return helperFactory; }
380 set { helperFactory = value; }
383 /// <summary>
384 /// Gets or sets the extension manager.
385 /// </summary>
386 /// <value>The extension manager.</value>
387 public ExtensionManager ExtensionManager
389 get { return extensionManager; }
390 set { extensionManager = value; }
393 /// <summary>
394 /// Gets the service.
395 /// </summary>
396 /// <typeparam name="T"></typeparam>
397 /// <returns></returns>
398 public T GetService<T>() where T : class
400 return (T) service2Impl[typeof(T)];
403 /// <summary>
404 /// Gets the service object of the specified type.
405 /// </summary>
406 /// <param name="serviceType">An object that specifies the type of service object to get.</param>
407 /// <returns>
408 /// A service object of type <paramref name="serviceType"/>.-or- null if there is no service object of type <paramref name="serviceType"/>.
409 /// </returns>
410 public object GetService(Type serviceType)
412 object value;
413 service2Impl.TryGetValue(serviceType, out value);
414 return value;