static void Main(string[] args) { IBookStorage bookStorage = new BinaryBookStorage("Storage10.bin"); IBookService bookService = new BookService(bookStorage); bookService.AddBook(new Book("978-3-16-123451-0", "Dostoevski", "one", "Minsk", 2000, 1000, 100)); bookService.AddBook(new Book("978-3-16-123452-1", "Strygacki", "two", "Gomel", 2001, 2000, 200)); bookService.AddBook(new Book("978-3-16-123453-2", "Kosh", "three", "Brest", 2002, 3000, 300)); bookService.AddBook(new Book("978-3-16-123454-3", "Bulgakov", "four", "Vitebsk", 2003, 4000, 400)); var book = new List <Book>(); book.Add(bookService.FindBook(new FindBookByName("one", bookService.GetAllBooks().ToList()))); //book.Add(bookService.FindBook(new FindBookByIsbn("978-3-16-123455-4", // bookService.GetAllBooks().ToList()))); PrintBook(book); //bookService.Sort(null); //PrintBook(bookService.GetAllBooks()); //bookService.Save(); Console.ReadKey(); }
private static void Main() { Console.WriteLine("Hello Books!"); ILibrary repository = new LibraryRepository(); var bookService = new BookService(repository); try { Console.WriteLine(bookService.Get(bookService.GetLastId() + 1000).Title); } catch (Exception e) { Console.WriteLine(e.Message); } bookService.AddBook("War and piece, part 1."); Console.WriteLine(bookService.Get(bookService.GetLastId()).Id.ToString(), bookService.Get(bookService.GetLastId()).Title); bookService.AddBook("War and piece, part 2."); Console.WriteLine(bookService.Get(bookService.GetLastId()).Id.ToString(), bookService.Get(bookService.GetLastId()).Title); OutBooks(bookService); Console.WriteLine("*".PadRight(20, '*')); bookService.EditBook(bookService.GetLastId()); OutBooks(bookService); Console.WriteLine("*".PadRight(20, '*')); bookService.DeleteBook(bookService.GetLastId()); OutBooks(bookService); Console.WriteLine(); }
public void CreateBookWithNoTitle() { Assert.Throws <Exception>( () => bookService.AddBook(new Book { Title = "" }) ); }
public void InitialisationsTestMethod() { IService service = new BookService(this.path); service.AddBook(new Book("Толстой", "Война и мир", 1, 1824, 750, (decimal)19.38)); service.AddBook(new Book("Кук", "Черный отряд", 2, 2004, 350, (decimal)10.96)); service.AddBook(new Book("Кинг", "Оно", 3, 2012, 750, (decimal)30)); service.AddBook(new Book("Степанов", "Порт Артур", 4, 1905, 480, (decimal)29.76)); }
static void Main(string[] args) { logger.Debug("The program has been started."); logger.Debug("Attempt to create objects"); IBookListStorage bookListStorage = new BookListToBinary("storage.dat"); IBookListService bookService = new BookService(bookListStorage); logger.Debug($"Objects have been created."); logger.Debug($"Attempt to add new books..."); try { logger.Info("Adding new books..."); bookService.AddBook(new Book("918-1-16197-276-1", "Джеффри Рихтер", "CLR via C#", "Питер", 2016, 896, 55)); bookService.AddBook(new Book("928-2-26197-376-2", "Джон Скит", "C# программирование для профессионалов", "Вильямс", 2018, 608, 68)); bookService.AddBook(new Book("938-3-36197-476-3", "Марк Дж. Прайс", "C# 7 и .NET Core.", "Питер", 2018, 640, 75)); bookService.AddBook(new Book("948-4-46197-576-4", "Эндрю Троелсен", "Язык программирования C# 6.0", "Вильямс", 2017, 1440, 123)); bookService.AddBook(new Book("958-5-56197-676-5", "Герберт Шилдт", "C# 4.0. Полное руководство", "Вильямс", 2015, 1056, 60)); logger.Info("New books have been added."); } catch (Exception e) { logger.Warn($"Book has not been added to list: {e.Message}"); } var findBook = new List <Book>(); findBook.Add(bookService.FindBookByTag("CLR via C#")); GetFindBook(findBook); logger.Debug($"Attempt to save book list..."); try { logger.Info("Save books..."); bookService.SaveBooskInStorage(); } catch (IOException e) { logger.Warn($"Failed to save book list: {e.Message}"); } Console.ReadLine(); }
public async Task AddBook_InvalidAuthorId_Exception(string title, int badId) { //Arrange->Preparing variables and objects for tests Mock <IBookRepository> fakeBookRepo = new Mock <IBookRepository>(); Mock <ILibraryLogRepository> fakeLogRepo = new Mock <ILibraryLogRepository>(); BookService bookService = new BookService(fakeBookRepo.Object, fakeLogRepo.Object); //Act->Calling all methods await bookService.AddBook(title, badId); //Assert->Verify result Assert.ThrowsAsync <ArgumentException>(() => bookService.AddBook(title, badId)); }
public void AddBook() { // Arrange var context = new Mock <IBookRankingDbContext>(); var mockMapper = new Mock <IMapper>(); var bookDTOMock = new Mock <BookDTO>(); bookDTOMock.SetupGet(t => t.Title).Returns("zoro"); var bookMock = new Mock <Book>(); mockMapper.Setup(m => m.Map <Book>(bookDTOMock.Object)).Returns(bookMock.Object); var books = new FakeDbSet <Book>(); context.Setup(c => c.Books).Returns(books); var publisherService = new PublisherService(context.Object, mockMapper.Object); var authorService = new AuthorService(context.Object, mockMapper.Object); var service = new BookService(authorService, publisherService, context.Object, mockMapper.Object); // Act service.AddBook(bookDTOMock.Object); // Assert Assert.IsTrue(context.Object.Books.Contains(bookMock.Object)); }
public void UpdateBook_ExistingBook_ReturnsGetBookDto() { AddBookDto newBook = BookTestData.AddBookDto(); mapperMock.Setup(m => m.Map <Book>(It.IsAny <AddBookDto>())).Returns(BookTestData.Book()); mapperMock.Setup(m => m.Map <UpdateBookDto>(It.IsAny <GetBookDto>())).Returns(BookTestData.AddBookDtoToUpdateBookDtoMapping()); mapperMock.Setup(m => m.Map <GetBookDto>(It.IsAny <Book>())).Returns(BookTestData.AddBookDtoToGetBookDtoMapping()); BookService bookService = new BookService(mapperMock.Object, dbContextMock.Object); ServiceResponse <List <GetBookDto> > addBookResponse = bookService.AddBook(newBook); GetBookDto addedBook = addBookResponse.Data.First(); UpdateBookDto updatedBook = mapperMock.Object.Map <UpdateBookDto>(addedBook); updatedBook.Price = 900; ServiceResponse <GetBookDto> updatedBookResponse = bookService.UpdateBook(updatedBook); GetBookDto savedBook = updatedBookResponse.Data; Assert.That(updatedBookResponse.Success, Is.EqualTo(true)); Assert.That(updatedBookResponse, Is.InstanceOf <ServiceResponse <GetBookDto> >()); Assert.That(savedBook, Is.InstanceOf <GetBookDto>()); Assert.That(savedBook.Price, Is.EqualTo(updatedBook.Price)); }
static void Main(string[] args) { Book book1 = new Book("123-4-56-78910-1", "Author1", "title1", "publisher1", 2012, 345, 56.10m); Console.WriteLine(book1.ToString("G", null)); Console.WriteLine(book1.ToString("AT", null)); Console.WriteLine(book1.ToString("ATPYP", null)); Book book2 = new Book("123-4-56-78910-2", "Author1", "title2", "publisher2", 2012, 1051, 78.10m); Book book3 = new Book("123-4-56-78910-3", "Author2", "title3", "publisher1", 2015, 1237, 45.10m); List <Book> books = new List <Book> { book1, book2 }; BookService service = new BookService(books, new NLogger(), new BookListStorage(@"storage.bin")); Show(service); service.AddBook(book3); Show(service); service.SaveToStorage(); service.FindBookByTag(new AuthorNamePredicate("Author1")); service.RemoveBook(book1); Show(service); Console.ReadKey(); }
public void PostBook([FromBody] JObject book) { Console.WriteLine(book.ToString()); // var temp = book.Value<JArray>("Categories"); string categories = string.Join(",", book.Value <JArray>("Categories")); var newBook = new Book() { ISBN = book.Value <string>("ISBN"), Title = book.Value <string>("Title"), Description = book.Value <string>("Description"), Language = "English", ImageLink = book.Value <string>("ImageLink"), Publisher = book.Value <string>("Publisher"), AverageRating = book.Value <double>("AverageRating"), RatingsCount = book.Value <int>("RatingsCount"), PublishedDate = book.Value <DateTime>("PublishedDate"), Categories = categories }; var authors = book.Value <JArray>("Author"); int i = 1; var Authors = authors.Select(auth => new BooksAuthor() { AuthorName = auth.ToString(), AuthorOrdinal = i++, ISBN = newBook.ISBN }); bookService.AddBook(newBook, Authors); }
public void AddExistsBookTest() { IService service = new BookService(this.path); var result = service.AddBook(new Book("Кук", "Черный отряд", 2, 2004, 350, (decimal)10.96)); Assert.That(result, Is.False); }
public void AddBook_NullArgument_Exception() { _mockBookRepository.Setup(w => w.GetAll()).ReturnsAsync(_books); _mockBookRepository.Setup(w => w.Add(It.IsAny <Book>())).ReturnsAsync(_book); using var bookService = new BookService(_mockBookRepository.Object, _mapper); Assert.ThrowsAsync <CustomException>(() => bookService.AddBook(null)); }
public void AddBookTest() { IService service = new BookService(this.path); var result = service.AddBook(new Book("Дойл", "Шерлок Холмс", 5, 1960, 80, (decimal)40.81)); Assert.That(result, Is.True); }
public void DeleteBookByTitleTest() { Assert.IsTrue(BookService.AddBook("J.K. Rowling", "Harry ------ Potter", 1997, "Fantasy", 5)); //delete to restore original db Assert.IsTrue(BookService.DeleteBook("Harry ------ Potter")); }
static void Main(string[] args) { var bookService = new BookService("mongodb://localhost:27017/"); bookService.AddBook("War and Peace"); bookService.BorrowBook("War and Peace", "John Doe"); }
private void Save() { using (var transaction = new TransactionScope()) { foreach (var item in books) { if (item.CrudType == BookCoreLibrary.Core.CRUDType.INSERT) { item.Idx = viewModel.AddBook(item); if (item.Idx > 0) { item.CrudType = BookCoreLibrary.Core.CRUDType.NONE; } } else if (item.CrudType == BookCoreLibrary.Core.CRUDType.MODIFY) { if (viewModel.ModifyBook(item)) { item.CrudType = BookCoreLibrary.Core.CRUDType.NONE; } } } transaction.Complete(); } }
protected async Task HandleValidSubmit() { if (Id == 0) { var addedBook = await BookService.AddBook(OneBook); if (addedBook != null) { StatusClass = "uk-text-success"; Message = "New book added successfully"; StateHasChanged(); await Task.Delay(2000); NavigationManager.NavigateTo("/admin/books"); } else { StatusClass = "uk-text-danger"; Message = "Something went wrong"; } } else { await BookService.UpdateBook(OneBook); StatusClass = "uk-text-success"; Message = "Book updated successfully"; StateHasChanged(); await Task.Delay(1000); NavigationManager.NavigateTo("/admin/books"); } }
public void AddBookToDatabaseTest() { Assert.IsTrue(BookService.AddBook("J.K. Rowling", "Harry ------ Potter", 1997, "Fantasy", 5)); Assert.AreEqual(BookService.GetAllBooksNumber(), 6); //delete to restore original db Assert.IsTrue(BookService.DeleteBook("Harry ------ Potter")); }
public void InsertBookShouldFailWhenBookIsNull() { var service = new BookService(); Assert.That(() => service.AddBook(null), Throws.Exception .TypeOf <ArgumentNullException>()); }
public string AddBook(string name, string author) { BookService.AddBook(new Book() { Author = author, Name = name }); return(All()); }
//یک کتاب به نویسندگی فروغ فرخزاد با عنوان دیوان اشعار فروغ //و رنج سنی بالای 15 سال در فهرست کتاب ها و در دسته شعر و ادبیات تعریف میکنم private async void When() { var addDto = BookDtoFactory.GenerateAddBookDto(_bookCategory.Id , 15 , "فروغ فرخزاد", "دیوان اشعارفروغ"); _bookId = await _sut.AddBook(addDto); }
public ActionResult AddBook(BookAddModel addModel) { try { ValidateAddBookModel(addModel); Book model = NewBook(); model.BookName = addModel.BookName; string pdfDir = bookService.GetUploadDir(); //Directory.CreateDirectory(pdfDir); model.BookPath = pdfDir + addModel.File.FileName; string saveDir = bookService.GetSWFDir(); //Directory.CreateDirectory(saveDir); model.SwfPath = saveDir + $"{Guid.NewGuid().ToString().Replace("-", "")}.swf"; model.ConvertStatus = Enum.ConvertStatusEnum.UnStart; model.DeleteFlag = Enum.DeleteFlagEnum.UnDeleted; model.UploadTime = DateTime.Now; var bookId = bookService.AddBook(model); ViewBag.BookId = bookId; SaveFileToDisk(addModel.File, model.BookPath); Task.Run(() => { try { bookService.UpdateBookConvertStatus(bookId, ConvertStatusEnum.Converting); ConvertPdfToSWF(model.BookPath, model.SwfPath); bookService.UpdateBookConvertStatus(bookId, ConvertStatusEnum.Finished); } catch (Exception ex) { Logger.Log($"swf:{model.SwfPath} {ex.Message}"); bookService.UpdateBookConvertStatus(bookId, ConvertStatusEnum.Failed); } }); //return Json(new { code = 1 }); ViewBag.Msg = "上传成功"; return(View()); } catch (ValidateException ex) { ViewBag.Msg = ex.Message; //return Json(new { code = ex.Code, msg = ex.Message }); return(View()); } catch (Exception ex) { ViewBag.Msg = ex.Message; //return Json(new { code = 0, msg = ex.Message }); return(View()); } }
public void Create(string models) { List <BookViewModel> books = JsonConvert.DeserializeObject <List <BookViewModel> >(models); foreach (BookViewModel bvm in books) { _bookService.AddBook(bvm); } }
public IActionResult AddBook(BookInputModel model) { if (ModelState.IsValid) { _bookService.AddBook(model); return(RedirectToAction("Index")); } return(View()); }
public IActionResult AddBook(InputBookModel book) { if (ModelState.IsValid) { _bookService.AddBook(book); } return(RedirectToAction("AddBook")); }
public void ShouldAddBook() { var book = Builder <Book> .CreateNew().Build(); context.Setup(t => t.Add(It.IsAny <Book>())); service.AddBook(book); context.Verify(c => c.Add(It.IsAny <Book>()), Times.Once); }
public void InsertBookShouldUpdateBookId() { var newBook = CreateBook((book) => book.BookId = 0); var service = new BookService(); var insertedBook = service.AddBook(newBook); Assert.That(newBook.BookId != 0, () => "BookId should be updated by AddBook"); }
private void btnInsert_Click(object sender, RoutedEventArgs e) { var service = new BookService(); var location = comboLocation.SelectedValue; service.AddBook(new BookManagerBL.DAL.Book { Title = txtTitle.Text, PublishedYear = int.Parse(txtPublishedYear.Text), LocationId = (int)comboLocation.SelectedValue, PublisherId = (int)comboPublisher.SelectedValue }); this.Close(); }
public IActionResult Create(BookInputModel model) { //This adds another book to the database if (!ModelState.IsValid) { return(View()); } _bookService.AddBook(model); return(RedirectToAction("Index", "User")); }
protected void btnAdd_Click(object sender, EventArgs e) { BookService BookData = new BookService(); int BookID = int.Parse(txtBookID.Text); string BookTitle = txtBookTitle.Text; float BookPrice = float.Parse(txtBookPrice.Text); BookData.AddBook(BookID, BookTitle, BookPrice); LoadData(); }