public void UndoablePropertyValueRedo() { BookCollection myBooks = new BookCollection(); myBooks.Name = "A few of my favorite books"; myBooks.Library.Add( ClockWorkOrange ); myBooks.Library.Add( DarwinsGod ); myBooks.Library.Add( SoftwareEstimates ); myBooks.FavoriteBook = ClockWorkOrange; // Redo of a basic property UndoablePropertyValue<BookCollection, String> nameChange = new UndoablePropertyValue<BookCollection, String>( myBooks, "Name", UndoableActions.Modify, "A few of my favorite books", "A few of my books" ); nameChange.Redo(); Assert.AreEqual( "A few of my books", myBooks.Name ); Assert.AreEqual( 3, myBooks.Library.Count ); Assert.IsTrue( myBooks.Library.Contains( DarwinsGod ) ); Assert.IsTrue( myBooks.Library.Contains( SoftwareEstimates ) ); Assert.IsTrue( myBooks.Library.Contains( ClockWorkOrange ) ); Assert.AreEqual( ClockWorkOrange, myBooks.FavoriteBook ); UndoablePropertyValue<BookCollection, Book> favoriteChange = new UndoablePropertyValue<BookCollection, Book>( myBooks, "FavoriteBook", UndoableActions.Modify, ClockWorkOrange, MereChristianity ); favoriteChange.Redo(); Assert.AreEqual( "A few of my books", myBooks.Name ); Assert.AreEqual( 3, myBooks.Library.Count ); Assert.IsTrue( myBooks.Library.Contains( DarwinsGod ) ); Assert.IsTrue( myBooks.Library.Contains( SoftwareEstimates ) ); Assert.IsTrue( myBooks.Library.Contains( ClockWorkOrange ) ); Assert.AreEqual( MereChristianity, myBooks.FavoriteBook ); // Redo of a removal from a collection UndoablePropertyValue<BookCollection, Book> removeBook = new UndoablePropertyValue<BookCollection, Book>( myBooks, "Library", UndoableActions.Remove, ClockWorkOrange, null ); removeBook.Redo(); Assert.AreEqual( "A few of my books", myBooks.Name ); Assert.AreEqual( 2, myBooks.Library.Count ); Assert.IsTrue( myBooks.Library.Contains( DarwinsGod ) ); Assert.IsTrue( myBooks.Library.Contains( SoftwareEstimates ) ); Assert.AreEqual( MereChristianity, myBooks.FavoriteBook ); // Redo of an addition to a collection UndoablePropertyValue<BookCollection, Book> addBook = new UndoablePropertyValue<BookCollection, Book>( myBooks, "Library", UndoableActions.Add, null, MereChristianity ); addBook.Redo(); Assert.AreEqual( "A few of my books", myBooks.Name ); Assert.AreEqual( 3, myBooks.Library.Count ); Assert.IsTrue( myBooks.Library.Contains( SoftwareEstimates ) ); Assert.IsTrue( myBooks.Library.Contains( DarwinsGod ) ); Assert.IsTrue( myBooks.Library.Contains( MereChristianity ) ); Assert.AreEqual( MereChristianity, myBooks.FavoriteBook ); }
public void UndoablePropertyValueConstruct() { BookCollection myBooks = new BookCollection(); myBooks.Name = "A few of my books"; myBooks.Library.Add( DarwinsGod ); myBooks.Library.Add( SoftwareEstimates ); myBooks.FavoriteBook = ClockWorkOrange; // Construct an object representing a change to a basic property UndoablePropertyValue<BookCollection, String> nameChange = new UndoablePropertyValue<BookCollection, String>( myBooks, "Name", UndoableActions.Modify, "A few of my books", "Some good books" ); // Construct an object representing an addition to a collection UndoablePropertyValue<BookCollection, Book> addBook = new UndoablePropertyValue<BookCollection, Book>( myBooks, "Library", UndoableActions.Add, null, MereChristianity ); // Construct an object representing a removal from a collection UndoablePropertyValue<BookCollection, Book> removeBook = new UndoablePropertyValue<BookCollection, Book>( myBooks, "Library", UndoableActions.Remove, MereChristianity, null ); }