Minor changes to improve testability of helpers
[castle.git] / MonoRail / Castle.MonoRail.Framework.Tests / Helpers / AjaxHelper2TestCase.cs
blobd78e09e9700789eaa780814dc237badcbaa029ce
1 // Copyright 2004-2007 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.Tests.Helpers
17 using System;
19 using NUnit.Framework;
21 using Castle.MonoRail.Framework.Helpers;
23 [TestFixture]
24 public class AjaxHelper2TestCase
26 private AjaxHelper helper = new AjaxHelper();
28 [Test]
29 public void ObserverField1()
31 String expected = "<script type=\"text/javascript\">" +
32 "new Form.Element.Observer('fieldid', 1, " +
33 "function(element, value) { new Ajax.Updater('elementtoupdate', " +
34 "'update.rails', {asynchronous:true, evalScripts:true, parameters:'value=' + value}) })</script>";
36 String actual = helper.ObserveField("fieldid", 1, "update.rails", new DictHelper().CreateDict("update=elementtoupdate") );
38 Assert.AreEqual(expected, actual);
41 [Test]
42 public void ObserverField2()
44 String expected = "<script type=\"text/javascript\">" +
45 "new Form.Element.Observer('fieldid', 1, " +
46 "function(element, value) { new Ajax.Updater('elementtoupdate', " +
47 "'update.rails', {asynchronous:true, evalScripts:true, parameters:obtainvalue()}) })</script>";
49 String actual = helper.ObserveField("fieldid", 1, "update.rails", "elementtoupdate", "obtainvalue()" );
51 Assert.AreEqual(expected, actual);
54 [Test]
55 public void OnSuccessFailureCallbacks()
57 String expected = "<form onsubmit=\"new Ajax.Request('something.rails', "
58 + "{onSuccess:function(request) { javascriptcode } , onFailure:function("
59 + "request) { javascriptcode } , asynchronous:true, evalScripts:true, "
60 + "parameters:Form.serialize(this)}); return false;\" enctype=\"multipart/form-data\" "
61 + "action=\"something.rails\" method=\"post\" >";
63 String actual = helper.BuildFormRemoteTag( new DictHelper().CreateDict("url=something.rails", "onfailure=javascriptcode", "onsuccess=javascriptcode") );
65 Assert.AreEqual(expected, actual);