public void BookListViewModelBooksTest()
        {
            List<Book> books = new List<Book>()
            {
                new Book() { Title = "The Fellowship of the Ring" },
                new Book() { Title = "The Two Towers" }
            };

            MockBookListView bookListView = new MockBookListView();
            IList<BookDataModel> bookDataModels = new SynchronizingCollection<BookDataModel, Book>(books, b => new BookDataModel(b, dummyCommand));

            AssertHelper.ExpectedException<ArgumentNullException>(() => new BookListViewModel(bookListView, null));
            BookListViewModel bookListViewModel = new BookListViewModel(bookListView, bookDataModels);

            Assert.AreEqual(bookDataModels, bookListViewModel.Books);
            Assert.IsNull(bookListViewModel.SelectedBook);
            Assert.IsFalse(bookListViewModel.SelectedBooks.Any());

            // Select the first book
            AssertHelper.PropertyChangedEvent(bookListViewModel, x => x.SelectedBook,
                () => bookListViewModel.SelectedBook = bookDataModels.First());
            Assert.AreEqual(books.First(), bookListViewModel.SelectedBook.Book);

            bookListViewModel.SelectedBooks.Add(bookDataModels.First());
            Assert.IsTrue(bookListViewModel.SelectedBooks.SequenceEqual(new[] { bookDataModels.First() }));

            // Select both books
            bookListViewModel.SelectedBooks.Add(bookDataModels.Last());
            Assert.IsTrue(bookListViewModel.SelectedBooks.SequenceEqual(bookDataModels));
        }
        public void BookListViewModelCommandsTest()
        {
            MockBookListView bookListView = new MockBookListView();
            BookListViewModel bookListViewModel = new BookListViewModel(bookListView, new List<BookDataModel>());

            DelegateCommand mockCommand = new DelegateCommand(() => { });
            AssertHelper.PropertyChangedEvent(bookListViewModel, x => x.AddNewCommand, () =>
                bookListViewModel.AddNewCommand = mockCommand);
            Assert.AreEqual(mockCommand, bookListViewModel.AddNewCommand);

            mockCommand = new DelegateCommand(() => { });
            AssertHelper.PropertyChangedEvent(bookListViewModel, x => x.RemoveCommand, () =>
                bookListViewModel.RemoveCommand = mockCommand);
            Assert.AreEqual(mockCommand, bookListViewModel.RemoveCommand);
        }
        public void BookListViewModelFilterTest()
        {
            IList<Book> books = new ObservableCollection<Book>()
            {
                new Book() { Title = "The Fellowship of the Ring", Author = "J.R.R. Tolkien" },
                new Book() { Title = "The Two Towers", Author = "J.R.R. Tolkien" }
            };

            MockBookListView bookListView = new MockBookListView();
            IList<BookDataModel> bookDataModels = new SynchronizingCollection<BookDataModel, Book>(books, b => new BookDataModel(b, dummyCommand));
            BookListViewModel bookListViewModel = new BookListViewModel(bookListView, bookDataModels);

            Assert.IsTrue(bookListViewModel.Filter(bookDataModels[0]));
            Assert.IsTrue(bookListViewModel.Filter(bookDataModels[1]));

            AssertHelper.PropertyChangedEvent(bookListViewModel, x => x.FilterText, () => bookListViewModel.FilterText = "J.");
            Assert.AreEqual("J.", bookListViewModel.FilterText);
            Assert.IsTrue(bookListViewModel.Filter(bookDataModels[0]));
            Assert.IsTrue(bookListViewModel.Filter(bookDataModels[1]));

            bookListViewModel.FilterText = "J.R.R. Tolkien";
            Assert.IsTrue(bookListViewModel.Filter(bookDataModels[0]));
            Assert.IsTrue(bookListViewModel.Filter(bookDataModels[1]));

            bookListViewModel.FilterText = "Fell";
            Assert.IsTrue(bookListViewModel.Filter(bookDataModels[0]));
            Assert.IsFalse(bookListViewModel.Filter(bookDataModels[1]));

            bookListViewModel.FilterText = "Tow";
            Assert.IsFalse(bookListViewModel.Filter(bookDataModels[0]));
            Assert.IsTrue(bookListViewModel.Filter(bookDataModels[1]));

            bookListViewModel.FilterText = "xyz";
            Assert.IsFalse(bookListViewModel.Filter(bookDataModels[0]));
            Assert.IsFalse(bookListViewModel.Filter(bookDataModels[1]));

            books.Add(new Book());
            Assert.IsTrue(bookListViewModel.Filter(bookDataModels[2]));
            books[2].Title = "Serenity, Vol 1: Those Left Behind";
            Assert.IsTrue(bookListViewModel.Filter(bookDataModels[2]));
        }