public void AddBook(Book newBook) { XDocument xmlDoc = XMLHelper.LoadDocument(XMLBooksFilePath + XMlBooksFileName); int newId = 1; //Add the root element to the XML doc, if it's empty if (xmlDoc.Element(BooksRoot) == null) { XElement root = new XElement(BooksRoot); xmlDoc.Add(root); } else { //Retrieve the new ID var query = (from item in xmlDoc.Descendants().Elements(BooksID) select int.Parse(item.Value.ToString())).Max(); newId = (int)query + 1; } XElement title = new XElement(BooksTitle, newBook.Title); XElement numberOfPages = new XElement(BooksNumberPages, newBook.NumberOfPages); XElement isbn = new XElement(BooksISBN, newBook.ISBN); XElement ubicacion = new XElement(BooksUbicacion, newBook.Location.ToString()); XElement descripcion = new XElement(BooksDescription, newBook.Description); XElement id = new XElement(BooksID, newId.ToString()); XElement book = new XElement(BooksElement, title, numberOfPages, isbn, ubicacion, descripcion, id); xmlDoc.Element(BooksRoot).Add(book); XMLHelper.SaveDocument(xmlDoc, XMLBooksFilePath + XMlBooksFileName); }
public static void ValidateBook(Book expectedBook, Book actualBook) { Assert.AreEqual(expectedBook.ID, actualBook.ID, "Wrong Book ID"); Assert.AreEqual(expectedBook.ISBN, actualBook.ISBN, "Wrong Book ISBN"); Assert.AreEqual(expectedBook.Location, actualBook.Location, "Wrong Book Location"); Assert.AreEqual(expectedBook.NumberOfPages, actualBook.NumberOfPages, "Wrong Book NumberOfPages"); Assert.AreEqual(expectedBook.Title, actualBook.Title, "Wrong Book Title"); }
public void setup() { Mongo mongo = MongoTestHelper.create_new_database_connection(); mongo.Database.DropCollection(typeof (Book).Name); _book = new Book(); mongo.GetCollection<Book>().Insert(_book); }
public void read_book() { var book = new Book { Title = "Ender's Game", Author = "Orson Scott Card", }; _mongo.GetCollection<Book>().Insert(book); new MongoQuery<Book>(_provider).First().Title.ShouldBe("Ender's Game"); }
public void insert_book_should_set_id() { var book = new Book { Title = "Ender's Game", Author = "Orson Scott Card", }; _mongo.GetCollection<Book>().Insert(book); new MongoQuery<Book>(_provider).First().Id.ShouldNotBe(ObjectId.Empty); }
public void insert_book() { var book = new Book { Title = "Ender's Game", Author = "Orson Scott Card", }; _mongo.GetCollection<Book>().Insert(book); _mongo.GetCollection<Book>().Count().ShouldBe(1); }
public void delete_book() { var book = new Book { Title = "Ender's Game", Author = "Orson Scott Card", }; _mongo.GetCollection<Book>().Insert(book); Book bookToDelete = new MongoQuery<Book>(_provider).First(); _mongo.GetCollection<Book>().Delete(bookToDelete); _mongo.GetCollection<Book>().Count().ShouldBe(0); }
public async Task <Unit> Handle(Command request, CancellationToken cancellationToken) { Domain.Book book = new Domain.Book { Id = request.Id, Title = request.Title, Detail = request.Detail, Gerne = request.Gerne, JAN = request.JAN, Other = request.Other, InsTime = DateTime.Now, UpdTime = DateTime.Now, }; _context.Books.Add(book); var success = await _context.SaveChangesAsync() > 0; if (success) { return(Unit.Value); } throw new Exception("Problem saving changes"); }
public void update_book() { var book = new Book { Title = "Ender's Game", Author = "Orson Scott Card", }; _mongo.GetCollection<Book>().Insert(book); Book bookToUpdate = new MongoQuery<Book>(_provider).First(); bookToUpdate.Title = "Hidden Empire"; _mongo.GetCollection<Book>().Save(bookToUpdate); _mongo.GetCollection<Book>().Count().ShouldBe(1); new MongoQuery<Book>(_provider).First().Title.ShouldBe("Hidden Empire"); }
public void AddBook() { //Create new book Book newBook = new Book() { Description = "Test book", NumberOfPages = 520, ISBN = "4564654", Title = "The book that didn't exist", Location = Lugares.BibliotecaLiving }; XDocument returnedDoc = GetBooksReturnedDocument(); //Create the element for that Book XElement xmlBook = CreateBookItem(newBook.Title, newBook.NumberOfPages, newBook.ISBN, newBook.Location, newBook.Description, 6); //create the expected xmldoc to be saved: XDocument expectedDoc = GetBooksReturnedDocument(); expectedDoc.Element(BooksRoot).Add(xmlBook); using (MockRepository.Record()) { Expect.Call(XMLHelper.LoadDocument(XMLBooksFilePath + XMlBooksFileName)) .Repeat.Times(1) .Return(returnedDoc); Expect.Call(delegate { XMLHelper.SaveDocument(expectedDoc, XMLBooksFilePath + XMlBooksFileName); }) .IgnoreArguments() .Constraints(Property.AllPropertiesMatch(expectedDoc), Property.AllPropertiesMatch(XMLBooksFilePath + XMlBooksFileName)) .Repeat.Once(); } using (MockRepository.Playback()) { RepositoryBook.AddBook(newBook); } }
/// <summary> /// Updated the book with Id = 2 /// </summary> private XDocument GetBooksReturnedDocumentUpdated(Book updatedBook) { XDocument xmlDoc = new XDocument(); XElement book1 = CreateBookItem("El tambor de hojalata", 23, "84-78949-78", Lugares.PiezaAndres, "Libro de Gunter Grass", 1); XElement book2 = CreateBookItem(updatedBook.Title, updatedBook.NumberOfPages, updatedBook.ISBN, updatedBook.Location, updatedBook.Description, updatedBook.ID); XElement book3 = CreateBookItem("El señor de los anillos", 1050, "99-457-847", Lugares.PiezaAndres, "Los tres libros", 3); XElement book4 = CreateBookItem("Rayuela", 556, "99987", Lugares.PiezaAbuela, "De Cortazar", 4); XElement book5 = CreateBookItem("El hombre terminal", 450, "84-454657-k", Lugares.PiezaAndres, "De Michael Crichton", 5); XElement root = new XElement(BooksRoot); xmlDoc.Add(root); xmlDoc.Element(BooksRoot).Add(book1); xmlDoc.Element(BooksRoot).Add(book2); xmlDoc.Element(BooksRoot).Add(book3); xmlDoc.Element(BooksRoot).Add(book4); xmlDoc.Element(BooksRoot).Add(book5); return xmlDoc; }
public void UpdateBook() { XDocument returnedDoc = GetBooksReturnedDocument(); //Update book with Id = 2 Book updatedBook = new Book() { Description = "El nombre de la rosa - Updated", NumberOfPages = 520, ISBN = "4564654", Title = "El nombre de la rosa, updated title", Location = Lugares.BibliotecaLiving, ID = 2 }; //create the expected xmldoc to be saved: XDocument updatedDocs = GetBooksReturnedDocumentUpdated(updatedBook); using (MockRepository.Record()) { Expect.Call(XMLHelper.LoadDocument(XMLBooksFilePath + XMlBooksFileName)) .Repeat.Times(1) .Return(returnedDoc); Expect.Call(delegate { XMLHelper.SaveDocument(updatedDocs, XMLBooksFilePath + XMlBooksFileName); }) .IgnoreArguments() .Constraints(Property.AllPropertiesMatch(updatedDocs), Property.AllPropertiesMatch(XMLBooksFilePath + XMlBooksFileName)) .Repeat.Once(); } using (MockRepository.Playback()) { RepositoryBook.UpdateBook(updatedBook); } }
public void DeleteBook_WrongID() { Book deletedBook = new Book() { ID = -1 }; XDocument returnedDoc = GetBooksReturnedDocument(); using (MockRepository.Record()) { Expect.Call(XMLHelper.LoadDocument(XMLBooksFilePath + XMlBooksFileName)) .Repeat.Once() .Return(returnedDoc); } using (MockRepository.Playback()) { RepositoryBook.DeleteBook(deletedBook); } }
public void DeleteBook() { Book deletedBook = new Book() { ID = 2 }; XDocument returnedDoc = GetBooksReturnedDocument(); XDocument listOfBooksAfterDeletion = GetBooksReturnedDocumentDeleted(deletedBook.ID); using (MockRepository.Record()) { Expect.Call(XMLHelper.LoadDocument(XMLBooksFilePath + XMlBooksFileName)) .Repeat.Once() .Return(returnedDoc); Expect.Call(delegate { XMLHelper.SaveDocument(listOfBooksAfterDeletion, XMLBooksFilePath + XMlBooksFileName); }) .IgnoreArguments() .Constraints(Property.AllPropertiesMatch(listOfBooksAfterDeletion), Property.AllPropertiesMatch(XMLBooksFilePath + XMlBooksFileName)) .Repeat.Once(); } using (MockRepository.Playback()) { RepositoryBook.DeleteBook(deletedBook); } }
public void UpdateBook(Book updatedBook) { XDocument xmlDoc = XMLHelper.LoadDocument(XMLBooksFilePath + XMlBooksFileName); if (xmlDoc.Element(BooksRoot) == null) { throw new Exception("The list of books is empty"); } XElement query = (from book in xmlDoc.Element(BooksRoot).Elements(BooksElement) where int.Parse(book.Element(BooksID).Value.ToString()) == updatedBook.ID select book).FirstOrDefault(); if (query != null) { query.Element(BooksDescription).Value = updatedBook.Description; query.Element(BooksISBN).Value = updatedBook.ISBN; query.Element(BooksNumberPages).Value = updatedBook.NumberOfPages.ToString(); query.Element(BooksTitle).Value = updatedBook.Title; query.Element(BooksUbicacion).Value = updatedBook.Location.ToString(); XMLHelper.SaveDocument(xmlDoc, XMLBooksFilePath + XMlBooksFileName); } }
public void DeleteBook(Book deletedeBook) { XDocument xmlDoc = XMLHelper.LoadDocument(XMLBooksFilePath + XMlBooksFileName); if (xmlDoc.Element(BooksRoot) == null) throw new Exception("The list of books is empty"); XElement query = (from book in xmlDoc.Element(BooksRoot).Elements(BooksElement) where int.Parse(book.Element(BooksID).Value.ToString()) == deletedeBook.ID select book).FirstOrDefault(); if (query != null) { query.Remove(); XMLHelper.SaveDocument(xmlDoc, XMLBooksFilePath + XMlBooksFileName); } else throw new ArgumentException("The Book to delete with ID = " + deletedeBook.ID.ToString() + " was not present in the list of books"); }