This question is locked. New answers and comments are not allowed.
Hi Guys,
I'm trying to test an extension method which create a generic grid:
Here is my test method:
But I receive following error: Object reference not set to an instance of an object.
Actually, the problem is that the grid can't find his resource file. Take a look at the StackTrace:
at Telerik.Web.Mvc.Infrastructure.Implementation.VirtualPathProviderWrapper.FileExists(String virtualPath)
at Telerik.Web.Mvc.Infrastructure.Implementation.LocalizationService.CreateResource(String resourceName, CultureInfo culture, String resourceLocation)
at Telerik.Web.Mvc.Infrastructure.Implementation.LocalizationService.DetectResource(String resourceLocation, String resourceName, CultureInfo culture)
at Telerik.Web.Mvc.Infrastructure.Implementation.LocalizationService..ctor(String resourceName, CultureInfo culture)
at Telerik.Web.Mvc.Infrastructure.Implementation.LocalizationServiceFactory.Create(String resourceName, CultureInfo culture)
at Telerik.Web.Mvc.UI.ViewComponentFactory.<Grid>b__2[T]()
at Telerik.Web.Mvc.UI.ViewComponentFactory.Register[TViewComponent](Func`1 factory)
at Telerik.Web.Mvc.UI.ViewComponentFactory.Grid[T]()
Is it possible to disable localization in testing purpose? Or can I mock and inject this localization service? Or can I fake this resource file some how?
Best regards,
Vangel
I'm trying to test an extension method which create a generic grid:
public static void GetEntityGrid<T>(HtmlHelper helper) where T : class{ helper.Telerik().Grid<T>() .Name("Grid_{0}".FormatWith(Guid.NewGuid())) .HtmlAttributes(htmlAttributes) .ToolBar(commands => SetToolbar(helper, commands, metadata, toolBarActions, entityFormattedName, routeValues, controller)) .Columns(columns => SetColumns(helper, columns, metadata, entityDisplayColumn, controller, itemActions, columnWidths)) .DataBinding(binding => binding.Ajax().Select("GetGridData", controller, routeValues)) .Sortable(sorting => SetSorting(sorting, metadata)) .Pageable(x => x.PageSize(GuiSettings.Global.GetSetting(GlobalSettingType.DefaultPageSize).ValueAs<int>())) .ClientEvents(events => SetClientEvents(events, clientEvents)) .Scrollable(scrolling => scrolling.Enabled(autoScroll).Height("auto")) .Render();}Here is my test method:
[TestMethod]public void EntityGridTest(){ MockToolsMvc.SetFakeHttpContext(); HtmlHelper htmlHelper = MockToolsMvc.FakeHtmlHelper(); htmlHelper.EntityGrid<TestingClass>(); }But I receive following error: Object reference not set to an instance of an object.
Actually, the problem is that the grid can't find his resource file. Take a look at the StackTrace:
at Telerik.Web.Mvc.Infrastructure.Implementation.VirtualPathProviderWrapper.FileExists(String virtualPath)
at Telerik.Web.Mvc.Infrastructure.Implementation.LocalizationService.CreateResource(String resourceName, CultureInfo culture, String resourceLocation)
at Telerik.Web.Mvc.Infrastructure.Implementation.LocalizationService.DetectResource(String resourceLocation, String resourceName, CultureInfo culture)
at Telerik.Web.Mvc.Infrastructure.Implementation.LocalizationService..ctor(String resourceName, CultureInfo culture)
at Telerik.Web.Mvc.Infrastructure.Implementation.LocalizationServiceFactory.Create(String resourceName, CultureInfo culture)
at Telerik.Web.Mvc.UI.ViewComponentFactory.<Grid>b__2[T]()
at Telerik.Web.Mvc.UI.ViewComponentFactory.Register[TViewComponent](Func`1 factory)
at Telerik.Web.Mvc.UI.ViewComponentFactory.Grid[T]()
Is it possible to disable localization in testing purpose? Or can I mock and inject this localization service? Or can I fake this resource file some how?
Best regards,
Vangel