コード例 #1
0
        public void GetBlocksWithProperty_OnOneGridNoneFound_ShouldReturnEmptyCollection()
        {
            string TestPropertyName = "IntegrityPercent";

            // Test data that doesn't contain any matching element on target grid, but contains on another grid
            XElement TestBlueprint = TestHelpers.DataBuilder.BuildBlueprint()
                                     .AndGridWith()
                                     .AndBlockWith().ThatsAll()
                                     .AndBlockWith().ThatsAll()
                                     .ExportThis(out var TargetGrid) // Note out TargetGrid
                                     .ThatsAll()
                                     .AndGridWith()
                                     .AndBlockWith().Integrity(0.5).ThatsAll() // Note Integrity set
                                     .AndBlockWith().ThatsAll();

            BlueprintDataContext DataContext = new BlueprintDataContext(TestBlueprint);

            // Affirm preconditions
            Assert.Multiple(() =>
            {
                Assert.That(TargetGrid.Descendants("IntegrityPercent").Count, Is.Zero,
                            $"Test blueprints's target grid shouldn't contain any {TestPropertyName} nodes.");

                Assert.That(TestBlueprint.Descendants("IntegrityPercent").Count, Is.Not.Zero,
                            $"Test blueprint should contain at least one {TestPropertyName} node on a non-target grid.");
            });

            var res = DataContext.GetBlocksWithProperty(TestPropertyName, TargetGrid);

            Assert.That(res, Is.Not.Null.And.Empty);
        }
コード例 #2
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);
        }
コード例 #3
0
        public void GetBlocksBySubtypeName_OnOneGridNotFound_ShouldReturnEmptyCollection()
        {
            string TestSubtypeName = "TestSubtypeName";

            // Test data that doesn't contain any matching element on target grid, but contains on another grid
            XElement TestBlueprint = TestHelpers.DataBuilder.BuildBlueprint()
                                     .AndGridWith()
                                     .AndBlockWith().ThatsAll()
                                     .AndBlockWith().ThatsAll()
                                     .ExportThis(out var TargetGrid) // Note out TargetGrid
                                     .ThatsAll()
                                     .AndGridWith()
                                     .AndBlockWith().SubtypeName(TestSubtypeName).ThatsAll() // Note SubtypeName set
                                     .AndBlockWith().ThatsAll();

            BlueprintDataContext DataContext = new BlueprintDataContext(TestBlueprint);

            // Affirm preconditions
            Assert.Multiple(() =>
            {
                Assert.That(TargetGrid.Descendants("SubtypeName").Where(e => e.Value == TestSubtypeName).Count, Is.Zero,
                            $"Test blueprints's target grid shouldn't contain any nodes with SubtypeName of {TestSubtypeName}.");

                Assert.That(TestBlueprint.Descendants("SubtypeName").Where(e => e.Value == TestSubtypeName).Count, Is.Not.Zero,
                            $"Test blueprint should contain at least one node with SubtypeName of {TestSubtypeName} on a non-target grid.");
            });

            var res = DataContext.GetBlocksBySubtypeName(TestSubtypeName, TargetGrid);

            Assert.That(res, Is.Not.Null.And.Empty);
        }
        protected void SourceGrid_CustomCallback(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewCustomCallbackEventArgs e)
        {
            rowValues = new List <object>();
            switch (e.Parameters)
            {
            case "removeSelectedRows":
                rowValues = TargetGrid.GetSelectedFieldValues(fieldNames);
                var categoryIDs = new StringBuilder();

                for (int i = 0; i < rowValues.Count(); i++)
                {
                    var categoryID = (rowValues[i] as object[])[0];
                    if (i < rowValues.Count() - 1)
                    {
                        categoryIDs.AppendFormat("{0}, ", categoryID);
                    }
                    else
                    {
                        categoryIDs.Append(categoryID);
                    }
                }

                if (categoryIDs.Length > 0)
                {
                    TargetDS.DeleteCommand = string.Format("DELETE FROM [CategoriesUpdated] WHERE [CategoryID] IN ({0})", categoryIDs);
                    TargetDS.Delete();

                    foreach (object[] rowValue in rowValues)
                    {
                        SourceDS.InsertCommand = string.Format(
                            "INSERT INTO [Categories] ([CategoryID], [CategoryName], [Description]) VALUES ({0}, '{1}', '{2}')",
                            rowValue[0], rowValue[1], rowValue[2]);
                        SourceDS.Insert();
                    }
                    SourceGrid.DataBind();
                }
                break;

            case "removeAllRows":
                for (int i = 0; i < TargetGrid.VisibleRowCount; i++)
                {
                    rowValues.Add(TargetGrid.GetRowValues(i, fieldNames));
                }
                if (rowValues.Count > 0)
                {
                    TargetDS.DeleteCommand = "DELETE * FROM [CategoriesUpdated]";
                    TargetDS.Delete();

                    foreach (object[] rowValue in rowValues)
                    {
                        SourceDS.InsertCommand = string.Format(
                            "INSERT INTO [Categories] ([CategoryID], [CategoryName], [Description]) VALUES ({0}, '{1}', '{2}')",
                            rowValue[0], rowValue[1], rowValue[2]);
                        SourceDS.Insert();
                    }
                    SourceGrid.DataBind();
                }
                break;
            }
        }
コード例 #5
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"
                },
            };

            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);
        }
コード例 #6
0
        public void source_happy_path_with_query_object()
        {
            var targetGrid = new TargetGrid();

            targetGrid.SourceIs <QueryGoodSource>();

            targetGrid.SourceType.ShouldEqual(typeof(QueryGoodSource));
        }
コード例 #7
0
        public void select_data_source_url_with_source_type_and_no_query()
        {
            var targetGrid = new TargetGrid();

            targetGrid.SourceIs <SimpleGoodSource>();

            targetGrid.DetermineRunnerType().ShouldEqual(typeof(GridRunner <GridDefTarget, TargetGrid, SimpleGoodSource>));
        }
コード例 #8
0
        public void select_data_source_url_with_source_type_and_a_query()
        {
            var targetGrid = new TargetGrid();

            targetGrid.SourceIs <QueryGoodSource>();

            targetGrid.DetermineRunnerType().ShouldEqual(typeof(GridRunner <GridDefTarget, TargetGrid, QueryGoodSource, DifferentClass>));
        }
コード例 #9
0
        public void is_paged_true_with_paged_source()
        {
            var grid = new TargetGrid();

            grid.SourceIs <PagedSource>();

            grid.IsPaged().ShouldBeTrue();
        }
コード例 #10
0
        public void is_paged_false_with_non_paged_source()
        {
            var grid = new TargetGrid();

            grid.SourceIs <SimpleGoodSource>();

            grid.IsPaged().ShouldBeFalse();
        }
コード例 #11
0
        public void select_data_source_url_with_paged_source()
        {
            var targetGrid = new TargetGrid();

            targetGrid.SourceIs <PagedSource>();

            targetGrid.As <IGridDefinition>().DetermineRunnerType().ShouldEqual(typeof(PagedGridRunner <GridDefTarget, TargetGrid, PagedSource, SpecialPagedQuery>));
        }
コード例 #12
0
ファイル: Program.cs プロジェクト: falkowskibartek/Battleship
        private static void WriteTargetGrid(TargetGrid targetGrid)
        {
            Console.WriteLine("Legend:\n\tO - Miss\n\tX - Hit");
            Console.WriteLine();

            var visualisedTargetGrid = targetGrid.ToString();

            Console.WriteLine(visualisedTargetGrid);
            Console.WriteLine();
        }
コード例 #13
0
 protected virtual void AsDefault()
 {
     if (DialogResult.Yes == XtraMessageBoxHelper.ShowYesNoAndTips("您确定要恢复默认设置吗?"))
     {
         GridConfigFactory.Current.DeleteConfig(TargetGrid.GridID, Guid.Empty);
         TargetGrid.LoadConfig();
         TargetGrid.IsConfigChange = false;
         Cancel();
     }
 }
コード例 #14
0
ファイル: Program.cs プロジェクト: falkowskibartek/Battleship
        private static ShotResult HandleShot(Grid grid, TargetGrid targetGrid, OceanGrid oceanGrid)
        {
            Console.WriteLine("Call out your shot!");

            var shotCoordinate = new Coordinate(grid.Size, Console.ReadLine());
            var shotResult     = oceanGrid.TakeTheShot(shotCoordinate);

            targetGrid.MarkShot(new TargetGridMark(shotCoordinate, shotResult.Result));

            return(shotResult);
        }
コード例 #15
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}]");
        }
コード例 #16
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}]");
        }
        protected void btnRestore_Click(object sender, EventArgs e)
        {
            File.Copy(
                Server.MapPath("~/App_Data/nwindNew_backup.mdb"),
                Server.MapPath("~/App_Data/nwindNew.mdb"),
                true);

            SourceGrid.DataBind();
            SourceGrid.Selection.UnselectAll();

            TargetGrid.DataBind();
            TargetGrid.Selection.UnselectAll();
        }
コード例 #18
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}]");
        }
コード例 #19
0
 protected MySlimBlock GetCubeBlock()
 {
     if (m_compoundId.HasValue)
     {
         var block = TargetGrid.GetCubeBlock(m_targetCube);
         if (block == null)
         {
             return(null);
         }
         return((block.FatBlock as MyCompoundCubeBlock).GetBlock(m_compoundId.Value));
     }
     else
     {
         return(TargetGrid.GetCubeBlock(m_targetCube));
     }
 }
コード例 #20
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");
        }
コード例 #21
0
ファイル: Program.cs プロジェクト: falkowskibartek/Battleship
        static void Main(string[] args)
        {
            var grid       = new Grid();
            var targetGrid = new TargetGrid(grid);
            var oceanGrid  = new OceanGrid(grid);

            ShotResult shotResult = null;

            while (!oceanGrid.IsTheEntireFleetSunk)
            {
                WriteTargetGrid(targetGrid);
                WriteShotResult(shotResult);
                shotResult = HandleShot(grid, targetGrid, oceanGrid);

                Console.Clear();
            }

            Console.WriteLine("The entire fleet is sunk. You won the game!");
        }
コード例 #22
0
            public void ReTarget([CanBeNull] Actor actor, int gridWeight)
            {
                if (null != TargetGrid && TargetGridSlot >= 0)
                {
                    TargetGrid.EmptyGridSlot(TargetGridSlot);
                }
                TargetGrid     = null;
                TargetGridSlot = -1;

                Actor = actor;

                Player player = Actor as Player;

                if (null != player)
                {
                    TargetGrid     = player.KungFuGrid;
                    TargetGridSlot = TargetGrid.GetAvailableGridSlot(gridWeight);
                }
            }
コード例 #23
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}]");
        }
コード例 #24
0
        private void btnAutoGenerated_Click(object sender, EventArgs e)
        {
            if (TargetGrid.EntityType == null)
            {
                XtraMessageBoxHelper.ShowWarning("没有指定表格的实体类型 EntityType");
                return;
            }
            string typeName = TargetGrid.EntityType.FullName;
            var    meta     = EntityMetadataFactory.Current.Get(typeName);

            if (meta == null)
            {
                XtraMessageBoxHelper.ShowWarning("没有指定实体元数据");
                return;
            }
            XtraMessageBoxHelper.ShowYesNoAndTips("确定自动生成列吗?", d =>
            {
                TargetGrid.OptionsBehavior.AutoPopulateColumns = false;
                TargetGrid.OptionsBehavior.Editable            = true;
                TargetGrid.Columns.Clear();

                for (int index = 0; index < meta.EntityFields.Count; index++)
                {
                    EntityField filed              = meta.EntityFields[index];
                    TreeListColumn column          = TargetGrid.Columns.Add();
                    column.Name                    = "tree_{0}_{1}".FS(typeName, filed.FieldName);
                    column.FieldName               = filed.FieldName;
                    column.Caption                 = filed.FieldComment;
                    column.VisibleIndex            = index + 1;
                    column.OptionsColumn.AllowEdit = false;
                    var dataType                   = EntityMetadata.GetFastProperty(TargetGrid.EntityType, filed.FieldName).Property.PropertyType;
                    if (dataType == typeof(DateTime) || dataType == typeof(DateTime?))
                    {
                        column.Format.FormatType   = DevExpress.Utils.FormatType.DateTime;
                        column.Format.FormatString = "yyyy-MM-dd HH:mm:ss";
                    }
                }
                Grid.RefreshData();
                TargetGrid.BestFitColumns();
            });
        }