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.
BindingRefreshTests.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")]
38 {
39 ApplicationContext.GlobalContext.Clear();
40
41 var personRoot = EditablePerson.GetEditablePerson();
42 using (var personForm = new PersonForm())
43 {
44 //allow read and but not write
45 personRoot.AuthLevel = 1;
46 personForm.BindUI(personRoot);
47 personForm.bindingSourceRefresh1.RefreshOnException = false;
48 personForm.Show(); // must show form to get databinding to work properly
49
50 //ensure all text boxes equal business object
51 Assert.AreEqual(personForm.firstNameTextBox.Text, personRoot.FirstName);
52
53 try
54 {
55 personForm.firstNameTextBox.Text = "Dummy First Name Value";
56 }
57 catch (System.Security.SecurityException) { };
58
59 Assert.AreNotEqual(personForm.firstNameTextBox.Text, personRoot.FirstName);
60 }
61 }
62
63
64 [TestMethod()]
65 [TestCategory("SkipWhenLiveUnitTesting")]
67 {
68 ApplicationContext.GlobalContext.Clear();
69
70 var personRoot = EditablePerson.GetEditablePerson();
71 using (var personForm = new PersonForm())
72 {
73 //allow read and but not write
74 personRoot.AuthLevel = 1;
75 personForm.BindUI(personRoot);
76 personForm.bindingSourceRefresh1.RefreshOnException = true;
77 personForm.Show(); // must show form to get databinding to work properly
78
79 //ensure text boxes equal business object
80 Assert.AreEqual(personForm.firstNameTextBox.Text, personRoot.FirstName);
81
82 try
83 {
84 personForm.firstNameTextBox.Text = "Dummy First Name Value";
85 }
86 catch (System.Security.SecurityException) { };
87
88 Assert.AreEqual(personForm.firstNameTextBox.Text, personRoot.FirstName, "Values did not refresh");
89 }
90 }
91
92 [TestMethod()]
93 public void TestRefresh()
94 {
95 ApplicationContext.GlobalContext.Clear();
96
97 var personRoot = EditablePerson.GetEditablePerson();
98 using (var personForm = new PersonForm())
99 {
100 //allow read and write of all fields
101 personRoot.AuthLevel = 2;
102 personForm.BindUI(personRoot);
103 personForm.Show(); // must show form to get databinding to work properly
104
105 //ensure all text boxes equal business object
106 Assert.AreEqual(personForm.firstNameTextBox.Text, personRoot.FirstName);
107 Assert.AreEqual(personForm.lastNameTextBox.Text, personRoot.LastName);
108 Assert.AreEqual(personForm.middleNameTextBox.Text, personRoot.MiddleName);
109 Assert.AreEqual(personForm.placeOfBirthTextBox.Text, personRoot.PlaceOfBirth);
110
111 personRoot.AuthLevel = 3;
112 Assert.AreEqual(personForm.firstNameTextBox.Text, personRoot.FirstName, "Values did not refresh");
113 Assert.AreEqual(personForm.lastNameTextBox.Text, personRoot.LastName, "Values did not refresh");
114 Assert.AreEqual(personForm.middleNameTextBox.Text, personRoot.MiddleName, "Values did not refresh");
115 Assert.AreEqual(personForm.placeOfBirthTextBox.Text, personRoot.PlaceOfBirth, "Values did not refresh");
116
117 }
118 }
119 }
120}
Provides consistent context information between the client and server DataPortal objects.
void Clear()
Clears all context collections.
static EditablePerson GetEditablePerson()