protected async Task HandleValidSubmit() { if (file != null) { EditBookModel.PhotoPath = await FileUpload.Upload(file, EditBookModel); } Mapper.Map(EditBookModel, Book); Book result = null; if (Book.id != 0) { result = await BookServices.UpdateBook(Book); } else { result = await BookServices.AddBook(Book); } if (result != null) { Navigation.NavigateTo("/Books"); } }
public string Post([FromBody] JObject obj) { //var booknumber = int.Parse(obj.GetValue("MyBookProperty").ToString()); //bookList.Add(new Book { MyBookProperty = booknumber }); book.AddBook(obj); return("Post Done"); }
public void Throw_When_Passed_Book_Is_Null() { // Arrange IBookServices sut = new BookServices(repository, saveChanges); Book nullBook = null; // Act & Assert Assert.Throws <ArgumentNullException>(() => sut.AddBook(nullBook)); }
public void Remove_Book_With_Exact_Id() { // Arrange IBookServices sut = new BookServices(repository, saveChanges); sut.AddBook(book); // Act sut.DeleteBookById(book.Id); // Assert CollectionAssert.DoesNotContain(dbContext.Books, book); }
public void Remove_Proper_Book_From_Collection() { // Arrange IBookServices sut = new BookServices(repository, saveChanges); sut.AddBook(book); // Act sut.DeleteBook(book); // Arrange Assert.IsEmpty(dbContext.Books); }
public void Insert_Proper_Entity_In_Collection() { // Arrange IBookServices sut = new BookServices(repository, saveChanges); // Act sut.AddBook(book); Book result = sut.GetById(book.Id); // Assert Assert.IsNotNull(result); }
public void Return_Book_With_Proper_Id() { // Arrange IBookServices sut = new BookServices(repository, saveChanges); sut.AddBook(book); // Act Book result = sut.GetById(book.Id); // Assert Assert.IsNotNull(result); Assert.AreEqual(result.Id, book.Id); }
public void BeCalled_IfPassedBookIsValid() { // Arrange var dbSetMock = new Mock <ILibrarySystemEfWrapper <Book> >(); var saveChangesMock = new Mock <ILibrarySystemEfDbContextSaveChanges>(); var bookServices = new BookServices(dbSetMock.Object, saveChangesMock.Object); var bookToWorkWithMock = new Mock <Book>(); // Act bookServices.AddBook(bookToWorkWithMock.Object); bookServices.DeleteBook(bookToWorkWithMock.Object); // Assert dbSetMock.Verify(r => r.Delete(bookToWorkWithMock.Object), Times.Once); }
public void CallSaveChangesOnce_IfBookIsValid() { // Arrange var dbSetMock = new Mock <ILibrarySystemEfWrapper <Book> >(); var saveChangesMock = new Mock <ILibrarySystemEfDbContextSaveChanges>(); var bookMock = new Mock <Book>(); // Act BookServices bookServices = new BookServices(dbSetMock.Object, saveChangesMock.Object); bookServices.AddBook(bookMock.Object); // Assert saveChangesMock.Verify(s => s.SaveChanges(), Times.Once); }
public void IsAddingCorrectBookToDatabase() { Book book = new Book { Id = 3, Title = "title3", Genre = "genre3" }; bookServices.AddBook(book); bool result = bookServices .GetAllBooks() .Exists(b => b.Id == book.Id); Assert.IsTrue(result); }
private void AddBookButton(object s, RoutedEventArgs e) { _bookServices.AddBook(); Close(); }
private void btnCommit_Click(object sender, EventArgs e) { //【1】 Input for validation //【2】 encapsulation Book objBook = new Book() { BookId = lblBookId.Text, BookName = txtBookName.Text.Trim(), BookType = cboBookTypeTwo.Enabled == true?Convert.ToInt32(cboBookTypeTwo.SelectedValue.ToString()) : Convert.ToInt32(cboBookTypeOne.SelectedValue), ISBN = txtBookISBN.Text, BookAuthor = txtBookAuthor.Text.Trim(), BookPrice = Convert.ToDouble(txtBookPrice.Text.Trim()), BookPress = Convert.ToInt32(cboBookPress.SelectedValue), BookPublishDate = Convert.ToDateTime(dtpPublishDate.Text), StorageInNum = Convert.ToInt32(txtStorageInNum.Text.Trim()), InventoryNum = Convert.ToInt32(lblInventoryNum.Text.Trim()), BorrowedNum = Convert.ToInt32(lblBorrowedNum.Text.Trim()), StorageInDate = Convert.ToDateTime(lblStorageInDate.Text), }; //Picture--> text if (pbCurrentImage.BackgroundImage == null) { objBook.BookImage = null; } else { objBook.BookImage = new Common.SerializeObjectToString().SerializeObject(pbCurrentImage.BackgroundImage); } //Perform switch (actionFlag) { case 2: try { if (objBookServices.AddBook(objBook) == 1) { //Prompt for Success! MessageBox.Show("Successful addition of book information!", "System Information", MessageBoxButtons.OK, MessageBoxIcon.Information); //Close a form Close(); //Return ok this.DialogResult = DialogResult.OK; } } catch (Exception ex) { MessageBox.Show("Error adding book information! Specific errors:" + ex.Message, "System Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } break; case 3: try { if (objBookServices.UpdateBook(objBook) == 1) { //Notice Successful! MessageBox.Show("Successful revision of book information!", "System Information", MessageBoxButtons.OK, MessageBoxIcon.Information); //Close From Close(); //Return OK this.DialogResult = DialogResult.OK; } } catch (Exception ex) { MessageBox.Show("Error in revising book information! Specific errors:" + ex.Message, "System Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } break; } }
public void GetBook_should_return_list_of_books_test() { bookServices.AddBook(expected); Assert.Contains(expected, bookServices.GetBook()); }
public void Post([FromBody] Book value) { bookService.AddBook(value); }