static void Main(string[] args) { const int MAXBOOKS = 10; Console.WriteLine($"Books to add in bookstore: {MAXBOOKS}\n"); //test delegate BookStore l = new BookStore(); //add a book with a custom callback l.AddBook("C# Delegate Sample", 25.99m, delegate(string message, decimal averagePrice) { Console.WriteLine("Custom callback. Message: {0}, Average Price {1:C2}", message, averagePrice); }); //add many books with a common callback ProcessBookCountCallback commonCallback = new ProcessBookCountCallback(delegate(string message, decimal averagePrice) { Console.WriteLine($"Common callback. Message: {message}, Average Price: {averagePrice.ToString("C2")}"); }); for (int i = 0; i < 10; i++) { decimal randomPrice = r.Next(0, 11) * 0.99m; l.AddBook($"C# Delegate Sample {i}", randomPrice, commonCallback); } Console.ReadLine(); }
public Book Get(int id) { if (id <= 0) { throw new InvalidIDException(); } return(BookStore.Get(id)); }
public int PutIntoFavList(int id, BookStore store) { BookStore book = dbConnection.bookStores.FirstOrDefault(b => b.BookId == id); book.Flag = store.Flag; return(dbConnection.SaveChanges()); }
public int Delete(int id) { BookStore book = dbConnection.bookStores.Find(id); dbConnection.bookStores.Remove(book); return(dbConnection.SaveChanges()); }
public ActionResult Delete(int id) { BookStore store = db.BookStores.Find(id); db.BookStores.Remove(store); db.SaveChanges(); return(RedirectToAction("ViewAll")); }
public virtual int PutIntoFavList(int id, BookStoreModel bookModel) { BookStore store = new BookStore(); store.Flag = bookModel.Flag; return(_bussiness.PutIntoFavList(id, store)); }
public ActionResult Book(string name) { Fail.IfArgumentWhiteSpace(name, nameof(name)); var book = BookStore.GetBook(name); return(RedirectToBookEditor(book)); }
public void Delete(int id) { if (id <= 0) { throw new InvalidIDException(); } BookStore.Delete(id); }
public void SpecificNonDefaultDistributor() { var store = new BookStore(); store.Distributor = new WestCostDitributor(); Assert.IsTrue(store.GetDistributor() is WestCostDitributor); }
public void Update(BookStore bookStore) { if (bookStore is null) { throw new Exception("Input is null"); } _dataService.UpdateBookStore(bookStore); }
public ActionResult WordNew(Guid categoryId) { Fail.IfArgumentEmpty(categoryId, nameof(categoryId)); var category = BookStore.GetCategory(categoryId); var model = new NewWordModel(category); return(View(model)); }
public void Verify() { var b1 = new Book(); var b2 = new Book(); var b3 = new Book(); var b4 = new Book(); var b5 = new Book(); var b6 = new Book(); var historyBooks = new[] { b1, b2, }; var artBooks = new[] { b3, b4, }; var scienceBooks = new[] { b5 }; var comics = new[] { b6 }; var all = historyBooks.Concat(artBooks).Concat(scienceBooks).Concat(comics).ToList(); var fs = new BookStore() { AllBooks = all, Genres = new[] { new Genre() { Books = historyBooks, }, new Genre() { Books = historyBooks, }, new Genre() { Books = artBooks, }, new Genre() { Books = scienceBooks, }, new Genre() { Books = comics, }, } }; var serializer = new ConfigurationContainer().Type <Book>(b => b.EnableReferences()) .Create(); var cycled = serializer.Cycle(fs); cycled.Genres.ElementAt(0).Books.ElementAt(0).Should().BeSameAs(cycled.AllBooks.ElementAt(0)); cycled.Genres.ElementAt(0).Books.ElementAt(1).Should().BeSameAs(cycled.AllBooks.ElementAt(1)); cycled.Genres.ElementAt(1).Books.ElementAt(0).Should().BeSameAs(cycled.AllBooks.ElementAt(0)); cycled.Genres.ElementAt(1).Books.ElementAt(1).Should().BeSameAs(cycled.AllBooks.ElementAt(1)); cycled.Genres.ElementAt(2).Books.ElementAt(0).Should().BeSameAs(cycled.AllBooks.ElementAt(2)); cycled.Genres.ElementAt(2).Books.ElementAt(1).Should().BeSameAs(cycled.AllBooks.ElementAt(3)); cycled.Genres.ElementAt(3).Books.ElementAt(0).Should().BeSameAs(cycled.AllBooks.ElementAt(4)); cycled.Genres.ElementAt(4).Books.ElementAt(0).Should().BeSameAs(cycled.AllBooks.ElementAt(5)); }
public void Post([FromBody] BookStore bookStore) { if (bookStore is null) { throw new Exception("Input is null"); } _dataService.AddBookStore(bookStore); }
public static EditModel GoToNextWord(EditModel model) { var b = BookStore.GetBook(model.Book); var c = b.GetCategory(model.Category); var w = c.GetWord(model.Word); var nextWord = c.GetNextWord(w); return(new EditModel(nextWord)); }
public void GivenBookStore_WhenBuy_ThenOnlyFirtCopyOfCategoryHasDiscount() { var bookStore = new BookStore(); bookStore.Import(json); Assert.AreEqual(30, bookStore.Buy("J.K Rowling - Goblet Of fire", "Robin Hobb - Assassin Apprentice", "Robin Hobb - Assassin Apprentice")); Assert.AreEqual(69.95, bookStore.Buy("Ayn Rand - FountainHead", "Isaac Asimov - Foundation", "Isaac Asimov - Robot series", "J.K Rowling - Goblet Of fire", "J.K Rowling - Goblet Of fire", "Robin Hobb - Assassin Apprentice", "Robin Hobb - Assassin Apprentice")); }
public void EFContext_Autofixture_Test() { Fixture fix = new Fixture(); Book b0 = fix.Create <Book>(); List <Book> b1 = fix.CreateMany <Book>(1000).ToList(); BookStore bs = fix.Create <BookStore>(); }
public ActionResult BookId(Guid id) { Fail.IfArgumentEmpty(id, nameof(id)); var book = BookStore.GetBookById(id); var model = new EditBookModel(book); return(View("Book", model)); }
public ActionResult CategoryNew(Guid bookId) { Fail.IfArgumentEmpty(bookId, nameof(bookId)); var category = BookStore.GetBookById(bookId); var model = new NewCategoryModel(category); return(View(model)); }
public ActionResult Category(Guid id) { Fail.IfArgumentEmpty(id, nameof(id)); var category = BookStore.GetCategory(id); var model = new EditCategoryModel(category); return(View(model)); }
public ActionResult Edit(EditInputModel input) { var book = BookStore.GetBook(input.Book); var category = book.GetCategory(input.Category); var word = category.GetWord(input.Word); var model = new EditModel(word); return(View(model)); }
public IActionResult Get(int id) { var result = BookStore.GetById(id); if (result == null) { return(NotFound()); } return(Ok(result)); }
public void Test_CalculateDiscountFactor(int inputValue, double expectedValue) { //Arrange BookStore bookStore = new BookStore(); //Act double actualResult = bookStore.CalculateDiscountFactor(inputValue); //Assert Assert.AreEqual(expectedValue, Math.Round(actualResult, 2)); }
public void Test_GetDiscountedPrice(int[] inputValue, double expectedValue) { //Arrange BookStore bookStore = new BookStore(); //Act double actualResult = bookStore.GetDiscountedPrice(new List <int>(inputValue)); //Assert Assert.AreEqual(expectedValue, Math.Round(actualResult, 2)); }
public void DefineBookQuality(BookStore book) { var quality = book.Quality - ((DateTime.Now - book.EntryDate).Days * 2); book.Quality = quality; if (quality <= 0) { throw new Exception($"The Comic has a quality of {quality}, its necesary remove from the inventory"); } }
public List <Book> returnBook() { var bookStore = new BookStore() { Path = bookPath }; var bookList = bookStore.GetCollection(); return(bookList); }
public void GetAllBooks() { // Arrange var subject = new BookStore(); // Act var books = subject.GetAllBooks(); // Assert Assert.AreEqual(5, books.Count()); }
public ActionResult Save(EditModel model) { var book = BookStore.GetBook(model.Book); var category = book.GetCategory(model.Category); var word = category.GetWord(model.Word); word.Edit(model.Polish, model.GetEnglishPhrases().ToList()); book.Save(); return(RedirectToAction("Edit", new EditInputModel(word))); }
public static void InsertData() { using (var context = new BookStore()) { Author author1 = new Author() { Name = "Mark", Books = new List <Book> { new Book() { Title = "Fundamentals of Computer Programming with C#" }, new Book() { Title = "Java: A Beginner's Guide" }, } }; Author author2 = new Author() { Name = "Andy", Books = new List <Book> { new Book() { Title = "SQL: The Ultimate Beginners Guide" } } }; Author author3 = new Author() { Name = "Johny", Books = new List <Book> { new Book() { Title = "Learn VB.NET" }, new Book() { Title = "C# Fundamentals for Absolute Beginners" }, } }; context.Authors.Add(author1); context.Authors.Add(author2); context.Authors.Add(author3); context.SaveChanges(); } }
public ActionResult Word(Guid categoryId, string name) { Fail.IfArgumentEmpty(categoryId, nameof(categoryId)); Fail.IfArgumentWhiteSpace(name, nameof(name)); var category = BookStore.GetCategory(categoryId); var word = category.GetWord(name); var model = new EditModel(word); return(View(model)); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); var filesPath = this.Server.MapPath("~\\App_Data"); BookStore.Read(filesPath); }
public void Delete(BookStore entity) { _dataContext.BookStores.Remove(entity); _dataContext.SaveChanges(); }
public void Insert(BookStore entity) { _dataContext.BookStores.Add(entity); _dataContext.SaveChanges(); }
public void Save(BookStore entity) { _dataContext.SaveChanges(); }