This is a migrated thread and some comments may be shown as answers.

GridCommand.Parse Equivalent for DataSourceRequest?

1 Answer 180 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nick
Top achievements
Rank 1
Nick asked on 24 Feb 2015, 07:32 PM
I'm migrating an application from the old Telerik Mvc controls to the latest UI for ASP.NET MVC wrappers.

I have a bunch of unit tests that validated the controller actions that the grid calls for data.  A simple example would be:

<TestMethod()>
Public Sub GetLogEntryData_Passes_Through_Filters_On_Multiple_Columns()
  Dim passedCmd As GridParameters = Nothing
  _adminLogService.Setup(Function(s) s.GetLogEntries(It.IsAny(Of GridParameters))).Returns(_validLogEntries).Callback(Sub(p) passedCmd = p)
  Dim target As New AdminLogController(_adminLogService.Object, Nothing)
  Dim cmd As GridCommand = GridCommand.Parse(1, 10, Nothing, Nothing, "UserName~eq~'test'~and~ControllerName~startswith~'Users'")
  target.GetLogEntryData(cmd)
  Assert.IsNotNull(passedCmd)
  Assert.AreEqual(2, passedCmd.Filters.Count)
End Sub

Now that I have replaced the grids and I'm passing a DataSourceRequest instead, I don't suppose there's a similarly handy function that can replace the GridCommand.Parse statement?

Cheers,
Nick

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 26 Feb 2015, 11:19 AM
Hello Nick,

Although, it is not available you could build such helper method on your own, similar to the following:

public static class DataSourceRequestHelper
{
    public static DataSourceRequest Parse(int page, int pageSize, string orderBy, string groupBy, string filter)
    {
        return new DataSourceRequest
        {
            Page = page,
            PageSize = pageSize,
            Sorts = GridDescriptorSerializer.Deserialize<SortDescriptor>(orderBy),
            Filters = FilterDescriptorFactory.Create(filter),
            Groups = GridDescriptorSerializer.Deserialize<GroupDescriptor>(groupBy)
        };
    }
}


Regards,
Rosen
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Nick
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or