I'm not sure if this is a JustMock question, but it may be. I'm trying to test a Kendo datasource 'read' method which is implemented in my MVC controller. The datasource is actually part of a grid definition, but I have others that are in auto-complete controls.
The following is a fragment of my grid definition in the view.
.DataSource(dataSource => dataSource .Ajax() .PageSize(10) .Events(events => events.Error("error_handler").RequestEnd("onGridRequestEnd")) .Model(model => { model.Id(p => p.Id); model.Field(p => p.Id).Editable(false); model.Field(p => p.PostedStr).Editable(false); model.Field(p => p.UpdatedStr).Editable(false); }) .Read(read => read.Action("_GetBulletins", "Bulletins").Type(HttpVerbs.Get)) .Create(create => create.Action("_CreateBulletin", "Bulletins").Type(HttpVerbs.Post).Data("sendAntiForgery")) .Update(update => update.Action("_UpdateBulletin", "Bulletins").Type(HttpVerbs.Post).Data("sendAntiForgery")) .Destroy(update => update.Action("_DeleteBulletin", "Bulletins").Type(HttpVerbs.Post).Data("sendAntiForgery")))
My controller methods is:
[AcceptVerbs(HttpVerbs.Get)][AjaxOnly][OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]public ActionResult _GetBulletins(DataSourceRequest request){ var model = (BulletinsViewModel)ViewModels.GetModel(HttpContext, Constants.Session.Model.BulletinsViewModelId); var enumerableModel = model.Bulletins.AsEnumerable(); return Json(enumerableModel.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);}
and a fragment of my test is:
var request = new DataSourceRequest(){ Aggregates = new List<AggregateDescriptor>(), Filters = new List<IFilterDescriptor>(), Groups = new List<GroupDescriptor>(), Sorts = new List<SortDescriptor>(), Page = 1, PageSize = 10};// Actvar result = controller._GetBulletins(request) as JsonResult;var model = result.Data as BulletinsViewModel;
When I run my test, the controller throws and exception:
System.ArgumentNullException: 'Value cannot be null.' Message:"Value cannot be null.\r\nParameter name: source"
Obviously I'm not setting up the 'request' properly, althought I don't exactly know what's wrong.
Rather than spin my wheels trying to figure that out, I wonder if you can advise me on the recomended approach to testing datasources.
TIA
Dave