public void ShouldCopyBook() { Book book = new Book { Id = 123, CategoryId = 1, Title = "Book title", Author = "pawel", AdditionalInfoLine1 = "Additional Info", ISBN = "222224" }; Bitmap bitmap = new Bitmap(4, 4); for (int x = 0; x < bitmap.Height; ++x) for (int y = 0; y < bitmap.Width; ++y) bitmap.SetPixel(x, y, Color.Red); book.Cover = bitmap; Book copy = book.Copy(); foreach (var propertyInfo in typeof(Book).GetProperties()) { if (propertyInfo.PropertyType == typeof(Image)) { Bitmap img1 = (Bitmap)propertyInfo.GetValue(book, null); Bitmap img2 = (Bitmap)propertyInfo.GetValue(copy, null); for (int x = 0; x < img1.Height; ++x) for (int y = 0; y < img1.Width; ++y) { Assert.AreEqual(img1.GetPixel(x, y), img2.GetPixel(x, y)); } } else { Assert.AreEqual(propertyInfo.GetValue(book, null), propertyInfo.GetValue(copy, null)); } } }
private void OnAddBookToCategoryItemExecute(object sender, ExecutedRoutedEventArgs e) { Category cat = e.Parameter as Category; if (cat != null) { Book book = new Book {Category = cat}; OperationStatus<Book> result1 = BookDetails.ShowWindow(this, book.Copy()); if (result1.Result == OperationResult.Passed) { var result = BooksManager.BooksManager.InsertBook(result1.Data); if (result.Result == OperationResult.Passed) { RefreshBooksList(new BookFilter {RootCategoryId = _selectedCategoryId}); uxBooksList.CurrentItem = book; } else { MessageBox.Show(result.OperationMessage); } } } }
private void OnAddBookItemExecute(object sender, ExecutedRoutedEventArgs e) { Book book = new Book { CategoryId = _selectedCategoryId, Title = uxAddBookTitle.Text, Author = uxAddBookAuthor.Text, ISBN = uxAddBookISBN.Text }; var result = BooksManager.BooksManager.InsertBook(book); if (result.Result == OperationResult.Passed) { uxAddBookTitle.Text = String.Empty; uxAddBookAuthor.Text = String.Empty; uxAddBookISBN.Text = String.Empty; RefreshBooksList(new BookFilter {RootCategoryId = _selectedCategoryId}); var x = (uxBooksList.ItemsSource as IList<Book>).FirstOrDefault(b => b.Id == book.Id); uxBooksList.CurrentItem = x; uxBooksList.SelectedItem = x; uxBooksList.UpdateLayout(); uxBooksList.ScrollIntoView(x); } else MessageBox.Show(result.OperationMessage); }