예제 #1
0
        public void BeginEndShouldStartEditOperation()
        {
            // arrange
            var target = new MockEditableObject();

            // act
            target.BeginEdit();

            // assert
            Assert.True( target.IsEditing );
        }
예제 #2
0
        public void EndEditShouldCompleteEditOperation()
        {
            // arrange
            var target = new MockEditableObject();

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

            // assert
            Assert.False( target.IsEditing );
        }
예제 #3
0
        public void CancelEditShouldAbortEditOperation()
        {
            // arrange
            var target = new MockEditableObject();

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

            // assert
            Assert.False( target.IsEditing );
        }
예제 #4
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 );
        }
예제 #5
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 );
        }
예제 #6
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 );
        }
예제 #7
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 );
        }
예제 #8
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 );
        }