public static IGridColumn <T> AddProperty <T, TProperty>(this IGridColumns <T> columns, Expression <Func <T, TProperty> > expression)
 {
     return(columns
            .Add(expression)
            .Css(GetCssClassFor <TProperty>())
            .Titled(ResourceProvider.GetPropertyTitle(expression)));
 }
Beispiel #2
0
        private void AssertCssClassFor <TProperty>(Expression <Func <AllTypesView, TProperty> > property, String expected)
        {
            columns = SubstituteColumns <AllTypesView, TProperty>(column);
            columns.AddProperty(property);

            column.Received().Css(expected);
        }
        public MvcGridExtensionsTests()
        {
            Grid <AllTypesView> grid       = new Grid <AllTypesView>(new AllTypesView[0]);
            HtmlHelper          htmlHelper = HtmlHelperFactory.CreateHtmlHelper();

            html    = new HtmlGrid <AllTypesView>(htmlHelper, grid);
            columns = new GridColumns <AllTypesView>(grid);
        }
Beispiel #4
0
        public void IGridColumns_ReturnsColumns()
        {
            Grid <GridModel> grid = new Grid <GridModel>(new GridModel[0]);

            IGridColumns actual   = ((IGrid)grid).Columns;
            IGridColumns expected = grid.Columns;

            Assert.Same(expected, actual);
        }
        public static IGridColumn <T> AddBooleanProperty <T>(this IGridColumns <T> columns, Expression <Func <T, Boolean> > expression)
        {
            Func <T, Boolean> valueFor = expression.Compile();

            return(columns
                   .AddProperty(expression)
                   .RenderedAs(model =>
                               valueFor(model)
                        ? TableResources.Yes
                        : TableResources.No));
        }
        public static IGridColumn <T> AddActionLink <T>(this IGridColumns <T> columns, String action, String iconClass) where T : class
        {
            if (!IsAuthorizedToView(columns.Grid, action))
            {
                return(new GridColumn <T, String>(columns.Grid, model => ""));
            }

            return(columns
                   .Add(model => GetLink(columns.Grid, model, action, iconClass))
                   .Css("action-cell")
                   .Encoded(false));
        }
Beispiel #7
0
        public void Build_BuildsColumns()
        {
            IGridColumns expected      = htmlGrid.Grid.Columns;
            Boolean      builderCalled = false;

            htmlGrid.Build(actual =>
            {
                Assert.Same(expected, actual);
                builderCalled = true;
            });

            Assert.True(builderCalled);
        }
Beispiel #8
0
        private IGridColumns <TModel> SubstituteColumns <TModel, TProperty>(IGridColumn <TModel> column)
        {
            IGridColumns <TModel> columns = Substitute.For <IGridColumns <TModel> >();

            columns.Add(Arg.Any <Expression <Func <TModel, String> > >()).Returns(column);
            columns.Add(Arg.Any <Expression <Func <TModel, Boolean> > >()).Returns(column);
            columns.Add(Arg.Any <Expression <Func <TModel, Boolean?> > >()).Returns(column);
            columns.Add(Arg.Any <Expression <Func <TModel, DateTime> > >()).Returns(column);
            columns.Add(Arg.Any <Expression <Func <TModel, DateTime?> > >()).Returns(column);
            columns.Add(Arg.Any <Expression <Func <TModel, TProperty> > >()).Returns(column);

            return(columns);
        }
        public static IGridColumn <T> AddBooleanProperty <T>(this IGridColumns <T> columns, Expression <Func <T, Boolean?> > property)
        {
            Func <T, Boolean?> valueFor = property.Compile();

            return(columns
                   .AddProperty(property)
                   .RenderedAs(model =>
                               valueFor(model) != null
                        ? valueFor(model) == true
                            ? TableResources.Yes
                            : TableResources.No
                        : ""));
        }
Beispiel #10
0
        public void AddActionLink_OnModelWihoutKeyPropertyThrows()
        {
            Func <Object, String> renderer = null;
            IGridColumn <Object>  column   = SubstituteColumn <Object>();
            IGridColumns <Object> columns  = SubstituteColumns <Object, String>(column);

            columns
            .Add(Arg.Any <Expression <Func <Object, String> > >())
            .Returns(column)
            .AndDoes(info =>
            {
                renderer = info.Arg <Expression <Func <Object, String> > >().Compile();
            });

            columns.AddActionLink("Delete", "fa fa-times");

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

            Assert.Equal(expected, actual);
        }
 public static IGridColumn <T> AddDateTimeProperty <T>(this IGridColumns <T> columns, Expression <Func <T, DateTime?> > expression)
 {
     return(columns.AddProperty(expression).Formatted("{0:g}"));
 }
Beispiel #12
0
 public MvcGridExtensionsTests()
 {
     column   = SubstituteColumn <AllTypesView>();
     htmlGrid = SubstituteHtmlGrid <AllTypesView>();
     columns  = SubstituteColumns <AllTypesView, DateTime?>(column);
 }
 public static IGridColumn <T> AddDateProperty <T>(this IGridColumns <T> columns, Expression <Func <T, DateTime> > property)
 {
     return(columns.AddProperty(property).Formatted("{0:d}"));
 }