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 AddAction_Unauthorized_Empty()
        {
            IGridColumn <AllTypesView, IHtmlContent> actual = columns.AddAction("Edit", "fa fa-pencil-alt");

            Assert.Empty(actual.ValueFor(new GridRow <AllTypesView>(new AllTypesView(), 0)).ToString());
            Assert.Empty(columns);
        }
        public void AddActionLink_Unauthorized_Empty()
        {
            IGridColumn <AllTypesView> actual = columns.AddActionLink("Edit", "fa fa-pencil");

            Assert.Empty(actual.ValueFor(null).ToString());
            Assert.Empty(columns);
        }
        public void AddBoolean_Nullable()
        {
            GridRow <AllTypesView> row = new GridRow <AllTypesView>(new AllTypesView {
                NullableBooleanField = null
            }, 0);
            IGridColumn <AllTypesView, Boolean?> column = columns.AddBoolean(model => model.NullableBooleanField);

            Assert.Empty(column.ValueFor(row).ToString());
        }
        public void AddActionLink_Unauthorized_Empty()
        {
            columns.Grid.ViewContext.HttpContext.ApplicationServices.GetService <IUrlHelper>().Returns(Substitute.For <IUrlHelper>());

            IGridColumn <AllTypesView> actual = columns.AddActionLink("Edit", "fa fa-pencil");

            Assert.Empty(actual.ValueFor(null).ToString());
            Assert.Empty(columns);
        }
Ejemplo n.º 6
0
        public void AddActionLink_Unauthorized_Empty()
        {
            Authorization.Provider = Substitute.For <IAuthorizationProvider>();

            IGridColumn <AllTypesView> actual = columns.AddActionLink("Edit", "fa fa-pencil");

            Assert.Empty(actual.ValueFor(null).ToString());
            Assert.Empty(columns);
        }
        public void AddBooleanProperty_Nullable()
        {
            GridRow <AllTypesView> row = new GridRow <AllTypesView>(new AllTypesView {
                NullableBooleanField = null
            });
            IGridColumn <AllTypesView> column = columns.AddBooleanProperty(model => model.NullableBooleanField);

            String actual = column.ValueFor(row).ToString();

            Assert.Empty(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_True()
        {
            GridRow <AllTypesView> row = new GridRow <AllTypesView>(new AllTypesView {
                BooleanField = true
            });
            IGridColumn <AllTypesView> column = columns.AddBooleanProperty(model => model.BooleanField);

            String actual   = column.ValueFor(row).ToString();
            String expected = Strings.Yes;

            Assert.Equal(expected, actual);
        }
        public void AddBoolean_True()
        {
            GridRow <AllTypesView> row = new GridRow <AllTypesView>(new AllTypesView {
                BooleanField = true
            }, 0);
            IGridColumn <AllTypesView, Boolean> column = columns.AddBoolean(model => model.BooleanField);

            String?actual   = column.ValueFor(row).ToString();
            String?expected = Resource.ForString("Yes");

            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 AddBoolean_Nullable_False()
        {
            GridRow <AllTypesView> row = new GridRow <AllTypesView>(new AllTypesView {
                NullableBooleanField = false
            }, 0);
            IGridColumn <AllTypesView, Boolean?> column = columns.AddBoolean(model => model.NullableBooleanField);

            String?actual   = column.ValueFor(row).ToString();
            String?expected = Resource.ForString("No");

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 13
0
        public void AddBoolean_Nullable_True()
        {
            IGridColumn <AllTypesView, Boolean?> column = columns.AddBoolean(model => model.NullableBooleanField);
            GridRow <AllTypesView> row = new GridRow <AllTypesView>(new AllTypesView {
                NullableBooleanField = true
            });

            String actual   = column.ValueFor(row).ToString();
            String expected = Resource.ForString("Yes");

            Assert.Equal(expected, 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_Nullable_False()
        {
            GridRow <AllTypesView> row = new GridRow <AllTypesView>(new AllTypesView {
                NullableBooleanField = false
            });
            IGridColumn <AllTypesView> column = columns.AddBooleanProperty(model => model.NullableBooleanField);

            String actual   = column.ValueFor(row).ToString();
            String expected = Strings.No;

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 16
0
        public void AddAction_NoId_Throws()
        {
            html.Grid.ViewContext.HttpContext.RequestServices.GetService <IAuthorization>().Returns((IAuthorization)null);
            IGridColumnsOf <Object> gridColumns = new GridColumns <Object>(new Grid <Object>(new Object[0]));

            gridColumns.Grid.ViewContext = html.Grid.ViewContext;

            IGridColumn <Object, IHtmlContent> column = gridColumns.AddAction("Delete", "fa fa-times");

            String actual   = Assert.Throws <Exception>(() => column.ValueFor(new GridRow <Object>(new Object()))).Message;
            String expected = "Object type does not have an id.";

            Assert.Equal(expected, actual);
        }
        public void AddActionLink_NoKey_Throws()
        {
            IGrid <Object>        grid    = new Grid <Object>(new Object[0]);
            IGridColumns <Object> columns = new GridColumns <Object>(grid);

            columns.Grid.HttpContext = HttpContextFactory.CreateHttpContextBase();

            IGridColumn <Object> column = columns.AddActionLink("Delete", "fa fa-times");

            String actual   = Assert.Throws <Exception>(() => column.ValueFor(new GridRow(new Object()))).Message;
            String expected = "Object type does not have a key property.";

            Assert.Equal(expected, actual);
        }
        public void AddAction_NoId_Throws()
        {
            IAuthorization          authorization = html.Grid.ViewContext !.HttpContext.RequestServices.GetRequiredService <IAuthorization>();
            IGridColumnsOf <Object> gridColumns   = new GridColumns <Object>(new Grid <Object>(Array.Empty <Object>()));

            authorization.IsGrantedFor(Arg.Any <Int64?>(), Arg.Any <String>()).Returns(true);
            gridColumns.Grid.ViewContext = html.Grid.ViewContext;

            IGridColumn <Object, IHtmlContent> column = gridColumns.AddAction("Delete", "fa fa-times");

            String actual   = Assert.Throws <Exception>(() => column.ValueFor(new GridRow <Object>(new Object(), 0))).Message;
            String expected = "Object type does not have an id.";

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 19
0
        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 AddActionLink_NoKey_Throws()
        {
            IGrid <Object>          grid    = new Grid <Object>(new Object[0]);
            IGridColumnsOf <Object> columns = new GridColumns <Object>(grid);

            columns.Grid.ViewContext = new ViewContext {
                HttpContext = Substitute.For <HttpContext>()
            };

            IGridColumn <Object> column = columns.AddActionLink("Delete", "fa fa-times");

            String actual   = Assert.Throws <Exception>(() => column.ValueFor(new GridRow <Object>(new Object()))).Message;
            String expected = "Object type does not have a key property.";

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 21
0
        public void AddAction_NoId_Throws()
        {
            IUrlHelperFactory       factory     = Substitute.For <IUrlHelperFactory>();
            IGridColumnsOf <Object> gridColumns = new GridColumns <Object>(new Grid <Object>(Array.Empty <Object>()));

            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(Substitute.For <IUrlHelper>());
            gridColumns.Grid.ViewContext = html.Grid.ViewContext;

            IGridColumn <Object, IHtmlContent> column = gridColumns.AddAction("Delete", "fa fa-times");

            String actual   = Assert.Throws <Exception>(() => column.ValueFor(new GridRow <Object>(new Object(), 0))).Message;
            String expected = "Object type does not have an id.";

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 22
0
        public void AddAction_Authorized_Renders()
        {
            StringWriter   writer        = new();
            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>(new AllTypesView(), 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);
        }
Ejemplo n.º 23
0
        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);
        }
Ejemplo n.º 24
0
        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);
        }
Ejemplo n.º 25
0
        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_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);
        }