public async Task <string> AddBook(Books.Book book) { book.LastUpdate = DateTime.Now; if (CrossConnectivity.Current.IsConnected) { (bool success, string res) = await booksService.AddBook(book, User); if (success) { book.BookKey = res; } else { return(res); } } else { //temporary local UID book.BookKey = Guid.NewGuid().ToString(); } localBooks.AddBook(book, User.Id); return(null); }
public void CallDataBooksAddMethodWithBookWithCorrectProperties() { // Arrange var bookModel = new BookModel() { Title = "Title", Author = "TheAuthor", Description = "Some description", GenreId = 5, PublishedOn = new DateTime(2014, 3, 5) }; var filename = "pic.jpg"; var mockedData = new Mock <IBetterReadsData>(); Book addedBook = null; mockedData.Setup(x => x.Books.Add(It.IsAny <Book>())) .Callback((Book book) => addedBook = book); var service = new BooksService(mockedData.Object); // Act service.AddBook(bookModel, filename); // Assert Assert.AreEqual(bookModel.Title, addedBook.Title); Assert.AreEqual(bookModel.Author, addedBook.Author); Assert.AreEqual(bookModel.Description, addedBook.Description); Assert.AreEqual(bookModel.GenreId, addedBook.GenreId); Assert.AreEqual(bookModel.PublishedOn, addedBook.PublishedOn); Assert.AreEqual(filename, addedBook.CoverFile); }
private void AddBook(object sender, RoutedEventArgs e) { Models.Book book = new Models.Book(); book.Title = BookTitle.Text; _booksService.AddBook(book); BookTitle.Text = string.Empty; BookList.ItemsSource = _storeLogic.GetInventory(); }
public void ThrowArgumentNullExceptionWithProperMessageWhenBookIsNull() { var mockedRepository = new Mock <IRepository <Book> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var booksService = new BooksService(mockedRepository.Object, mockedUnitOfWork.Object); Assert.That(() => booksService.AddBook(null), Throws.ArgumentNullException.With.Message.Contains("book")); }
public IHttpActionResult PostBook(VMBook book) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } bService.AddBook(book); return(CreatedAtRoute("DefaultApi", new { id = book.BookID }, book)); }
public void Post([FromBody] CreateBookData data) { if (!ModelState.IsValid) { throw new InvalidOperationException("You must specify book creation data!"); } _booksService.AddBook(data); }
public ActionResult Create(VMBook vmbook) { if (ModelState.IsValid) { booksService.AddBook(vmbook); return(RedirectToAction("Index")); } return(View(vmbook)); }
public void CallUnitOfWorkCommintMethodWhenBookParameterIsValid() { var mockedRepository = new Mock <IRepository <Book> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var booksSercvice = new BooksService(mockedRepository.Object, mockedUnitOfWork.Object); var mockedBook = new Mock <Book>(); booksSercvice.AddBook(mockedBook.Object); mockedUnitOfWork.Verify(x => x.Commit(), Times.Once()); }
public void CallDataSaveChanges() { // Arrange var mockedData = new Mock <IBetterReadsData>(); mockedData.Setup(x => x.Books.Add(It.IsAny <Book>())).Verifiable(); mockedData.Setup(x => x.SaveChanges()).Verifiable(); var service = new BooksService(mockedData.Object); // Act service.AddBook(new BookModel(), "filename"); // Assert mockedData.Verify(x => x.SaveChanges(), Times.Once); }
public void SaveBook() { if (_currentMode == EditMode.Edit) { _booksService.CurrentBook.Title = _bookView.TextTitle.Text; _booksService.CurrentBook.Publisher = _bookView.TextPublisher.Text; } else if (_currentMode == EditMode.CreateNew) { _newBook.Title = _bookView.TextTitle.Text; _newBook.Publisher = _bookView.TextPublisher.Text; _booksService.AddBook(_newBook); } SetMode(EditMode.View); }
private void OnSave(object sender, RoutedEventArgs e) { if (_currentMode == EditMode.Edit) { _booksService.CurrentBook.Title = textTitle.Text; _booksService.CurrentBook.Publisher = textPublisher.Text; } else if (_currentMode == EditMode.CreateNew) { _newBook.Title = textTitle.Text; _newBook.Publisher = textPublisher.Text; _booksService.AddBook(_newBook); } SetMode(EditMode.View); }
public async Task AddBook_ValidBook_SaveChanges() { // Arrange var data = new List <Book> { }; var dbset = GenerateEnumerableDbSetMock(data.AsQueryable()); var context = GenerateEnumerableContextMock(dbset); var booksService = new BooksService(context.Object); // Act await booksService.AddBook(new BookBuilder().Build()); // Assert context.Verify(x => x.SaveChangesAsync(It.IsAny <CancellationToken>()), Times.Once); }
public async Task AddBook_ValidBook_AddsOnceToDbset() { // Arrange var book = new BookBuilder().WithId(1).Build(); var data = new List <Book> { new BookBuilder().Build(), new BookBuilder().Build(), }; var dbset = GenerateEnumerableDbSetMock(data.AsQueryable()); var context = GenerateEnumerableContextMock(dbset); var booksService = new BooksService(context.Object); // Act await booksService.AddBook(book); // Assert dbset.Verify(x => x.Add(book), Times.Once); }
private void BtnClick_Add(object sender, RoutedEventArgs e) { // get the selected Book Book newBook = new Book(); if (ValidateInputs()) { newBook.Title = uiTextTitle.Text; newBook.AuthorFirstname = uiTextAuthorFirstname.Text; newBook.AuthorLastname = uiTextAuthorLastname.Text; newBook.Isbn = int.Parse(uiTextIsbn.Text); if (_booksService.AddBook(newBook) == false) { MessageBox.Show("Error: The book was not added, ISBN number already exists in list."); } CollectionViewSource.GetDefaultView(uiBookslist.ItemsSource).Refresh(); } }
/// <summary> /// Load local database from user /// </summary> /// <returns></returns> public async static void UpdateLocalDb() { try { BUser bUser = new BUser(); BooksService booksService = new BooksService(); LocalBooks localBooks = new LocalBooks(); BBooks bBooks = new BBooks(); //todo - get user by signin email User user = bUser.GetUserLocal(); bool ContinuosProcess = true; while (ContinuosProcess) { //User not logged if (user == null) { break; } Synchronizing = true; if (CrossConnectivity.Current.IsConnected) { DateTime LastUptade = user.LastUpdate; List <Books.Book> booksList = await localBooks.GetBooksLocalByLastUpdate(user.Id, user.LastUpdate); //update fb database foreach (Books.Book book in booksList) { //if the book has a local temporary Guid key, register it in the firebase if (Guid.TryParse(book.BookKey, out Guid localBookId)) { //define the key has a null for register the book in firebase book.BookKey = null; (bool success, string res) = await booksService.AddBook(book, user); if (success) { localBooks.UpdateLocalBookKey(localBookId, res, user.Id); } else { throw (new Exception($"Não foi possivel sincronizar o livro {book.BookKey}, res: {res}")); } } else { localBooks.UpdateBook(book, user.Id); } } foreach (Books.Book book in await booksService.GetBooksByLastUpdate(user)) { localBooks.SyncUpdateBook(book, user.Id); if (LastUptade < book.LastUpdate) { LastUptade = book.LastUpdate; } } bUser.UpdateUserLastUpdateLocal(user.Id, LastUptade); } Synchronizing = false; //in a interval of thre minutes check updates await Task.Delay(180000); } } catch (Exception ex) { throw ex; } }
public void OnAddBook() => _booksService.AddBook(new Book(GetNextBookId(), $"Professional C# {GetNextBookId() + 3}", "Wrox Press"));
public void InsertTitle(string title) { _booksService.AddBook(new Book { Title = title, Category = "Undefined" }); }
public void Post([FromBody] Book book) { _booksService.AddBook(book); }
public IActionResult AddBook([FromBody] BookDTO book) { _bookSerivce.AddBook(book); return(Ok()); }
private void OnAddBook(object sender, RoutedEventArgs e) { _booksService.AddBook(new Book(GetNextBookId(), $"Professional C# {GetNextBookId() + 3}", "Wrox Press")); }
public IActionResult AddBook([FromBody] BookVM book) { _bookservice.AddBook(book); return(Ok()); }