CSLA.NET 6.0.0
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
ReadWriteAuthorizationTests.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="ReadWriteAuthorizationTests.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>no summary</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.Collections.Generic;
10using System.Text;
11using Csla.Test.Security;
12using UnitDriven;
13using System.Diagnostics;
14
15#if NUNIT
16using NUnit.Framework;
17using TestClass = NUnit.Framework.TestFixtureAttribute;
18using TestInitialize = NUnit.Framework.SetUpAttribute;
19using TestCleanup = NUnit.Framework.TearDownAttribute;
20using TestMethod = NUnit.Framework.TestAttribute;
21#elif MSTEST
22using Microsoft.VisualStudio.TestTools.UnitTesting;
23#endif
24
25namespace Csla.Test.Windows
26{
27#if TESTING
28 [DebuggerNonUserCode]
29 [DebuggerStepThrough]
30#endif
31 [TestClass()]
33 {
34
35 [TestMethod()]
36 [TestCategory("SkipWhenLiveUnitTesting")]
37 public void TestReadWrite()
38 {
39 ApplicationContext.GlobalContext.Clear();
40
41 var personRoot = EditablePerson.GetEditablePerson();
42 using (var personForm = new PersonForm())
43 {
44
45
46 Assert.IsFalse(personForm.readWriteAuthorization1.GetApplyAuthorization(personForm.firstNameTextBox));
47 Assert.IsFalse(personForm.readWriteAuthorization1.GetApplyAuthorization(personForm.middleNameTextBox));
48 Assert.IsFalse(personForm.readWriteAuthorization1.GetApplyAuthorization(personForm.lastNameTextBox));
49
50 personForm.readWriteAuthorization1.SetApplyAuthorization(personForm.firstNameTextBox, true);
51 personForm.readWriteAuthorization1.SetApplyAuthorization(personForm.middleNameTextBox, true);
52 personForm.readWriteAuthorization1.SetApplyAuthorization(personForm.lastNameTextBox, true);
53
54 Assert.IsTrue(personForm.readWriteAuthorization1.GetApplyAuthorization(personForm.firstNameTextBox),
55 "ApplyAuth on");
56 Assert.IsTrue(personForm.readWriteAuthorization1.GetApplyAuthorization(personForm.middleNameTextBox),
57 "ApplyAuth on");
58 Assert.IsTrue(personForm.readWriteAuthorization1.GetApplyAuthorization(personForm.lastNameTextBox),
59 "ApplyAuth on");
60
61 // assert that controls are available
62 Assert.IsFalse(personForm.firstNameTextBox.ReadOnly, "firstname initial readonly false");
63
64 // read and write of FirstName is not allowed
65 personRoot.AuthLevel = 0;
66 personForm.BindUI(personRoot);
67 personForm.Show(); // must show form to get databinding to work properly
68
69 // RWA shoul now set ReadOnly to true and no textvalue
70 Assert.IsFalse(personRoot.CanReadProperty(EditablePerson.FirstNameProperty.Name));
71 Assert.IsFalse(personRoot.CanWriteProperty(EditablePerson.FirstNameProperty.Name));
72
73 Assert.IsTrue(personForm.firstNameTextBox.ReadOnly, "Control set to readonly");
74 Assert.IsTrue(String.IsNullOrEmpty(personForm.firstNameTextBox.Text), "Not allowed to get value");
75
76 // now allowed to get value but not set value
77 personRoot.AuthLevel = 1;
78 Assert.IsTrue(personRoot.CanReadProperty(EditablePerson.FirstNameProperty.Name));
79 Assert.IsFalse(personRoot.CanWriteProperty(EditablePerson.FirstNameProperty.Name));
80 Assert.IsTrue(personForm.firstNameTextBox.ReadOnly, "Control set to readonly");
81 Assert.AreEqual(personRoot.FirstName, personForm.firstNameTextBox.Text, "display text value from BO");
82
83 personRoot.AuthLevel = 2;
84 Assert.IsTrue(personRoot.CanReadProperty(EditablePerson.FirstNameProperty.Name));
85 Assert.IsTrue(personRoot.CanWriteProperty(EditablePerson.FirstNameProperty.Name));
86 Assert.IsFalse(personForm.firstNameTextBox.ReadOnly, "Control no longer readonly");
87 Assert.AreEqual(personRoot.FirstName, personForm.firstNameTextBox.Text, "display text value from BO");
88 }
89 }
90 }
91}
Provides consistent context information between the client and server DataPortal objects.
void Clear()
Clears all context collections.
static readonly PropertyInfo< string > FirstNameProperty
static EditablePerson GetEditablePerson()