public void AddBookToMyBook(object sender, EventArgs s) { Button btn = (Button)sender; var bookId = int.Parse(btn.AccessibleName); var myBookService = new MyBookService(); var newMyBook = new MyBook(); newMyBook.BookId = bookId; newMyBook.UserId = Global.UserId; myBookService.Add(newMyBook); MessageBox.Show("Successfull added!"); }
public void MyBook() { var mockSet = new Mock <DbSet <MyBook> >(); var mockContext = new Mock <BookContext>(); mockContext.Setup(m => m.MyBooks).Returns(mockSet.Object); var service = new MyBookService(mockContext.Object); service.Add(new MyBook()); mockSet.Verify(m => m.Add(It.IsAny <MyBook>()), Times.Once()); mockContext.Verify(m => m.SaveChanges(), Times.Once()); }