Я делаю это, чтобы проверить, возвращается ли мой запрос с записями.
Контроллер:
public ActionResult Index() {
_logger.LogInfo("In home");
//var data = _tricksTable.All(orderBy: "DateCreated");
dynamic viewModel = new ExpandoObject();
var data = _tricksTable.Query("SELECT TOP(10) * FROM Tricks ORDER BY DateCreated DESC");
viewModel.TenTricksNewestFirst = data;
var data2 = _tricksTable.Query("SELECT TOP(10) * FROM Tricks ORDER BY Votes DESC");
viewModel.TenTricksMostPopularFirst = data2;
return View(viewModel);
}
и тест:
[Test]
public void a_user_should_be_able_to_view_10_newest_tricks_in_latest_videos_tab() {
var result = _controller.Index() as ViewResult;
dynamic viewModelExpando = result.ViewData.Model;
var queryFromMassiveDynamic = viewModelExpando.TenTricksNewestFirst;
var i = Enumerable.Count(queryFromMassiveDynamic);
Assert.AreNotEqual(0, i, "TenTricksNewestFirst returned 0 records");
Assert.LessOrEqual(i,10, "Ten Tricks Newest First returned more than 10 tricks");
}