Esempio n. 1
0
 public void RecoveryModelPropertyShouldBeReadWrite()
 {
     var target = new MockEditableObject();
     Assert.Equal( EditRecoveryModel.Simple, target.RecoveryModel );
     target.RecoveryModel = EditRecoveryModel.Full;
     Assert.Equal( EditRecoveryModel.Full, target.RecoveryModel );
 }
Esempio n. 2
0
        public void BeginEndShouldStartEditOperation()
        {
            // arrange
            var target = new MockEditableObject();

            // act
            target.BeginEdit();

            // assert
            Assert.True( target.IsEditing );
        }
Esempio n. 3
0
        public void EndEditShouldCompleteEditOperation()
        {
            // arrange
            var target = new MockEditableObject();

            // act
            target.BeginEdit();
            target.EndEdit();

            // assert
            Assert.False( target.IsEditing );
        }
Esempio n. 4
0
        public void CancelEditShouldAbortEditOperation()
        {
            // arrange
            var target = new MockEditableObject();

            // act
            target.BeginEdit();
            target.CancelEdit();

            // assert
            Assert.False( target.IsEditing );
        }
        public void ShouldRollbackChangesToObject()
        {
            // arrange
            var obj = new MockEditableObject();
            var transaction = new FieldTransaction( obj, new[] { "LastModified" } );
            var lastModified = obj.LastModified;

            // act
            transaction.Begin();
            obj.LastModified = DateTime.Now;
            transaction.Rollback();

            // assert
            Assert.Equal( lastModified, obj.LastModified );
        }
        public void ShouldCommitChangesToObject()
        {
            // arrange
            var obj = new MockEditableObject();
            var createdDate = obj.CreatedDate;
            var transaction = new PropertyTransaction( obj );

            obj.Id = 1;
            obj.FirstName = string.Empty;
            obj.LastName = string.Empty;

            // act
            transaction.Begin();
            obj.FirstName = "unit";
            obj.LastName = "test";
            transaction.Commit();

            // assert
            Assert.Equal( 1, obj.Id );
            Assert.Equal( "unit", obj.FirstName );
            Assert.Equal( "test", obj.LastName );
            Assert.Equal( createdDate, obj.CreatedDate );
        }
Esempio n. 7
0
        public void EndEditShouldCommitChangesToObject()
        {
            // arrange
            var target = new MockEditableObject();
            var createdDate = target.CreatedDate;

            // act
            target.Id = 1;
            target.FirstName = string.Empty;
            target.LastName = string.Empty;

            target.BeginEdit();
            target.FirstName = "unit";
            target.LastName = "test";
            target.EndEdit();

            // assert
            Assert.False( target.IsEditing );
            Assert.Equal( 1, target.Id );
            Assert.Equal( "unit", target.FirstName );
            Assert.Equal( "test", target.LastName );
            Assert.Equal( createdDate, target.CreatedDate );
        }
        public void ShouldRollbackChangesToObject()
        {
            // arrange
            var obj = new MockEditableObject();
            var createdDate = obj.CreatedDate;
            var transaction = new PropertyTransaction( obj, new[] { "FirstName", "LastName" } );

            obj.Id = 1;
            obj.FirstName = string.Empty;
            obj.LastName = string.Empty;

            // act
            transaction.Begin();
            obj.Id = 2;
            obj.FirstName = "unit";
            obj.LastName = "test";
            transaction.Rollback();

            // assert
            Assert.Equal( 2, obj.Id );
            Assert.Equal( string.Empty, obj.FirstName );
            Assert.Equal( string.Empty, obj.LastName );
            Assert.Equal( createdDate, obj.CreatedDate );
        }
Esempio n. 9
0
        public void CancelEditShouldRollbackPropertyChangesToObject()
        {
            // arrange
            var target = new MockEditableObject();
            var createdDate = target.CreatedDate;

            target.Id = 1;
            target.FirstName = string.Empty;
            target.LastName = string.Empty;

            // act
            target.BeginEdit();
            target.Id = 2;
            target.FirstName = "unit";
            target.LastName = "test";
            target.CancelEdit();

            // assert
            Assert.False( target.IsEditing );
            Assert.Equal( 2, target.Id ); // doesn't support rollback
            Assert.Equal( string.Empty, target.FirstName );
            Assert.Equal( string.Empty, target.LastName );
            Assert.Equal( createdDate, target.CreatedDate );
        }
Esempio n. 10
0
 public void OnPropertyChangedShouldNotTriggerStateChangeWhenSuppressed()
 {
     var target = new MockEditableObject();
     target.InvokeOnPropertyChanged( "FirstName", true );
     Assert.False( target.IsChanged );
 }
Esempio n. 11
0
        public void AcceptChangesShouldCreateNewSavepoint()
        {
            // arrange
            var target = new MockEditableObject();

            target.RecoveryModel = EditRecoveryModel.Full;
            target.Id = 5;
            target.FirstName = "bill";
            target.LastName = "mei";
            target.AcceptChanges();

            // act
            target.BeginEdit();
            target.FirstName = "john";
            target.LastName = "doe";
            target.EndEdit();
            target.AcceptChanges();

            target.BeginEdit();
            target.FirstName = "jane";
            target.LastName = "doe";
            target.EndEdit();

            target.RejectChanges();

            // assert
            Assert.False( target.IsChanged );
            Assert.Equal( "john", target.FirstName );
            Assert.Equal( "doe", target.LastName );
        }
Esempio n. 12
0
        public void RejectChangesShouldSignalNoChanges()
        {
            // arrange
            var target = new MockEditableObject();

            target.Id = 5;
            target.LastName = "bill";
            target.FirstName = "mei";

            // act
            var changed = target.IsChanged;
            target.RejectChanges();

            // assert
            Assert.True( changed );
            Assert.False( target.IsChanged );
        }
Esempio n. 13
0
        public void IsChangedPropertyShouldBeTrueUntilAcceptChangesIsInvoked()
        {
            var target = new MockEditableObject();

            Assert.False( target.IsChanged );

            target.BeginEdit();
            target.Id = 5;
            target.LastName = "bill";
            target.FirstName = "mei";
            target.CancelEdit();

            // initial state was unchanged, so it should still be unchanged
            Assert.False( target.IsChanged );

            target.BeginEdit();
            target.Id = 10;
            target.LastName = "john";
            target.FirstName = "doe";
            target.EndEdit();

            // change committed, so it should now be changed
            Assert.True( target.IsChanged );

            target.BeginEdit();
            target.Id = 20;
            target.LastName = "jane";
            target.FirstName = "doe";
            target.CancelEdit();

            // although previous edit was canceled, the object was already the
            // changed state.  it should, therfore, still be in the changed state
            Assert.True( target.IsChanged );

            target.AcceptChanges();

            Assert.False( target.IsChanged );
        }
Esempio n. 14
0
        public void CancelEditShouldRollbackFieldChangesToObject()
        {
            // arrange
            var target = new MockEditableObject( ( @this, uneditable ) => new FieldTransaction( @this, new []{ "LastModified" } ) );
            var lastModified = target.LastModified;

            // act
            target.BeginEdit();
            target.LastModified = DateTime.Now;
            target.CancelEdit();

            // assert
            Assert.False( target.IsEditing );
            Assert.Equal( lastModified, target.LastModified );
        }