Пример #1
0
        public void Delete_Removes_Correct_Book()
        {
            // Arrange
            LibraryContextMock mockContext = new LibraryContextMock();
            BookRepository     repo        = new BookRepository(mockContext);
            Book newBook1 = new Book()
            {
                id = 0, title = "Test1"
            };
            Book newBook2 = new Book()
            {
                id = 1, title = "Test2"
            };
            Book newBook3 = new Book()
            {
                id = 2, title = "Test3"
            };

            repo.Add(newBook1);
            repo.Add(newBook2);
            repo.Add(newBook3);

            // Act
            repo.Remove(1);
            IEnumerable <Book> books = repo.GetAll();

            // Asert
            Assert.Equal(new Book[] { newBook1, newBook3 }, books.ToArray());
        }
Пример #2
0
        public void Delete_Removes_Correct_Book()
        {
            // Arrange
            BookRepository repo     = new BookRepository();
            Book           newBook1 = new Book()
            {
                Title = "Test1"
            };
            Book newBook2 = new Book()
            {
                Title = "Test2"
            };
            Book newBook3 = new Book()
            {
                Title = "Test3"
            };

            repo.Add(newBook1);
            repo.Add(newBook2);
            repo.Add(newBook3);

            // Act
            repo.Remove(1);
            IEnumerable <Book> books = repo.GetAll();

            // Asert
            Assert.Equal(new Book[] { newBook1, newBook3 }, books.ToArray());
        }
Пример #3
0
        protected void BuildBooks()
        {
            PageRepository.DeleteAll();
            BookRepository.DeleteAll();

            Console.WriteLine("Add books");

            Book b = new Book("mexikansk-mad", "Mexikansk mad", "En samling af mine yndlingsopskrifter fra Mexiko",
                              TestDataConstants.Profiles.SimonProfileId);

            b.PublishedDate = DateTime.UtcNow;

            Page p1 = new TextPage("Velbekomme", 1, "Demo");

            PageRepository.Add(p1);
            b.AddPage(p1.Id);

            RecipePage p2 = new RecipePage(MexicanskeBurritosRecipe.Title, 2, MexicanskeBurritosRecipe.Id);

            PageRepository.Add(p2);
            b.AddPage(p2.Id);

            RecipePage p3 = new RecipePage(BonneMosRecipe.Title, 3, BonneMosRecipe.Id);

            PageRepository.Add(p3);
            b.AddPage(p3.Id);

            BookRepository.Add(b);
        }
Пример #4
0
        public BookstoreMutation(AuthorRepository authorRepository, BookRepository bookRepository)
        {
            Field <AuthorType>("createAuthor",
                               arguments: new QueryArguments(new QueryArgument <NonNullGraphType <AuthorInputType> > {
                Name = "input"
            }),
                               resolve: context => {
                return(authorRepository.Add(context.GetArgument <Author>("input")));
            });
            Field <AuthorType>("updateAuthor",
                               arguments: new QueryArguments(
                                   new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "id"
            },
                                   new QueryArgument <NonNullGraphType <AuthorInputType> > {
                Name = "input"
            }
                                   ),
                               resolve: context => {
                var id     = context.GetArgument <long>("id");
                var author = context.GetArgument <Author>("input");
                return(authorRepository.Update(id, author));
            });
            Field <AuthorType>("deleteAuthor",
                               arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "id"
            }),
                               resolve: context => {
                return(authorRepository.Remove(context.GetArgument <long>("id")));
            });

            Field <BookType>("createBook",
                             arguments: new QueryArguments(new QueryArgument <NonNullGraphType <BookInputType> > {
                Name = "input"
            }),
                             resolve: context => {
                return(bookRepository.Add(context.GetArgument <Book>("input")));
            });
            Field <BookType>("updateBook",
                             arguments: new QueryArguments(
                                 new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "id"
            },
                                 new QueryArgument <NonNullGraphType <BookInputType> > {
                Name = "input"
            }
                                 ),
                             resolve: context => {
                var id   = context.GetArgument <long>("id");
                var book = context.GetArgument <Book>("input");
                return(bookRepository.Update(id, book));
            });
            Field <BookType>("deleteBook",
                             arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "id"
            }),
                             resolve: context => {
                return(bookRepository.Remove(context.GetArgument <long>("id")));
            });
        }
Пример #5
0
        public void CanAddNewBook()
        {
            var page = new Page {
                FileName = "test_filename", Number = 1
            };

            page.AddLine(new Line {
                Number = 1
            });
            var book = new Book {
                Directory = "test", Name = "test"
            };

            book.AddPage(page);
            var repository = new BookRepository(DbFile);

            repository.Add(book);

            using (var session = _sessionFactory.OpenSession())
            {
                var fromDb = session.Get <Book>(book.UID);

                Assert.IsNotNull(fromDb);
                Assert.AreNotSame(book, fromDb);
                Assert.AreEqual(book.Name, fromDb.Name);
                Assert.AreEqual(book.Directory, fromDb.Directory);
                Assert.AreEqual(book.Pages[0].Number, fromDb.Pages[0].Number);
                Assert.AreEqual(book.Pages[0].FileName, fromDb.Pages[0].FileName);
                Assert.AreEqual(book.Pages[0].Lines[0].Number, fromDb.Pages[0].Lines[0].Number);
            }
        }
Пример #6
0
        public IActionResult Create([FromBody] Book item)
        {
            if (item == null)
            {
                return(BadRequest());
            }

            Library librarydetails = new Library();

            if (item.librarydetails != null)
            {
                librarydetails.libraryid = item.librarydetails.libraryid;
            }
            Book book = new Book();

            book.title          = item.title;
            book.publisheddate  = item.publisheddate;
            book.librarydetails = librarydetails;
            book.bookauthors    = item.bookauthors;

            var createdBook = _bookRepository.Add(book);

            if (createdBook == null)
            {
                return(Ok("Author doesn't exist!"));
            }

            return(CreatedAtRoute("GetBook", new { id = createdBook.bookid }, createdBook));
        }
Пример #7
0
        public ActionResult Create([Bind(Include = "BookId,Name,Description,BookGenderId")] Book book, HttpPostedFileBase ImageFile, string hiddenArray)
        {
            if (ModelState.IsValid)
            {
                var items = JsonConvert.DeserializeObject <List <Comment> >(hiddenArray);

                if (ImageFile != null)
                {
                    book.ImageUrl = Utils.Instance.moveMyImage(ImageFile, User.Identity.Name);
                }

                foreach (Comment com in items)
                {
                    book.Comments.Add(com);
                }

                repository.Add(book);
                repository.SaveChanges();

                return(RedirectToAction("Index"));
            }

            ViewBag.BookGenderId = new SelectList(repository.getAllBookGenders(), "BookGenderId", "Name", book.BookGenderId);
            return(View(book));
        }
Пример #8
0
        public Book Add(string title, string name)
        {
            var author = authorRepository.AuthorWithName(name);
            var book   = new Book(title, author);

            return(bookRepository.Add(book));
        }
        private void BookMutations()
        {
            FieldAsync <BookType>("createBook",
                                  arguments: new QueryArguments(new QueryArgument <NonNullGraphType <BookInputType> > {
                Name = "input"
            }),
                                  resolve: async context => {
                return(await context.TryAsyncResolve(async c => await _bookRepository.Add(context.GetArgument <Book>("input"))));
            });

            FieldAsync <BookType>("updateBook",
                                  arguments: new QueryArguments(
                                      new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "id"
            },
                                      new QueryArgument <NonNullGraphType <BookInputType> > {
                Name = "input"
            }
                                      ),
                                  resolve: async context => {
                var id   = context.GetArgument <long>("id");
                var book = context.GetArgument <Book>("input");
                return(await context.TryAsyncResolve(async c => await _bookRepository.Update(id, book)));
            });

            FieldAsync <BookType>("deleteBook",
                                  arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "id"
            }),
                                  resolve: async context => {
                return(await context.TryAsyncResolve(async c => await _bookRepository.Remove(context.GetArgument <long>("id"))));
            });
        }
Пример #10
0
        public void Update_updates_Correct_Book()
        {
            // Arrange
            LibraryContextMock mockContext = new LibraryContextMock();
            BookRepository     repo        = new BookRepository(mockContext);
            Book newBook = new Book()
            {
                title       = "New title",
                author      = "New author",
                isbn        = "22222",
                publishDate = "2001"
            };
            Book oldBook = new Book()
            {
                title       = "Old title",
                author      = "Old author",
                isbn        = "11111",
                publishDate = "2000"
            };

            repo.Add(oldBook);

            // Act
            repo.Update(newBook, 0);
            IEnumerable <Book> books = repo.GetAll();

            // Asert
            Assert.Equal(new Book[] { newBook }, books.ToArray());
        }
        public void Get_All_Returns_All_Reservations()
        {
            // Arrange
            LibraryContextMock    mockContext = new LibraryContextMock();
            ReservationRepository repo        = new ReservationRepository(mockContext);
            BookRepository        bookRepo    = new BookRepository(mockContext);
            Book newBook = new Book()
            {
                title       = "New title",
                author      = "New author",
                isbn        = "22222",
                publishDate = "2001"
            };
            Reservation newReservation1 = new Reservation()
            {
                book = newBook
            };
            Reservation newReservation2 = new Reservation()
            {
                book = newBook
            };

            bookRepo.Add(newBook);
            repo.Add(newReservation1);
            repo.Add(newReservation2);

            // Act
            IEnumerable <Reservation> Reservations = repo.GetAll();

            // Asert
            Assert.Equal(new Reservation[] { newReservation1, newReservation2 }, Reservations.ToArray());
        }
        public void Get_Returns_Specific_Reservation()
        {
            // Arrange
            LibraryContextMock    mockContext = new LibraryContextMock();
            ReservationRepository repo        = new ReservationRepository(mockContext);
            BookRepository        bookRepo    = new BookRepository(mockContext);
            Book newBook = new Book()
            {
                title       = "New title",
                author      = "New author",
                isbn        = "22222",
                publishDate = "2001"
            };
            Reservation newReservation1 = new Reservation()
            {
                id = 0, book = newBook
            };
            Reservation newReservation2 = new Reservation()
            {
                id = 1, book = newBook
            };

            bookRepo.Add(newBook);
            repo.Add(newReservation1);
            repo.Add(newReservation2);

            // Act
            Reservation Reservation = repo.Get(1);

            // Asert
            Assert.Equal(newReservation2, Reservation);
        }
        public void Put_Doesnt_Update_If_Times_Clash()
        {
            // Arrange
            LibraryContextMock    mockContext = new LibraryContextMock();
            ReservationRepository repo        = new ReservationRepository(mockContext);
            BookRepository        bookRepo    = new BookRepository(mockContext);
            Book newBook = new Book()
            {
                title       = "New title",
                author      = "New author",
                isbn        = "22222",
                publishDate = "2001"
            };
            Reservation Reservation1 = new Reservation()
            {
                book      = newBook,
                startDate = new System.DateTime(2016, 1, 1, 1, 0, 0),
                endDate   = new System.DateTime(2016, 1, 1, 2, 0, 0),
            };
            Reservation Reservation2 = new Reservation()
            {
                book      = newBook,
                startDate = new System.DateTime(2016, 1, 1, 1, 30, 0),
                endDate   = new System.DateTime(2016, 1, 1, 2, 30, 0),
            };

            bookRepo.Add(newBook);
            repo.Add(Reservation1);

            Assert.Throws <InvalidOperationException>(() => repo.Update(Reservation2, 0));
            IEnumerable <Reservation> Reservations = repo.GetAll();

            Assert.Equal(new Reservation[] { Reservation1 }, Reservations.ToArray());
        }
Пример #14
0
        public void AddBook()
        {
            Console.WriteLine("Please enter book Title:");
            var bookTitle = Console.ReadLine().ToUpper();
            var checkBook = BookRepository.GetFirstWhere(x => x.Title == bookTitle);

            if (checkBook != null)
            {
                throw new FlowException("Book already exist!");
            }
            Console.WriteLine("Please enter number of copies:");
            var checkCopies = int.TryParse(Console.ReadLine(), out int bookCopies);

            CheckInput(checkCopies);
            if (bookCopies <= 0)
            {
                throw new FlowException("Please enter amount above 0");
            }
            var bookId     = GenerateBookId();
            var createBook = new Book()
            {
                Id             = bookId,
                Title          = bookTitle,
                NumberOfCopies = bookCopies
            };

            BookRepository.Add(createBook);
            BookRepository.SaveEntities();
            Console.WriteLine("Book successfully added!");
        }
Пример #15
0
        public void Add([FromBody] BookViewModel viewModel)
        {
            Book book = new Book()
            {
                Title          = viewModel.Title,
                PagesCount     = viewModel.PagesCount,
                Price          = viewModel.Price,
                PublishingYear = viewModel.PublishingYear,
                EncodedPhoto   = viewModel.Image,
                Count          = viewModel.Count,
                Description    = viewModel.Description,
                Rating         = 0
            };

            bookRepository.Add(book);

            foreach (string name in viewModel.Authors)
            {
                BookToAuthor bookToAuthor = new BookToAuthor {
                    BookId = book.Id, AuthorId = authorRepository.GetByName(name).Id
                };
                bookToAuthorRepository.Add(bookToAuthor);
            }

            foreach (string genre in viewModel.Genres)
            {
                BookToGenre bookToGenre = new BookToGenre {
                    BookId = book.Id, Genre = (Genre)Enum.Parse(typeof(Genre), genre)
                };
                bookToGenreRepository.Add(bookToGenre);
            }
            ;
        }
Пример #16
0
        public IActionResult Post(Book book)
        {
            var currentUser = GetCurrentUser();

            book.UserId = currentUser.Id;
            _bookRepository.Add(book);
            return(CreatedAtAction("GetByGoogleId", new { googleId = book.GoogleId }, book));
        }
Пример #17
0
        public void AddBook(Book item)
        {
            BookRepository repository = new BookRepository();

            //Gerar novo ID
            item.Id = Guid.NewGuid();
            repository.Add(item);
        }
Пример #18
0
        public async Task <bool> Add(string title, string isbn, string year, List <Guid> authorsIds)
        {
            Guid id = Guid.NewGuid();

            Book book = new Book
            {
                Id      = id,
                Title   = title,
                ISBN    = isbn,
                Year    = year,
                Authors = new List <AuthorBook>()
            };

            List <Guid> validAuthors = new List <Guid>();

            foreach (Guid guid in authorsIds)
            {
                Author author = await AuthorRepository.GetById(guid);

                if (author != null)
                {
                    validAuthors.Add(guid);
                    AuthorBook relationship = new AuthorBook {
                        AuthorId = guid, BookId = id
                    };
                    book.Authors.Add(relationship);
                    if (author.Books == null)
                    {
                        author.Books = new List <AuthorBook>();
                    }
                    author.Books.Add(relationship);
                }
            }

            if (validAuthors.Count == 0)
            {
                return(false);
            }

            bool bookCreated = await BookRepository.Add(book);

            if (!bookCreated)
            {
                return(false);
            }

            foreach (Guid guid in validAuthors)
            {
                bool relationshipCreated = !await AuthorBookRepository.AddBookToAuthor(new AuthorBook { AuthorId = guid, BookId = id });

                if (!relationshipCreated)
                {
                    return(false);
                }
            }

            return(bookCreated);
        }
        public PurchaseDetail SavePaymentDetails(PurchaseDetail purchaseDetail)
        {
            BookDbContext   context        = new BookDbContext();
            IBookRepository bookRepository = new BookRepository(context);

            PurchaseDetail opurchaseDetail = bookRepository.Add(purchaseDetail);

            return(opurchaseDetail);
        }
Пример #20
0
 public bool Add(Book b)
 {
     if (_booksRepo.GetBooks().SingleOrDefault(x => x.Isbn == b.Isbn) == null)
     {
         _booksRepo.Add(b);
         return(true);
     }
     return(false);
 }
Пример #21
0
        public void Add(PostBookViewModel bookView)
        {
            Book book = Mapper.Map <PostBookViewModel, Book>(bookView);

            book.PublicationType = PublicationType.Book;
            _bookRepository.Add(book);

            AddRelationshipsBookPublisher(book, bookView.Publishers);
            AddRelationshipsBookAuthor(book, bookView.Authors);
        }
Пример #22
0
        public void ThrowException_WhenBookPreconditionDontFulfill()
        {
            BookRepository bookRepository = new BookRepository();
            Book           b2             = new Book
            {
                ISBN = "3232",
            };

            bookRepository.Add(b2);
        }
        public void AddUserMustAddUserWhenSaveChangesCalled()
        {
            BookRepository repository = new BookRepository(new MockBookContext {
                Books = new MockDbSet <Book>()
            });
            Guid id = Guid.NewGuid();

            repository.Add(new Book("Goodnight Moon", "Margaret Wise Brown", id));
            Assert.Equal("Goodnight Moon", repository.Find(id).Title);
        }
Пример #24
0
        private void btnKitapEkle_Click(object sender, EventArgs e)
        {
            Book b = new Book();

            b.Title      = txtKitapAdi.Text;
            b.CategoryID = Convert.ToInt32(cmbKategori.SelectedValue);
            b.AuthorID   = Convert.ToInt32(cmbYazar.SelectedValue);
            br.Add(b);
            BookList();
        }
Пример #25
0
        public ActionResult AddBook([FromBody] Book book)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            repo.Add(book);
            book.Description = "";
            return(Accepted(book));
        }
Пример #26
0
        public void Add_Book_CountIncreaseOne()
        {
            var before = repository.FindAll().Count;

            repository.Add(book);
            var after = repository.FindAll().Count;

            var actual = after - before;

            Assert.AreEqual(1, actual);
        }
Пример #27
0
        public void Add_CheckNumberofElements()
        {
            BookRepository bookRepository = new BookRepository();
            Book           b1             = new Book
            {
                ISBN  = "1232132",
                Title = "Clean Code"
            };

            bookRepository = new BookRepository();
            Book b2 = new Book
            {
                ISBN  = "3232",
                Title = "Refactoring"
            };

            bookRepository.Add(b1);
            bookRepository.Add(b2);
            Assert.AreEqual(2, bookRepository.Count);
        }
Пример #28
0
        public IActionResult Create([FromBody] Book book)
        {
            if (book == null)
            {
                return(BadRequest());
            }

            Book addedBook = _bookRepository.Add(book);

            return(Created("book", addedBook));
        }
Пример #29
0
        static void Main(string[] args)
        {
            var a = new BookRepository(new JsonFileHandler());

            a.Add(new Book {
                Title = "asf", Id = 423
            });

            a.SaveChanges();
            Console.ReadKey();
        }
        public void SaveChanges_BookAdded_ShouldSaveWithBook()
        {
            var fileHandlerMock = new Mock <IFileHandler>();
            var subject         = new BookRepository(fileHandlerMock.Object);

            subject.Add(new Book {
                Id = 2, Title = "Book2"
            });
            subject.SaveChanges();
            fileHandlerMock.Verify(x => x.Save(It.Is <List <Book> >(list => list.Any(y => y.Id == 2))), Times.Once);
        }
 private static BookRepository CreateRepository()
 {
     var repository = new BookRepository();
     repository.Add(new Book("978-0735667457",
         "0735667454",
         "CLR via C#",
         4,
         new DateTime(2012, 12, 4),
         new[] {"testing", "C#", "programming", "windows"}));
     repository.Add(new Book("978-0735662780",
         "0735662789",
         "Inside Windows Debugging",
         1,
         new DateTime(2012, 5, 21),
         new[] {"debugging", "logic", "compiler", "windows"}));
     repository.Add(new Book("978-1617291081",
         "1617291080",
         "Learn Windows PowerShell 3 in a Month of Lunches",
         1,
         new DateTime(2012, 11, 22),
         new[] {"C", "C++", "network", "administration", "windows"}));
     return repository;
 }
Пример #32
0
        private static void Main(string[] args)
        {
            var eventStorage = new EventStorage();
            var query = new BookStateQuery();

            DomainEvents.RegisterHandler(() => new BookStateHandler(query));
            DomainEvents.RegisterHandler(() => new LateReturnNotifier());

            var bookId = BookId.NewBookId();

            using (var session = new Session(eventStorage))
            {
                var books = new BookRepository();
                var book = new Book(bookId,
                    "The Lord of the Rings",
                    "0-618-15396-9");
                books.Add(book);

                session.SubmitChanges();
            }

            ShowBooks(query);

            using (var session = new Session(eventStorage))
            {
                var books = new BookRepository();
                var book = books[bookId];
                book.Lend("Alice",
                    new DateTime(2009, 11, 2),
                    TimeSpan.FromDays(14));

                session.SubmitChanges();
            }

            ShowBooks(query);

            using (var session = new Session(eventStorage))
            {
                var books = new BookRepository();
                var book = books[bookId];
                book.Return(new DateTime(2009, 11, 8));

                session.SubmitChanges();
            }

            ShowBooks(query);

            using (var session = new Session(eventStorage))
            {
                var books = new BookRepository();
                var book = books[bookId];
                book.Lend("Bob",
                    new DateTime(2009, 11, 9),
                    TimeSpan.FromDays(14));

                session.SubmitChanges();
            }

            ShowBooks(query);

            using (var session = new Session(eventStorage))
            {
                var books = new BookRepository();
                var book = books[bookId];
                book.Return(new DateTime(2010, 03, 1));
                session.SubmitChanges();
            }

            ShowBooks(query);
        }