public void AddActionLink_OnNullAuthorizationProviderRendersActionLink() { String actionLink = ""; Authorization.Provider = null; AllTypesView view = new AllTypesView(); columns.Grid.HttpContext = HttpContextFactory.CreateHttpContextBase(); UrlHelper urlHelper = new UrlHelper(columns.Grid.HttpContext.Request.RequestContext); columns .Add(Arg.Any <Expression <Func <AllTypesView, String> > >()).Returns(column) .AndDoes(info => { actionLink = info.Arg <Expression <Func <AllTypesView, String> > >().Compile().Invoke(view); }); columns.AddActionLink("Details", "fa fa-info"); String actual = actionLink; String expected = String.Format( "<a class=\"details-action\" href=\"{0}\">" + "<i class=\"fa fa-info\"></i>" + "</a>", urlHelper.Action("Details", new { id = view.Id })); Assert.Equal(expected, actual); }
public void AddActionLink_NullAuthorization_Renders() { AllTypesView view = new AllTypesView(); StringWriter writer = new StringWriter(); IUrlHelper urlHelper = Substitute.For <IUrlHelper>(); urlHelper.Action("Details", Arg.Any <Object>()).Returns("Test"); columns.Grid.ViewContext.HttpContext.ApplicationServices.GetService <IAuthorizationProvider>().Returns(null as IAuthorizationProvider); columns.Grid.ViewContext = new ViewContext { RouteData = new RouteData(), HttpContext = Substitute.For <HttpContext>() }; columns.Grid.ViewContext.HttpContext.ApplicationServices.GetService <IUrlHelper>().Returns(urlHelper); IGridColumn <AllTypesView> column = columns.AddActionLink("Details", "fa fa-info"); column.ValueFor(new GridRow <AllTypesView>(view)).WriteTo(writer, HtmlEncoder.Default); String actual = writer.ToString(); String expected = $"<a class=\"details-action\" href=\"{urlHelper.Action("Details", new { view.Id })}\">" + "<i class=\"fa fa-info\"></i>" + "</a>"; Assert.Equal(expected, actual); }
public void AddBooleanProperty_Nullable_RendersEmpty() { AllTypesView view = new AllTypesView { NullableBooleanField = null }; IGridColumn <AllTypesView> column = columns.AddBooleanProperty(model => model.NullableBooleanField); String actual = column.ValueFor(new GridRow(view)).ToString(); Assert.Empty(actual); }
public void AddBooleanProperty_Nullable_RendersNo() { AllTypesView view = new AllTypesView { NullableBooleanField = false }; IGridColumn <AllTypesView> column = columns.AddBooleanProperty(model => model.NullableBooleanField); String actual = column.ValueFor(new GridRow(view)).ToString(); String expected = TableResources.No; Assert.Equal(expected, actual); }
public void AddBooleanProperty_RendersYes() { AllTypesView view = new AllTypesView { BooleanField = true }; IGridColumn <AllTypesView> column = columns.AddBooleanProperty(model => model.BooleanField); String actual = column.ValueFor(new GridRow(view)).ToString(); String expected = TableResources.Yes; Assert.Equal(expected, actual); }
public void AddActionLink_NullAuthorization_Renders() { Authorization.Provider = null; AllTypesView view = new AllTypesView(); UrlHelper urlHelper = new UrlHelper(columns.Grid.HttpContext.Request.RequestContext); IGridColumn <AllTypesView> column = columns.AddActionLink("Details", "fa fa-info"); String actual = column.ValueFor(new GridRow <AllTypesView>(view)).ToString(); String expected = $"<a class=\"details-action\" href=\"{urlHelper.Action("Details", new {view.Id})}\">" + "<i class=\"fa fa-info\"></i>" + "</a>"; Assert.Equal(expected, actual); }
public void AddBooleanProperty_Nullable_RendersBooleanNullValue() { Object renderedValue = null; AllTypesView view = new AllTypesView { NullableBooleanField = null }; column .When(sub => sub.RenderedAs(Arg.Any <Func <AllTypesView, Object> >())) .Do(info => renderedValue = info.Arg <Func <AllTypesView, Object> >()(view)); columns.AddBooleanProperty(model => model.NullableBooleanField); Object expected = ""; Object actual = renderedValue; Assert.Equal(expected, actual); }
public void AddBooleanProperty_RendersBooleanFalseValue() { Object renderedValue = null; AllTypesView view = new AllTypesView { BooleanField = false }; column .When(sub => sub.RenderedAs(Arg.Any <Func <AllTypesView, Object> >())) .Do(info => renderedValue = info.Arg <Func <AllTypesView, Object> >()(view)); columns.AddBooleanProperty(model => model.BooleanField); Object expected = TableResources.No; Object actual = renderedValue; Assert.Equal(expected, actual); }
public void AddAction_NoAuthorization_Renders() { AllTypesView view = new AllTypesView(); StringWriter writer = new StringWriter(); LinkGenerator link = Substitute.For <LinkGenerator>(); columns.Grid.ViewContext.HttpContext.RequestServices.GetService <IAuthorization>().Returns((IAuthorization)null); columns.Grid.ViewContext.HttpContext.RequestServices.GetService <LinkGenerator>().Returns(link); IGridColumn <AllTypesView, IHtmlContent> column = columns.AddAction("Details", "fa fa-info"); column.ValueFor(new GridRow <AllTypesView>(view)).WriteTo(writer, HtmlEncoder.Default); String expected = "<a class=\"fa fa-info\" href=\"\"></a>"; String actual = writer.ToString(); Assert.Equal(expected, actual); }
public void AddAction_Authorized_Renders() { AllTypesView view = new AllTypesView(); StringWriter writer = new StringWriter(); IUrlHelper url = context.HttpContext.RequestServices.GetRequiredService <IUrlHelperFactory>().GetUrlHelper(context); IAuthorization authorization = html.Grid.ViewContext !.HttpContext.RequestServices.GetRequiredService <IAuthorization>(); url.Action(Arg.Any <UrlActionContext>()).Returns("/test"); authorization.IsGrantedFor(Arg.Any <Int64?>(), "//Details").Returns(true); IGridColumn <AllTypesView, IHtmlContent> column = columns.AddAction("Details", "fa fa-info"); column.ValueFor(new GridRow <AllTypesView>(view, 0)).WriteTo(writer, HtmlEncoder.Default); String expected = $"<a class=\"fa fa-info\" href=\"/test\" title=\"{Resource.ForAction("Details")}\"></a>"; String actual = writer.ToString(); Assert.Equal(expected, actual); }
public void AddActionLink_Authorized_Renders() { AllTypesView view = new AllTypesView(); Authorization.Provider = Substitute.For <IAuthorizationProvider>(); UrlHelper urlHelper = new UrlHelper(columns.Grid.HttpContext.Request.RequestContext); Authorization.Provider.IsAuthorizedFor(Arg.Any <Int32?>(), Arg.Any <String>(), Arg.Any <String>(), "Details").Returns(true); IGridColumn <AllTypesView> column = columns.AddActionLink("Details", "fa fa-info"); String actual = column.ValueFor(new GridRow <AllTypesView>(view)).ToString(); String expected = $"<a class=\"details-action\" href=\"{urlHelper.Action("Details", new {view.Id})}\">" + "<i class=\"fa fa-info\"></i>" + "</a>"; Assert.Equal(expected, actual); }
public void AddAction_NoAuthorization_Renders() { AllTypesView view = new AllTypesView(); StringWriter writer = new StringWriter(); IUrlHelper url = Substitute.For <IUrlHelper>(); IUrlHelperFactory factory = Substitute.For <IUrlHelperFactory>(); html.Grid.ViewContext?.HttpContext.RequestServices.GetService(typeof(IUrlHelperFactory)).Returns(factory); html.Grid.ViewContext?.HttpContext.RequestServices.GetService(typeof(IAuthorization)).ReturnsNull(); factory.GetUrlHelper(html.Grid.ViewContext).Returns(url); url.Action(Arg.Any <UrlActionContext>()).Returns("/test"); IGridColumn <AllTypesView, IHtmlContent> column = columns.AddAction("Details", "fa fa-info"); column.ValueFor(new GridRow <AllTypesView>(view, 0)).WriteTo(writer, HtmlEncoder.Default); String expected = $"<a class=\"fa fa-info\" href=\"/test\" title=\"{Resource.ForAction("Details")}\"></a>"; String actual = writer.ToString(); Assert.Equal(expected, actual); }
public void AddActionLink_OnNullAuthorizationProviderRendersActionLink() { AllTypesView view = new AllTypesView(); Authorization.Provider = null; String actionLink = ""; column .RenderValueAs(Arg.Any <Func <AllTypesView, String> >()).Returns(column) .AndDoes(info => { actionLink = info.Arg <Func <AllTypesView, String> >().Invoke(view); }); columns.AddActionLink("Details", "fa fa-info"); String actual = actionLink; String expected = String.Format( "<a class=\"details-action\" href=\"{0}\">" + "<i class=\"fa fa-info\"></i>" + "</a>", urlHelper.Action("Details", new { id = view.Id })); Assert.AreEqual(expected, actual); }
public void AddActionLink_NullAuthorization_Renders() { AllTypesView view = new AllTypesView(); StringWriter writer = new StringWriter(); IRouter router = Substitute.For <IRouter>(); columns.Grid.ViewContext.HttpContext.RequestServices.GetService <IAuthorizationProvider>().Returns(null as IAuthorizationProvider); router.GetVirtualPath(Arg.Any <VirtualPathContext>()).Returns(new VirtualPathData(router, "/test")); columns.Grid.ViewContext.RouteData.Routers.Add(router); IGridColumn <AllTypesView> column = columns.AddActionLink("Details", "fa fa-info"); column.ValueFor(new GridRow <AllTypesView>(view)).WriteTo(writer, HtmlEncoder.Default); String actual = writer.ToString(); String expected = $"<a class=\"details-action\" href=\"/test\">" + "<i class=\"fa fa-info\"></i>" + "</a>"; Assert.Equal(expected, actual); }
public void AddActionLink_RendersDeleteLinkAction() { Func <AllTypesView, String> deleteFunc = null; AllTypesView view = new AllTypesView(); column .RenderValueAs(Arg.Any <Func <AllTypesView, String> >()) .Returns(column) .AndDoes(info => { deleteFunc = info.Arg <Func <AllTypesView, String> >(); }); columns.AddActionLink(LinkAction.Delete); String actual = deleteFunc.Invoke(view); String expected = String.Format( "<a class=\"delete-action\" href=\"{0}\">" + "<i class=\"fa fa-times\"></i>" + "</a>", urlHelper.Action("Delete", new { id = view.Id })); Assert.AreEqual(expected, actual); }