Exemple #1
0
        public void format_data_smoke_test()
        {
            var grid = new TargetGrid();

            grid.Column(x => x.Count);
            grid.Column(x => x.IsCool);
            grid.Column(x => x.Name);

            var data = new GridDefTarget[] {
                new GridDefTarget {
                    Count = 1, IsCool = true, Name = "Scooby"
                },
                new GridDefTarget {
                    Count = 2, IsCool = true, Name = "Velma"
                },
                new GridDefTarget {
                    Count = 3, IsCool = true, Name = "Daphne"
                },
            };

            IProjection <GridDefTarget> projection = grid.As <IGridDefinition <GridDefTarget> >().Projection.As <IProjection <GridDefTarget> >();


            var dicts = data.Select(x => {
                var node = new DictionaryMediaNode();

                projection.Write(new ProjectionContext <GridDefTarget>(new InMemoryServiceLocator(), x), node);

                return(node.Values);
            });

            dicts.Select(x => x["Name"]).ShouldHaveTheSameElementsAs("Scooby", "Velma", "Daphne");
            dicts.Select(x => x["Count"]).ShouldHaveTheSameElementsAs(1, 2, 3);
        }
        public void format_data_smoke_test()
        {
            var grid = new TargetGrid();

            grid.Column(x => x.Count);
            grid.Column(x => x.IsCool);
            grid.Column(x => x.Name);

            var data = new GridDefTarget[] {
                new GridDefTarget {
                    Count = 1, IsCool = true, Name = "Scooby"
                },
                new GridDefTarget {
                    Count = 2, IsCool = true, Name = "Velma"
                },
                new GridDefTarget {
                    Count = 3, IsCool = true, Name = "Daphne"
                },
            };

            var dicts = grid.As <IGridDefinition <GridDefTarget> >().FormatData(data);

            dicts.Select(x => x["Name"]).ShouldHaveTheSameElementsAs("Scooby", "Velma", "Daphne");
            dicts.Select(x => x["Count"]).ShouldHaveTheSameElementsAs(1, 2, 3);
        }
Exemple #3
0
        public void create_column_json_with_data_elements()
        {
            var grid = new TargetGrid();

            grid.Column(x => x.Count);
            grid.Data(x => x.IsCool);
            grid.Column(x => x.Name);

            var json = grid.As <IGridDefinition>().ToColumnJson();

            json
            .ShouldEqual("[{name: \"Count\", field: \"Count\", id: \"Count\", sortable: true, frozen: false}, {name: \"Name\", field: \"Name\", id: \"Name\", sortable: true, frozen: false}]");
        }
Exemple #4
0
        public void create_all_frozen_columns_json()
        {
            var grid = new TargetGrid();

            grid.Column(x => x.Count).Frozen(true);
            grid.Column(x => x.IsCool).Frozen(true);
            grid.Column(x => x.Name).Frozen(true);

            var json = grid.As <IGridDefinition>().ToColumnJson();

            json
            .ShouldEqual("[{name: \"Count\", field: \"Count\", id: \"Count\", sortable: true, frozen: true}, {name: \"IsCool\", field: \"IsCool\", id: \"IsCool\", sortable: true, frozen: true}, {name: \"Name\", field: \"Name\", id: \"Name\", sortable: true, frozen: true}]");
        }
Exemple #5
0
        public void create_column_json()
        {
            var grid = new TargetGrid();

            grid.Column(x => x.Count);
            grid.Column(x => x.IsCool);
            grid.Column(x => x.Name);

            var json = grid.As <IGridDefinition>().ToColumnJson(new StubFieldAccessService());

            json
            .ShouldEqual("[{name: \"en-US_Count\", field: \"Count\", id: \"Count\", sortable: true, frozen: false}, {name: \"en-US_IsCool\", field: \"IsCool\", id: \"IsCool\", sortable: true, frozen: false}, {name: \"en-US_Name\", field: \"Name\", id: \"Name\", sortable: true, frozen: false}]");
        }
Exemple #6
0
        public void projection_does_not_include_not_authorized_columns()
        {
            var grid = new TargetGrid();

            grid.Column(x => x.Count);
            grid.Column(x => x.Name);
            grid.Column(x => x.IsCool);

            var service = new StubFieldAccessService();

            service.SetRights <GridDefTarget>(x => x.Count, AccessRight.ReadOnly);
            service.SetRights <GridDefTarget>(x => x.Name, AccessRight.None);

            var projection = grid.ToProjection(service);

            projection.As <IProjection <GridDefTarget> >().Accessors()
            .Select(x => x.Name)
            .ShouldHaveTheSameElementsAs("Count", "IsCool");
        }
Exemple #7
0
        public void create_column_json_with_authorization_field_rights()
        {
            var grid = new TargetGrid();

            grid.Column(x => x.Count);
            grid.Data(x => x.IsCool);
            grid.Column(x => x.Name);
            grid.Column(x => x.Random);

            var service = new StubFieldAccessService();

            service.SetRights <GridDefTarget>(x => x.Random, AccessRight.None);
            service.SetRights <GridDefTarget>(x => x.Name, AccessRight.ReadOnly);

            var json = grid.As <IGridDefinition>().ToColumnJson(service);

            json
            .ShouldEqual("[{name: \"en-US_Count\", field: \"Count\", id: \"Count\", sortable: true, frozen: false}, {name: \"en-US_Name\", field: \"Name\", id: \"Name\", sortable: true, frozen: false}]");
        }