Removed untyped contructor from ComponentRegistration and add a protected setter.
[castle.git] / MonoRail / Castle.MonoRail.ActiveRecordSupport.Tests / ARDataBinderTests / AccountControllerTestCase.cs
blob54c56cacbf55e1028f0351fc674ebdbeca479f1f
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.ARDataBinderTests
17 using System;
18 using Castle.ActiveRecord;
19 using NUnit.Framework;
20 using TestSiteARSupport.Model;
21 using WatiN.Core;
23 [TestFixture]
24 public class AccountControllerTestCase : BaseAcceptanceTestCase
26 private ProductLicense lic1, lic2;
27 private AccountPermission perm1, perm2;
28 private User user1, user2;
29 private Account account;
31 protected override void CreateTestData()
33 lic1 = new ProductLicense();
34 lic2 = new ProductLicense();
36 perm1 = new AccountPermission("Permission 1");
37 perm2 = new AccountPermission("Permission 2");
39 user1 = new User("John Doe");
40 user2 = new User("Mary Jane");
42 ActiveRecordMediator<ProductLicense>.Create(lic1);
43 ActiveRecordMediator<ProductLicense>.Create(lic2);
44 ActiveRecordMediator<AccountPermission>.Create(perm1);
45 ActiveRecordMediator<AccountPermission>.Create(perm2);
46 ActiveRecordMediator<User>.Create(user1);
47 ActiveRecordMediator<User>.Create(user2);
50 [Test]
51 public void CreateAccount()
53 ie.GoTo("http://localhost:88/Account/new.castle");
55 ie.Button(new Value("Insert")).Click(); // Trying to save will spark the validation
57 Assert.IsTrue(ie.Elements.Exists("advice-required-account_name"));
58 Assert.IsTrue(ie.Elements.Exists("advice-required-account_email"));
59 Assert.IsTrue(ie.Elements.Exists("advice-required-account_password"));
61 Assert.AreEqual("This is a required field.", ie.Element("advice-required-account_name").InnerHtml);
62 Assert.AreEqual("Please enter a valid email address. For example fred@domain.com. This is a required field.", ie.Element("advice-required-account_email").InnerHtml);
63 Assert.AreEqual("This is a required field.", ie.Element("advice-required-account_password").InnerHtml);
65 // Passwords wont match
66 ie.TextField("account_password").TypeText("123");
67 ie.TextField("account_confirmationpassword").TypeText("321");
69 Assert.IsTrue(ie.Elements.Exists("advice-validate-same-as-password-account_confirmationpassword"));
70 Assert.AreEqual("Fields do not match.", ie.Element("advice-validate-same-as-password-account_confirmationpassword").InnerHtml);
72 // This should fix it
73 ie.TextField("account_password").TypeText("123987");
74 ie.TextField("account_confirmationpassword").TypeText("123987");
76 ie.TextField("account_name").TypeText("My first account");
77 ie.TextField("account_email").TypeText("johndoe@gmail.com");
79 ie.SelectList("account_ProductLicense_id").SelectByValue(lic1.Id.ToString());
81 ie.CheckBox("account_permissions").Checked = true;
82 ie.CheckBox("account_Permissions_1_").Checked = true;
84 ie.CheckBox("account_users").Checked = true;
85 ie.CheckBox("account_Users_1_").Checked = true;
87 ie.Button(new Value("Insert")).Click();
89 int accountId = Convert.ToInt32(ie.Element("newid").InnerHtml);
91 account = ActiveRecordMediator<Account>.FindByPrimaryKey(accountId);
93 Assert.AreEqual("My first account", account.Name);
94 Assert.AreEqual("johndoe@gmail.com", account.Email);
95 Assert.AreEqual("123987", account.Password);
97 Assert.IsNotNull(account.ProductLicense);
98 Assert.AreEqual(lic1.Id, account.ProductLicense.Id);
100 Assert.AreEqual(2, account.Permissions.Count);
101 Assert.AreEqual(2, account.Users.Count);
104 [Test]
105 public void RemovingElementsFromCollections()
107 CreateAccount();
109 ie.GoTo("http://localhost:88/Account/edit.castle?id=" + account.Id);
111 ie.TextField("account_password").TypeText("123987");
112 ie.TextField("account_confirmationpassword").TypeText("123987");
114 ie.CheckBox("account_Permissions_0_").Checked = false;
115 ie.CheckBox("account_Permissions_1_").Checked = false;
117 ie.CheckBox("account_Users_0_").Checked = false;
118 ie.CheckBox("account_Users_1_").Checked = false;
120 ie.Button(new Value("Update")).Click();
122 ActiveRecordMediator<Account>.Refresh(account);
124 Assert.AreEqual("My first account", account.Name);
125 Assert.AreEqual("johndoe@gmail.com", account.Email);
126 Assert.AreEqual("123987", account.Password);
128 Assert.AreEqual(0, account.Permissions.Count);
129 Assert.AreEqual(0, account.Users.Count);