Removed untyped contructor from ComponentRegistration and add a protected setter.
[castle.git] / MonoRail / Castle.MonoRail.ActiveRecordSupport.Tests / ScaffoldingTests / UserScaffoldTestCase.cs
blobede8167a74a3abe7bbef9cdec2886bdcd25d2912
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.ActiveRecordSupport.Tests.ScaffoldingTests
17 using System;
18 using Castle.ActiveRecord;
19 using Castle.ActiveRecord.Framework;
20 using NUnit.Framework;
21 using TestSiteARSupport.Model;
22 using WatiN.Core;
23 using Attribute=WatiN.Core.Attribute;
25 [TestFixture]
26 public class UserScaffoldTestCase : BaseAcceptanceTestCase
28 private Account account1, account2, account3;
29 private User user;
31 protected override void CreateTestData()
33 account1 = new Account("AdWords", "email1@gmail.net", "abc123");
34 account2 = new Account("AdSense", "email1@gmail.net", "abc123");
35 account3 = new Account("Orkut", "email1@gmail.net", "abc123");
37 account1.Password = account2.Password = account3.Password = "123abcd";
38 account1.ConfirmationPassword = account2.ConfirmationPassword = account3.ConfirmationPassword = "123abcd";
40 account1.Create();
41 account2.Create();
42 account3.Create();
45 [Test]
46 public void CreateUser()
48 ie.GoTo("http://localhost:88/UserScaffold/new.castle");
50 ie.Button(new Value("Create")).Click(); // Trying to save will spark the validation
52 Assert.AreEqual("http://localhost:88/UserScaffold/new.castle", ie.Url);
54 Assert.IsTrue(ie.Elements.Exists("advice-required-User_Name"));
55 Assert.AreEqual("This is a required field.", ie.Element("advice-required-User_Name").InnerHtml);
57 ie.TextField("User_Name").TypeText("John Doe");
58 ie.SelectList("User_Account_Id").SelectByValue(account1.Id.ToString());
60 ie.Button(new Value("Create")).Click(); // Now it should save
62 Assert.AreEqual("http://localhost:88/UserScaffold/list.castle", ie.Url);
64 ElementCollection elements = ie.Elements.Filter(new Attribute("className", "idRow"));
66 Assert.IsTrue(elements.Length > 0, "Newly added object not present on the list?");
68 int id = Convert.ToInt32(elements[elements.Length - 1].InnerHtml);
70 user = ActiveRecordMediator<User>.FindByPrimaryKey(id);
72 Assert.AreEqual("John Doe", user.Name);
73 Assert.IsNotNull(user.Account);
74 Assert.AreEqual(account1.Id, user.Account.Id);
77 [Test]
78 public void EditUser()
80 CreateUser();
82 ie.GoTo("http://localhost:88/UserScaffold/edit.castle?id=" + user.Id);
84 ie.TextField("User_Name").TypeText("");
85 ie.Button(new Value("Save Changes")).Click(); // Trying to save will spark the validation
87 Assert.AreEqual("http://localhost:88/UserScaffold/edit.castle?id=" + user.Id, ie.Url);
89 Assert.IsTrue(ie.Elements.Exists("advice-required-User_Name"));
90 Assert.AreEqual("This is a required field.", ie.Element("advice-required-User_Name").InnerHtml);
92 ie.TextField("User_Name").TypeText("Mary Jane");
93 ie.SelectList("User_Account_Id").SelectByValue(account2.Id.ToString());
95 ie.Button(new Value("Save Changes")).Click(); // Now it should save
97 Assert.AreEqual("http://localhost:88/UserScaffold/list.castle", ie.Url);
99 ElementCollection elements = ie.Elements.Filter(new Attribute("className", "idRow"));
101 Assert.IsTrue(elements.Length > 0, "Changed object not present on the list?");
103 int id = Convert.ToInt32(elements[elements.Length - 1].InnerHtml);
105 user = ActiveRecordMediator<User>.FindByPrimaryKey(id);
107 Assert.AreEqual("Mary Jane", user.Name);
108 Assert.IsNotNull(user.Account);
109 Assert.AreEqual(account2.Id, user.Account.Id);
112 [Test]
113 public void ConfirmAndDeleteNewlyCreatedUser()
115 CreateUser();
117 Assert.AreEqual("http://localhost:88/UserScaffold/list.castle", ie.Url);
119 ElementCollection elements = ie.Elements.Filter(new Attribute("className", "deletelink"));
121 Link delLink = null;
123 foreach(Link link in elements)
125 if (link.Url.EndsWith("confirm.castle?id=" + user.Id))
127 delLink = link;
128 break;
132 Assert.IsNotNull(delLink);
134 delLink.Click();
136 ie.Button(new Value("Yes")).Click();
140 ActiveRecordMediator<User>.Refresh(user);
142 Assert.Fail("Expecting exception as the user was removed");
144 catch(ActiveRecordException)