Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
 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();
 }
Exemplo n.º 4
0
        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"));
        }
Exemplo n.º 5
0
 public IHttpActionResult PostBook(VMBook book)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     bService.AddBook(book);
     return(CreatedAtRoute("DefaultApi", new { id = book.BookID }, book));
 }
Exemplo n.º 6
0
        public void Post([FromBody] CreateBookData data)
        {
            if (!ModelState.IsValid)
            {
                throw new InvalidOperationException("You must specify book creation data!");
            }

            _booksService.AddBook(data);
        }
Exemplo n.º 7
0
        public ActionResult Create(VMBook vmbook)
        {
            if (ModelState.IsValid)
            {
                booksService.AddBook(vmbook);
                return(RedirectToAction("Index"));
            }

            return(View(vmbook));
        }
Exemplo n.º 8
0
        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());
        }
Exemplo n.º 9
0
        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);
 }
Exemplo n.º 11
0
 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);
        }
Exemplo n.º 14
0
        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();
            }
        }
Exemplo n.º 15
0
        /// <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; }
        }
Exemplo n.º 16
0
 public void OnAddBook() =>
 _booksService.AddBook(new Book(GetNextBookId(), $"Professional C# {GetNextBookId() + 3}", "Wrox Press"));
Exemplo n.º 17
0
 public void InsertTitle(string title)
 {
     _booksService.AddBook(new Book {
         Title = title, Category = "Undefined"
     });
 }
Exemplo n.º 18
0
 public void Post([FromBody] Book book)
 {
     _booksService.AddBook(book);
 }
Exemplo n.º 19
0
 public IActionResult AddBook([FromBody] BookDTO book)
 {
     _bookSerivce.AddBook(book);
     return(Ok());
 }
Exemplo n.º 20
0
 private void OnAddBook(object sender, RoutedEventArgs e)
 {
     _booksService.AddBook(new Book(GetNextBookId(), $"Professional C# {GetNextBookId() + 3}", "Wrox Press"));
 }
Exemplo n.º 21
0
 public IActionResult AddBook([FromBody] BookVM book)
 {
     _bookservice.AddBook(book);
     return(Ok());
 }