public ActionResult HistoryQuery(StockItemHistoryQuery query)
 {
     var stockItem = stockItemService.GetById(query.StockItemId);
     var history = stockItemService.GetHistory(stockItem, query.Start, query.End).ToList();
     var viewData = new StockItemHistoryViewData
     {
         StockItem = stockItem,
         History = history,
         Start = query.Start,
         End = query.End
     };
     return View("History", viewData);
 }
        public void History_should_show_stockItems_between_given_dates()
        {
            const int stockItemId = 89;
            var stockItem = StockItem.Create("Widget", "Small", now, "*****@*****.**").SetId(stockItemId);
            stockItem.ReceiveStock(10, now, user);
            stockItem.Dispatch(2, 5, now, user);
            stockItem.Dispatch(2, 5, now, user);

            var start = new DateTime(2011, 1, 1);
            var end = new DateTime(2011, 2, 1);

            stockItemService.GetHistoryDelegate = (stockItemArg, startArg, endArg) =>
            {
                stockItemArg.ShouldBeTheSameAs(stockItem);
                startArg.ShouldEqual(start);
                endArg.ShouldEqual(end);

                return stockItem.History;
            };
            stockItemService.GetByIdDelegate = id =>
            {
                id.ShouldEqual(stockItemId);
                return stockItem;
            };

            var query = new StockItemHistoryQuery
            {
                StockItemId = stockItemId,
                Start = start,
                End = end
            };

            var viewData = controller.HistoryQuery(query)
                .ReturnsViewResult()
                .WithModel<StockItemHistoryViewData>();

            viewData.StockItem.ShouldBeTheSameAs(stockItem);
            viewData.History.Count.ShouldEqual(stockItem.History.Count);
            viewData.Start.ShouldEqual(start);
            viewData.End.ShouldEqual(end);
        }