1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
.Collections
;
18 using Castle
.Components
.Common
.EmailSender
;
22 /// Mocks the <see cref="IEmailTemplateService"/> calling
23 /// <see cref="MockEngineContext.AddMailTemplateRendered"/> to register
24 /// the calls made to these methods
26 public class MockEmailTemplateService
: IEmailTemplateService
28 private readonly MockEngineContext context
;
31 /// Initializes a new instance of the <see cref="MockEmailTemplateService"/> class.
33 /// <param name="context">The context.</param>
34 public MockEmailTemplateService(MockEngineContext context
)
36 this.context
= context
;
40 /// Creates an instance of <see cref="Message"/>
41 /// using the specified template for the body
43 /// <param name="templateName">Name of the template to load.
44 /// Will look in <c>Views/mail</c> for that template file.</param>
45 /// <param name="layoutName">Name of the layout.</param>
46 /// <param name="parameters">Dictionary with parameters
47 /// that you can use on the email template</param>
48 /// <returns>An instance of <see cref="Message"/></returns>
49 public Message
RenderMailMessage(string templateName
, string layoutName
, IDictionary parameters
)
51 context
.AddMailTemplateRendered(templateName
, parameters
);
53 return new Message("from", "to", "subject", "body");
57 /// Creates an instance of <see cref="Message"/>
58 /// using the specified template for the body
60 /// <param name="templateName">Name of the template to load.
61 /// Will look in <c>Views/mail</c> for that template file.</param>
62 /// <param name="layoutName">Name of the layout.</param>
63 /// <param name="parameters">Dictionary with parameters
64 /// that you can use on the email template</param>
65 /// <returns>An instance of <see cref="Message"/></returns>
66 public Message
RenderMailMessage(string templateName
, string layoutName
, object parameters
)
68 context
.AddMailTemplateRendered(templateName
, new ReflectionBasedDictionaryAdapter(parameters
));
70 return new Message("from", "to", "subject", "body");
74 /// Renders the mail message.
76 /// <param name="templateName">Name of the template.</param>
77 /// <param name="engineContext">The engine context.</param>
78 /// <param name="controller">The controller.</param>
79 /// <param name="controllerContext">The controller context.</param>
80 /// <param name="doNotApplyLayout">if set to <c>true</c> [do not apply layout].</param>
81 /// <returns></returns>
82 public Message
RenderMailMessage(string templateName
, IEngineContext engineContext
, IController controller
,
83 IControllerContext controllerContext
, bool doNotApplyLayout
)
85 context
.AddMailTemplateRendered(templateName
, controllerContext
.PropertyBag
);
87 return new Message("from", "to", "subject", "body");