Accept and Reject changes

BLToolkit.NET

Business Logic Toolkit for .NET www.bltoolkit.net
 

After verifying the accuracy of changes made to the object, you can accept the changes using the AcceptChanges method of the object, which will set the Current field values to be the Original values. The RejectChanges method rejects all changes made to the object since AcceptChanges was last called.

AcceptRejectChanges.cs
using System;
using NUnit.Framework;
using BLToolkit.EditableObjects;

namespace HowTo.EditableObjects
{
    [TestFixture]
    public class AcceptRejectChanges
    {
        public abstract class TestObject : EditableObject<TestObject>
        {
            public abstract string FirstName { get; set; }
            public abstract string LastName  { get; set; }
        }

        [Test]
        public void Test()
        {
            // Create an instance.
            //
            TestObject obj = TestObject.CreateInstance();

            // Accept changes.
            //
            obj.FirstName = "Tester";
            obj.LastName  = "Testerson";

            Assert.IsTrue(obj.IsDirty);

            obj.AcceptChanges();

            Assert.AreEqual("Tester", obj.FirstName);
            Assert.IsFalse(obj.IsDirty);

            // Reject changes.
            //
            obj.FirstName = "Developer";

            Assert.IsTrue(obj.IsDirty);

            obj.RejectChanges();

            Assert.AreEqual("Tester", obj.FirstName);
            Assert.IsFalse(obj.IsDirty);
        }
    }
}
 
© 2010 www.bltoolkit.net
[email protected]