I've created a Find method on a Massive class. Problem is I've just realised it always returns true as the results are never null. Here's my code:
public dynamic Find(string email)
{
dynamic result = new ExpandoObject();
dynamic experience = new ExpandoObject();
result.Success = false;
experience = this.Query(@"SELECT we.* FROM WorkExperience we
LEFT JOIN Members m ON m.Id = we.MemberId
WHERE m.Email = @0", email);
if (experience != null)
{
result.Experience = experience;
result.Success = true;
}
return result;
}
In this case experience is never null so result.Success always comes back as false. How can I test whether this.Query() returns a record or records?
I'm doing this to test whether my query comes back with records.
Controller:
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);
}
and test:
[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");
}