Esempio n. 1
0
        public void TestRefreshOnException()
        {
            ApplicationContext.GlobalContext.Clear();

            var personRoot = EditablePerson.GetEditablePerson();

            using (var personForm = new PersonForm())
            {
                //allow read and but not write
                personRoot.AuthLevel = 1;
                personForm.BindUI(personRoot);
                personForm.bindingSourceRefresh1.RefreshOnException = true;
                personForm.Show(); // must show form to get databinding to work properly

                //ensure text boxes equal business object
                Assert.AreEqual(personForm.firstNameTextBox.Text, personRoot.FirstName);

                try
                {
                    personForm.firstNameTextBox.Text = "Dummy First Name Value";
                }
                catch (System.Security.SecurityException) { };

                Assert.AreEqual(personForm.firstNameTextBox.Text, personRoot.FirstName, "Values did not refresh");
            }
        }
Esempio n. 2
0
        public void TestRefresh()
        {
            ApplicationContext.GlobalContext.Clear();

            var personRoot = EditablePerson.GetEditablePerson();

            using (var personForm = new PersonForm())
            {
                //allow read and write of all fields
                personRoot.AuthLevel = 2;
                personForm.BindUI(personRoot);
                personForm.Show(); // must show form to get databinding to work properly

                //ensure all text boxes equal business object
                Assert.AreEqual(personForm.firstNameTextBox.Text, personRoot.FirstName);
                Assert.AreEqual(personForm.lastNameTextBox.Text, personRoot.LastName);
                Assert.AreEqual(personForm.middleNameTextBox.Text, personRoot.MiddleName);
                Assert.AreEqual(personForm.placeOfBirthTextBox.Text, personRoot.PlaceOfBirth);

                personRoot.AuthLevel = 3;
                Assert.AreEqual(personForm.firstNameTextBox.Text, personRoot.FirstName, "Values did not refresh");
                Assert.AreEqual(personForm.lastNameTextBox.Text, personRoot.LastName, "Values did not refresh");
                Assert.AreEqual(personForm.middleNameTextBox.Text, personRoot.MiddleName, "Values did not refresh");
                Assert.AreEqual(personForm.placeOfBirthTextBox.Text, personRoot.PlaceOfBirth, "Values did not refresh");
            }
        }
Esempio n. 3
0
        public void TestActionExtenderChangeState()
        {
            ApplicationContext.GlobalContext.Clear();

            var personRoot = EditablePerson.GetEditablePerson(2);

            using (var personForm = new PersonForm())
            {
                personForm.BindUI(personRoot, true);
                personForm.Show(); // must show form to get databinding to work properly

                //ensure button state matches logical status
                Assert.AreEqual(personForm.SaveButton.Enabled, false, "Default button state on fetch not correct");
                Assert.AreEqual(personForm.CancelButton.Enabled, false, "Default button state on fetch not correct");
                Assert.AreEqual(personForm.CloseButton.Enabled, true, "Default button state on fetch not correct");
                Assert.AreEqual(personForm.ValidateButton.Enabled, true, "Default button state on fetch not correct");

                personForm.firstNameTextBox.Text = "";

                Assert.AreEqual(personForm.SaveButton.Enabled, false, "Save button did not become disabled");
                Assert.AreEqual(personForm.CancelButton.Enabled, true, "Cancel button is not enabled");
                Assert.AreEqual(personForm.CloseButton.Enabled, true, "Button state is not correct");
                Assert.AreEqual(personForm.ValidateButton.Enabled, true, "Button state is not correct");

                personForm.firstNameTextBox.Text = "ABC";

                Assert.AreEqual(personForm.SaveButton.Enabled, true, "Save button did not become enabled");
                Assert.AreEqual(personForm.CancelButton.Enabled, true, "Cancel button is not enabled");
                Assert.AreEqual(personForm.CloseButton.Enabled, true, "Button state is not correct");
                Assert.AreEqual(personForm.ValidateButton.Enabled, true, "Button state is not correct");
            }
        }
Esempio n. 4
0
        public void TestActionExtenderDefaultButtonState()
        {
            ApplicationContext.GlobalContext.Clear();

            var personRoot = EditablePerson.NewEditablePerson();

            using (var personForm = new PersonForm())
            {
                //allow read and write
                personRoot.AuthLevel = 2;
                personForm.BindUI(personRoot, true);
                personForm.Show(); // must show form to get databinding to work properly

                //ensure button state matches logical status
                Assert.AreEqual(personForm.SaveButton.Enabled, true, "Default button state on new not correct");
                Assert.AreEqual(personForm.CancelButton.Enabled, true, "Default button state on new not correct");
                Assert.AreEqual(personForm.CloseButton.Enabled, true, "Default button state on new not correct");
                Assert.AreEqual(personForm.ValidateButton.Enabled, true, "Default button state on new not correct");
            }

            personRoot = EditablePerson.GetEditablePerson(2);
            using (var personForm = new PersonForm())
            {
                personForm.BindUI(personRoot, true);
                personForm.Show(); // must show form to get databinding to work properly

                //ensure button state matches logical status
                Assert.AreEqual(personForm.SaveButton.Enabled, false, "Default button state on fetch not correct");
                Assert.AreEqual(personForm.CancelButton.Enabled, false, "Default button state on fetch not correct");
                Assert.AreEqual(personForm.CloseButton.Enabled, true, "Default button state on fetch not correct");
                Assert.AreEqual(personForm.ValidateButton.Enabled, true, "Default button state on fetch not correct");
            }
        }
        public void TestReadWrite()
        {
            ApplicationContext.GlobalContext.Clear();

            var personRoot = EditablePerson.GetEditablePerson();

            using (var personForm = new PersonForm())
            {
                Assert.IsFalse(personForm.readWriteAuthorization1.GetApplyAuthorization(personForm.firstNameTextBox));
                Assert.IsFalse(personForm.readWriteAuthorization1.GetApplyAuthorization(personForm.middleNameTextBox));
                Assert.IsFalse(personForm.readWriteAuthorization1.GetApplyAuthorization(personForm.lastNameTextBox));

                personForm.readWriteAuthorization1.SetApplyAuthorization(personForm.firstNameTextBox, true);
                personForm.readWriteAuthorization1.SetApplyAuthorization(personForm.middleNameTextBox, true);
                personForm.readWriteAuthorization1.SetApplyAuthorization(personForm.lastNameTextBox, true);

                Assert.IsTrue(personForm.readWriteAuthorization1.GetApplyAuthorization(personForm.firstNameTextBox),
                              "ApplyAuth on");
                Assert.IsTrue(personForm.readWriteAuthorization1.GetApplyAuthorization(personForm.middleNameTextBox),
                              "ApplyAuth on");
                Assert.IsTrue(personForm.readWriteAuthorization1.GetApplyAuthorization(personForm.lastNameTextBox),
                              "ApplyAuth on");

                // assert that controls are available
                Assert.IsFalse(personForm.firstNameTextBox.ReadOnly, "firstname initial readonly false");

                // read and write of FirstName is not allowed
                personRoot.AuthLevel = 0;
                personForm.BindUI(personRoot);
                personForm.Show(); // must show form to get databinding to work properly

                // RWA shoul now set ReadOnly to true and no textvalue
                Assert.IsFalse(personRoot.CanReadProperty(EditablePerson.FirstNameProperty.Name));
                Assert.IsFalse(personRoot.CanWriteProperty(EditablePerson.FirstNameProperty.Name));

                Assert.IsTrue(personForm.firstNameTextBox.ReadOnly, "Control set to readonly");
                Assert.IsTrue(String.IsNullOrEmpty(personForm.firstNameTextBox.Text), "Not allowed to get value");

                // now allowed to get value but not set value
                personRoot.AuthLevel = 1;
                Assert.IsTrue(personRoot.CanReadProperty(EditablePerson.FirstNameProperty.Name));
                Assert.IsFalse(personRoot.CanWriteProperty(EditablePerson.FirstNameProperty.Name));
                Assert.IsTrue(personForm.firstNameTextBox.ReadOnly, "Control set to readonly");
                Assert.AreEqual(personRoot.FirstName, personForm.firstNameTextBox.Text, "display text value from BO");

                personRoot.AuthLevel = 2;
                Assert.IsTrue(personRoot.CanReadProperty(EditablePerson.FirstNameProperty.Name));
                Assert.IsTrue(personRoot.CanWriteProperty(EditablePerson.FirstNameProperty.Name));
                Assert.IsFalse(personForm.firstNameTextBox.ReadOnly, "Control no longer readonly");
                Assert.AreEqual(personRoot.FirstName, personForm.firstNameTextBox.Text, "display text value from BO");
            }
        }
Esempio n. 6
0
 public void BindUI(EditablePerson person, bool useStandardActionExtender)
 {
     editablePersonBindingSource.DataSource = person;
     readWriteAuthorization1.ResetControlAuthorization();
     if (useStandardActionExtender)
     {
         cslaActionExtender1.ResetActionBehaviors(person);
     }
     else
     {
         cslaActionExtenderToolStrip1.ResetActionBehaviors(person);
     }
 }
Esempio n. 7
0
 public void BindUI(EditablePerson person)
 {
     BindUI(person, true);
 }