public void CreateOrderRow_Test() { var bookId = Guid.NewGuid(); var books = new List <IBook>() { new Book() { Title = "Title", Author = "Author", InStock = 20, Price = 100m, Id = bookId } }; var checkoutRow = new CheckoutRow() { Quantity = 10, BookId = bookId }; var privateObject = new PrivateObject(this.orderService); var row = (OrderRow)privateObject.Invoke("CreateOrderRow", new object[] { checkoutRow, books }); Assert.AreEqual(10, row.Quantity); Assert.AreEqual(0, row.Backordered); }
private OrderRow CreateOrderRow(CheckoutRow checkoutRow, IEnumerable <IBook> books) { var book = books.SingleOrDefault(x => { var o = x as Book; return(o != null && o.Id == checkoutRow.BookId); }); if (book != null) { var backordered = (book as Book).InStock > checkoutRow.Quantity ? 0 : checkoutRow.Quantity - (book as Book).InStock; return(new OrderRow() { Book = book, Quantity = backordered != 0 ? (book as Book).InStock : checkoutRow.Quantity, Backordered = backordered }); } return(null); }