public void AddBook_Correctdata_SaveData_ReturnTrue() { //Arrange var data = new Bookstore { Id = 1, Author = "test Author", Title = "test Title", inStock = 6, Price = 1000 }; Mock <IGenericRepository <Bookstore> > generic = new Mock <IGenericRepository <Bookstore> >(); _uniOfWorkMock.Setup(x => x.BookstoreRepository.Insert(It.IsAny <Bookstore>())) .Returns(Task.FromResult <bool>(true)); var bookService = new BookService(_uniOfWorkMock.Object); //Act var action = bookService.AddBookAsync(data); //Assert var content = action.Result; Assert.IsTrue(content); _uniOfWorkMock.Verify(u => u.Save(), Times.Exactly(1)); _uniOfWorkMock.Verify(u => u.BookstoreRepository.Insert(It.IsAny <Bookstore>()), Times.Exactly(1)); }
public void EditBook_NullBookId_ReturnFalse() { //Arrange var data = new Bookstore { Author = "test Author", Title = "test Title", inStock = 6, Price = 1000 }; Mock <IGenericRepository <Bookstore> > generic = new Mock <IGenericRepository <Bookstore> >(); _uniOfWorkMock.Setup(x => x.BookstoreRepository.Update(It.IsAny <Bookstore>())) .Returns(Task.FromResult <bool>(false)); var bookService = new BookService(_uniOfWorkMock.Object); //Act var action = bookService.EditBookAsync(data); //Assert var content = action.Result; Assert.IsFalse(content); _uniOfWorkMock.Verify(u => u.Save(), Times.Exactly(0)); _uniOfWorkMock.Verify(u => u.BookstoreRepository.Update(It.IsAny <Bookstore>()), Times.Exactly(0)); }
public void OnObjectGroupCreated(IScriptObjectGroup group) { try { if (sObjectGroupCreated) { return; } sObjectGroupCreated = true; if (sDelayedSkillBooks.Count > 0) { BooterLogger.AddTrace("OnWorldLoadStarted: " + sDelayedSkillBooks.Count); foreach (XmlDbData bookData in sDelayedSkillBooks) { LoadSkillBookData(bookData, "BookSkill"); } sDelayedSkillBooks.Clear(); Bookstore.mItemDictionary.Clear(); Bookstore.LoadData(); } } catch (Exception exception) { Common.Exception("OnWorldLoadStarted", exception); } }
public void buying_two_books_final_value_should_be_discounted() { //given var bookstore = new Bookstore { Books = new List <Book>() { new Book() { Name = "Harry Potter", Price = 8.0 }, new Book() { Name = "Harry Potter1", Price = 8.0 } } }; //When bookstore.Purchase(new[] { "Harry Potter", "Harry Potter1" }); //Then Assert.AreEqual(16, bookstore.ShoppingCartBalance); }
public static void Main(string[] args) { var library = new Library() .AddBook("Book1", 123, "Author1", "Department1") .AddBook("Book2", 234, "Author2", "Department1") .AddBook("Book3", 345, "Author3", "Department1") .AddBook("Book4", 456, "Author1", "Department2") .AddBook("Book5", 567, "Author2", "Department2"); Console.WriteLine("Books amount in the library: {0}", library.GetBooksCount()); library.PrintAllBooks(); library.PrintAllAuthors(); library.PrintAllDepartments(); //var xmlwork = new XmlWork(); //xmlwork.SortByPages("Library.xml"); IBookFactory bookhouse = new Bookhouse(); IBookFactory bookstore = new Bookstore(); Console.WriteLine(bookhouse.GetBook().ToString()); Console.WriteLine(bookstore.GetBook().ToString()); Console.ReadKey(); }
public void SubmitOrder_OutOfStockRange_ReturnFalse() { //Arrange var cart = new List <Cart> { new Cart { BookId = 1, Author = "test Author", Title = "test Title", Number = 7, Price = 2000 } }; var order = new List <Order> { new Order { OrderId = Guid.NewGuid(), BookId = 1, Number = 2, TotalPrice = 4000 } }; var book = new Bookstore { Id = 1, Author = "test Author", Title = "test Title", inStock = 6, Price = 1000 }; var bookgeneric = new Mock <IGenericRepository <Bookstore> >(); bookgeneric.Setup(x => x.GetByID(It.IsAny <int>())) .Returns(Task.FromResult <Bookstore>(book)); Mock <IGenericRepository <Order> > ordergeneric = new Mock <IGenericRepository <Order> >(); _uniOfWorkMock.Setup(bo => bo.BookstoreRepository).Returns(bookgeneric.Object); var bookService = new BookService(_uniOfWorkMock.Object); //Act var action = bookService.OrderBookAsync(cart); //Assert var content = action.Result; Assert.IsFalse(content); _uniOfWorkMock.Verify(u => u.Save(), Times.Exactly(0)); _uniOfWorkMock.Verify(u => u.BookstoreRepository.Update(It.IsAny <Bookstore>()), Times.Exactly(0)); _uniOfWorkMock.Verify(u => u.OrderRepository.Insert(It.IsAny <Order>()), Times.Exactly(0)); }
public async Task AddAsync(Bookstore bookStore) { using (var context = _dbContextFactoryMethod()) { context.BookStores.Add(bookStore); await context.SaveChangesAsync(); } }
public IHttpActionResult EditBook(Bookstore book) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } return(Ok(_bookService.EditBookAsync(book))); }
public void Price_MiltipleDifferentAndDoubleBooks_ShouldReturnDiscountedPrice(double expected, int[] books) { // Arrange // Act double actual = Bookstore.Price(books); // Assert Assert.Equal(expected, actual); }
public void Price_OneOrZeroBooks_ShouldReturn0Or8(double expected, int[] books) { // Arrange // Act double actual = Bookstore.Price(books); // Assert Assert.Equal(expected, actual); }
public void AddToInventory() { Book book = new Book(); Bookstore store = new Bookstore(); store.GetInventory(); store.AddToInventory(book); Assert.AreEqual(1, store.GetInventory().Count); }
public IActionResult OnPostRemove(long bookId, string returnUrl) { Bookstore bookstore = repository.Bookstores.FirstOrDefault(b => b.BookID == bookId); Cart.RemoveLine(bookstore); return(RedirectToPage(new { returnUrl = returnUrl })); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); FormBookstore f1 = new FormBookstore(); DatabasePackagingClass db = DatabasePackagingClass.instance; db.initializeAndConnect(); Bookstore b = Bookstore.initialize(/*f1,*/ db, db); f1.initialize(b); Application.Run(f1); }
public async Task <bool> AddBookAsync(Bookstore book) { var bookRepository = _unitOfWork.BookstoreRepository; if (book == null) { return(false); } await bookRepository.Insert(book); _unitOfWork.Save(); return(true); }
public void EditBook_InvalidModeStade_BadRequest() { //Arrange var bookstore = new Bookstore(); var controller = new BookController(_bookServiceMock.Object); controller.ModelState.AddModelError("ModelError", "ModelError"); //Act var action = controller.EditBook(bookstore); //Assert Assert.IsTrue(action is InvalidModelStateResult); }
static void Main(string[] args) { Console.OutputEncoding = Encoding.UTF8; Bookstore bookstore = new Bookstore(); Book book1 = new Book("The answer to everything...", 42.00M); Magazine mag1 = new Magazine("WD40 weekly tips!", 8.95M, new DateTime(2012, 10, 7)); CD cd1 = new CD("Sounds of the universe", 9.99M); bookstore.AddToStock(book1, 24); bookstore.AddToStock(mag1, 10); bookstore.AddToStock(cd1); bookstore.PrintStock(); Console.ReadKey(); }
// json // using System.Runtime.Serialization.Json; static public void SerializeBooks(string path, Bookstore <Product> book) { DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(Bookstore <Product>)); try { using (FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write)) { jsonSerializer.WriteObject(fs, book); } } catch (Exception ex) { Console.WriteLine("Ошибка в сериализации" + ex.Message); } }
public void Import(string catalogAsJson) { Bookstore bookstore = JsonConvert.DeserializeObject <Bookstore>(catalogAsJson); if (bookstore != null) { foreach (var catalog in bookstore.Catalog) { this.catalogService.addCatalog(catalog); } foreach (var category in bookstore.Category) { this.categoryService.addCategory(category); } } }
protected override void PerformFile(BooterHelper.BootFile file) { BooterHelper.DataBootFile dataFile = file as BooterHelper.DataBootFile; if (dataFile == null) { return; } sDelayedSkillBooks.Add(dataFile.Data); BookData.LoadBookData(dataFile.Data, "BookGeneral", BookData.BookType.General); BookData.LoadBookData(dataFile.Data, "BookRecipe", BookData.BookType.Recipe); BookData.LoadBookData(dataFile.Data, "MedicalJournal", BookData.BookType.MedicalJournal); BookData.LoadBookData(dataFile.Data, "SheetMusic", BookData.BookType.SheetMusic); BookData.LoadBookData(dataFile.Data, "BookToddler", BookData.BookType.Toddler); BookData.LoadBookData(dataFile.Data, "BookAlchemyRecipe", BookData.BookType.AlchemyRecipe); LoadWrittenBookTitles(dataFile.Data); LoadWrittenBookMaterials(dataFile.Data); BookData.LoadBookData(dataFile.Data, "BookFish", BookData.BookType.FishBook); XmlDbTable table = dataFile.GetTable("OmniJournal"); if (table != null) { BooterLogger.AddTrace(file.ToString() + ": Found OmniJournal = " + table.Rows.Count.ToString()); int rowIndex = 0; foreach (XmlDbRow row in table.Rows) { new OmniJournalData(row, rowIndex); rowIndex++; } } else { BooterLogger.AddTrace(file.ToString() + ": No OmniJournal"); } Bookstore.mItemDictionary.Clear(); Bookstore.LoadData(); }
public void TestMethod1() { //given var bookstore = new Bookstore { Books = new List <Book>() { new Book() { Name = "Harry Potter", Price = 8.0 } } }; //When bookstore.Purchase(new [] { "Harry Potter" }); //Then Assert.AreEqual(8.0, bookstore.ShoppingCartBalance); }
public static void ParseBooks() { string text = "BooksSewable"; XmlDbData xmlDbData = XmlDbData.ReadData(text); if (xmlDbData != null && xmlDbData.Tables != null) { sDelayedSkillBooks.Add(xmlDbData); BookData.LoadBookData(xmlDbData, "BookSkill", BookData.BookType.Skill); bool loaded = true; if (loaded) { Bookstore.mItemDictionary.Clear(); Bookstore.LoadData(); } } else { SimpleMessageDialog.Show("[DEBUG] Arsil's CustomBookLoader", "Resource " + text + " of type _XML not found or with no data defined!"); } }
public void AddBook_EmptyData_ReturnFalse() { //Arrange Bookstore data = null; Mock <IGenericRepository <Bookstore> > generic = new Mock <IGenericRepository <Bookstore> >(); _uniOfWorkMock.Setup(x => x.BookstoreRepository.Insert(It.IsAny <Bookstore>())) .Returns(Task.FromResult <bool>(false)); var bookService = new BookService(_uniOfWorkMock.Object); //Act var action = bookService.AddBookAsync(data); //Assert var content = action.Result; Assert.IsFalse(content); _uniOfWorkMock.Verify(u => u.Save(), Times.Exactly(0)); _uniOfWorkMock.Verify(u => u.BookstoreRepository.Insert(It.IsAny <Bookstore>()), Times.Exactly(0)); }
public void initialize(Bookstore b) { navigation = new BookstoreNavFunctions(this); //uclog = new UserControlLogin(b, navigation); //ucreg = new UserControlRegister(b, navigation); ucAcc = new UserControlAccount(b, navigation); //ucShCategs = new UserControlShowCategs(b, navigation); //ucEditCategs = new UserControlEditCategs(b, navigation); ucSea = new UserControlSearch(b, navigation); funEditCategs = b; navEditCategs = navigation; showCategs = b; navShowCategs = navigation; funLogin = b; navLogin = navigation; funRegister = b; navRegister = navigation; this.Controls.Clear(); this.Controls.Add(new UserControlLogin(b, navigation)); this.Refresh(); }
public async Task <bool> EditBookAsync(Bookstore book) { var bookRepository = _unitOfWork.BookstoreRepository; if (book.Id <= 0) { return(false); } try { await bookRepository.Update(book); _unitOfWork.Save(); return(true); } catch (Exception ex) { Console.WriteLine("Commit Exception Type: {0}", ex.GetType()); Console.WriteLine(" Message: {0}", ex.Message); throw; } }
static void Main(string[] args) { do { Bookstore <Product> books = new Bookstore <Product>(); try { using (FileStream fs = new FileStream(@"../../../books.json", FileMode.Open)) { DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(Bookstore <Product>), new Type[] { typeof(Book), typeof(Product) }); books = (Bookstore <Product>)jsonSerializer.ReadObject(fs); } } catch (Exception e) { Console.WriteLine("проблемы" + e.Message); } foreach (var item in books) { Console.WriteLine(item); } books.Remove(); var linq = from book in books where ((Book)book).Year == books.Max(x => ((Book)x).Year) select book; Console.WriteLine("3 линк: "); foreach (var item in linq) { Console.WriteLine(item); } Console.WriteLine($"Размер = {linq.Count()}"); Console.WriteLine(); } while (Console.ReadKey(true).Key != ConsoleKey.Escape); }
/// <summary> /// /// </summary> /// <param name="args"></param> public static void Main(string[] args) { Console.CursorVisible = false; Console.Title = Resources.WindowTitle; Console.BackgroundColor = ConsoleColor.DarkCyan; Console.ForegroundColor = ConsoleColor.Cyan; Console.Clear(); Console.WriteLine(Resources.Header); ChannelServices.RegisterChannel(new TcpChannel(new Hashtable { { "port", WarehouseCommon.BookstorePort } }, new BinaryClientFormatterSinkProvider(), new BinaryServerFormatterSinkProvider { TypeFilterLevel = TypeFilterLevel.Full }), false); try { Bookstore.Open(); RemotingConfiguration.RegisterActivatedServiceType(typeof(IBookstoreRemoting)); RemotingServices.Marshal(new BookstoreRemoting(), WarehouseCommon.BookstoreEndpoint); LogMessage("IStoreService running on port {0:D}...", Bookstore.BaseAddresses.FirstOrDefault()?.Port); Webstore.Open(); LogMessage("IWebstoreService running on port {0:D}...", Webstore.BaseAddresses.FirstOrDefault()?.Port); LogMessage("Press <any> key to close!"); Console.ReadKey(true); Bookstore.Close(); Webstore.Close(); } catch (Exception ex) { LogException(ex); Console.BackgroundColor = ConsoleColor.DarkRed; Console.ForegroundColor = ConsoleColor.Red; LogMessage(Resources.ExceptionCaught); } }
public static void Initialize(DatabaseContext context) { context.Database.EnsureCreated(); #region Bookstore if (context.Bookstore.Any()) { return; } var bookstores = new Bookstore[] { new Bookstore { Name = "Bookstore Vulkan", CreatedDate = DateTime.UtcNow }, new Bookstore { Name = "Bookstore Delfi", CreatedDate = DateTime.UtcNow }, new Bookstore { Name = "Bookstore Zvezdan", CreatedDate = DateTime.UtcNow } }; foreach (Bookstore b in bookstores) { context.Bookstore.Add(b); } context.SaveChanges(); #endregion #region Author if (context.Author.Any()) { return; } var authors = new Author[] { new Author { Name = "Author 1", CreatedDate = DateTime.UtcNow }, new Author { Name = "Author 2", CreatedDate = DateTime.UtcNow }, new Author { Name = "Author 3", CreatedDate = DateTime.UtcNow }, new Author { Name = "Author 4", CreatedDate = DateTime.UtcNow } }; foreach (Author a in authors) { context.Author.Add(a); } context.SaveChanges(); #endregion #region AuthorBio if (context.AuthorBio.Any()) { return; } var authorBio = new AuthorBio[] { new AuthorBio { Name = "Author 1 biography", CreatedDate = DateTime.UtcNow, AuthorId = 1 }, new AuthorBio { Name = "Author 2 biography", CreatedDate = DateTime.UtcNow, AuthorId = 2 }, new AuthorBio { Name = "Author 3 biography", CreatedDate = DateTime.UtcNow, AuthorId = 3 }, new AuthorBio { Name = "Author 4 biography", CreatedDate = DateTime.UtcNow, AuthorId = 4 } }; foreach (AuthorBio ab in authorBio) { context.AuthorBio.Add(ab); } context.SaveChanges(); #endregion #region Book if (context.Book.Any()) { return; } var books = new Book[] { new Book { Name = "Book 1", CreatedDate = DateTime.UtcNow, AuthorId = 1 }, new Book { Name = "Book 2", CreatedDate = DateTime.UtcNow, AuthorId = 2 }, new Book { Name = "Book 3", CreatedDate = DateTime.UtcNow, AuthorId = 3 }, new Book { Name = "Book 4", CreatedDate = DateTime.UtcNow, AuthorId = 4 } }; foreach (Book b in books) { context.Book.Add(b); } context.SaveChanges(); #endregion }
public void bookstoreChanged(Bookstore bookstore) { throw new System.NotImplementedException(); }
static void Main(string[] args) { var service = new Bookstore(); service.Run(); }
public async Task PostBookstore([FromBody] Bookstore bookstore) { await _bookStoreService.AddAsync(bookstore); }
public BookController(Bookstore context) { _context = context; }