示例#1
0
        private void TestConnections(IFeatureWorkspace ws)
        {
            IFieldsEdit fields = new FieldsClass();

            fields.AddField(FieldUtils.CreateOIDField());
            fields.AddField(FieldUtils.CreateIntegerField("LineTyp", "LineTyp"));
            fields.AddField(FieldUtils.CreateShapeField(
                                "Shape", esriGeometryType.esriGeometryPolyline,
                                SpatialReferenceUtils.CreateSpatialReference
                                    ((int)esriSRProjCS2Type.esriSRProjCS_CH1903Plus_LV95,
                                    true), 1000, false, false));

            IFeatureClass fc =
                DatasetUtils.CreateSimpleFeatureClass(ws, "TestConnections", fields,
                                                      null);
            IList <ITable> tbls = new[] { (ITable)fc };

            // make sure the table is known by the workspace
            ((IWorkspaceEdit)ws).StartEditing(false);
            ((IWorkspaceEdit)ws).StopEditing(true);

            {
                IFeature row = fc.CreateFeature();
                row.set_Value(1, 1);
                row.Shape =
                    CurveConstruction.StartLine(100, 100).LineTo(200, 200).Curve;
                row.Store();
            }
            {
                IFeature row = fc.CreateFeature();
                row.set_Value(1, 2);
                row.Shape =
                    CurveConstruction.StartLine(100, 100.1).LineTo(100, 200).Curve;
                row.Store();
            }

            IList <QaConnectionRule> rules = new[]
            {
                new QaConnectionRule(tbls, new[] { "LineTyp = 1" }),
                new QaConnectionRule(tbls, new[] { "LineTyp = 2" })
            };
            var test = new QaConnections(new[] { fc }, rules, 0);

            test.QaError += Test_QaError;
            _errorCount   = 0;
            test.Execute();
            Assert.AreEqual(0, _errorCount);
            test.QaError -= Test_QaError;

            var container = new TestContainer();

            container.AddTest(test);
            container.QaError += Test_QaError;
            _errorCount        = 0;
            container.Execute();
            Assert.AreEqual(0, _errorCount);
        }
        public void Duplicates()
        {
            IDomain domain1 = DomainUtils.AddDomain(_workspace,
                                                    DomainUtils.CreateCodedValueDomain(
                                                        "DOM_FIELD1",
                                                        esriFieldType.esriFieldTypeInteger,
                                                        "Description of DOM_FIELD1",
                                                        new CodedValue(1, "Value 1"),
                                                        new CodedValue(2, "Value 2")));
            IDomain domain2 = DomainUtils.AddDomain(_workspace,
                                                    DomainUtils.CreateCodedValueDomain(
                                                        "DOM_FIELD2",
                                                        esriFieldType.esriFieldTypeInteger,
                                                        "Description of DOM_FIELD2",
                                                        new CodedValue(1, "Value 1"),
                                                        new CodedValue(2, "Value 2")));

            // domain (not used in table) with duplicate name
            DomainUtils.AddDomain(_workspace,
                                  DomainUtils.CreateCodedValueDomain("DOM_FIELD3",
                                                                     esriFieldType
                                                                     .esriFieldTypeInteger,
                                                                     "Description of DOM_FIELD2",
                                                                     new CodedValue(1,
                                                                                    "Value 1"),
                                                                     new CodedValue(2,
                                                                                    "Value 2")));

            DomainUtils.AddDomain(_workspace,
                                  DomainUtils.CreateRangeDomain("DOM_FIELD4",
                                                                esriFieldType.esriFieldTypeInteger,
                                                                0, 100,
                                                                "Description of DOM_FIELD2"));

            IField field1 = FieldUtils.CreateField("FIELD1", esriFieldType.esriFieldTypeInteger);
            IField field2 = FieldUtils.CreateField("FIELD2", esriFieldType.esriFieldTypeInteger);
            IField field3 = FieldUtils.CreateTextField("FIELD3", 20);

            ((IFieldEdit)field1).Domain_2 = domain1;
            ((IFieldEdit)field2).Domain_2 = domain2;

            ITable table = DatasetUtils.CreateTable(_workspace,
                                                    MethodBase.GetCurrentMethod().Name,
                                                    FieldUtils.CreateOIDField(),
                                                    field1, field2, field3);

            const int  maxLength    = 25;
            const bool noDuplicates = true;
            var        runner       =
                new QaTestRunner(new QaSchemaFieldDomainDescriptions(table, maxLength,
                                                                     noDuplicates,
                                                                     null));

            runner.Execute();

            Assert.AreEqual(1, runner.Errors.Count);
        }
示例#3
0
        private static void TestReferencedGuid(IFeatureWorkspace ws)
        {
            IFieldsEdit fields1 = new FieldsClass();

            fields1.AddField(FieldUtils.CreateOIDField());
            fields1.AddField(FieldUtils.CreateField("Pk", esriFieldType.esriFieldTypeGUID));

            ITable tbl1 = DatasetUtils.CreateTable(ws, "TestReferencedGuid1", null, fields1);

            IFieldsEdit fields2 = new FieldsClass();

            fields2.AddField(FieldUtils.CreateOIDField());
            fields2.AddField(FieldUtils.CreateTextField("Fk", 50));

            ITable tbl2 = DatasetUtils.CreateTable(ws, "TestReferencedGuid2", null, fields2);

            IFieldsEdit fields3 = new FieldsClass();

            fields3.AddField(FieldUtils.CreateOIDField());
            fields3.AddField(FieldUtils.CreateField("Fk", esriFieldType.esriFieldTypeGUID));

            ITable tbl3 = DatasetUtils.CreateTable(ws, "TestReferencedGuid3", null, fields3);

            // make sure the table is known by the workspace
            ((IWorkspaceEdit)ws).StartEditing(false);
            ((IWorkspaceEdit)ws).StopEditing(true);

            for (int i = 0; i < 5; i++)
            {
                Guid guid = Guid.NewGuid();
                CreateRow(tbl1, guid.ToString("B"));

                if (i % 2 == 0)
                {
                    CreateRow(tbl2, guid.ToString());
                }
                else
                {
                    CreateRow(tbl3, guid.ToString("B"));
                }
            }

            var test = new QaUnreferencedRows(tbl1,
                                              new[] { tbl2, tbl3 },
                                              new[] { "pk,fk", "pk,fk" });

            using (var r = new QaTestRunner(test))
            {
                r.Execute();
                Assert.AreEqual(0, r.Errors.Count);
            }

            var container = new QaContainerTestRunner(10000, test);

            container.Execute();
            Assert.AreEqual(0, container.Errors.Count);
        }
示例#4
0
        private static void CanDetect1ToNUnique([NotNull] IFeatureWorkspace workspace)
        {
            const string uniqueFieldName = "Unique";

            ITable tableOrig;
            {
                IFieldsEdit fields = new FieldsClass();
                fields.AddField(FieldUtils.CreateOIDField());
                fields.AddField(FieldUtils.CreateField(
                                    uniqueFieldName, esriFieldType.esriFieldTypeInteger));
                ITable table = TestWorkspaceUtils.CreateSimpleTable(
                    workspace, "Relate1NUnique1", fields);
                for (var i = 0; i < 10; i++)
                {
                    IRow row = table.CreateRow();
                    row.set_Value(1, i);
                    row.Store();
                }

                tableOrig = table;
            }
            ITable tableRel;
            {
                IFieldsEdit fields = new FieldsClass();
                fields.AddField(FieldUtils.CreateOIDField());
                fields.AddField(FieldUtils.CreateField(
                                    "Ref", esriFieldType.esriFieldTypeInteger));
                ITable table = TestWorkspaceUtils.CreateSimpleTable(
                    workspace, "Relate1NUnique2", fields);
                for (var i = 0; i < 10; i++)
                {
                    IRow row = table.CreateRow();
                    row.set_Value(1, i);
                    row.Store();
                }

                tableRel = table;
            }
            IRelationshipClass rel =
                TestWorkspaceUtils.CreateSimple1NRelationship(workspace,
                                                              "rel1NUnique", tableOrig,
                                                              tableRel, uniqueFieldName, "Ref");

            ITable relTab = TableJoinUtils.CreateQueryTable(rel, JoinType.InnerJoin);

            foreach (bool forceInMemoryTableSort in new[] { true, false })
            {
                var test = new QaUnique(relTab, "Relate1NUnique1." + uniqueFieldName)
                {
                    ForceInMemoryTableSorting = forceInMemoryTableSort
                };

                var runner = new QaTestRunner(test);
                runner.Execute();
                AssertUtils.NoError(runner);
            }
        }
示例#5
0
        private static IEnumerable <IField> CreateAttributeFields(
            [NotNull] IIssueTableFieldManagement fields)
        {
            yield return(FieldUtils.CreateOIDField());

            foreach (IField field in fields.CreateFields())
            {
                yield return(field);
            }
        }
示例#6
0
        public void CanCreateGdbFeatureClass()
        {
            // An in-memory backing dataset is created automatically, if no factory method is provided
            GdbFeatureClass gdbFeatureClass =
                new GdbFeatureClass(41, "TESTABLE", esriGeometryType.esriGeometryPoint,
                                    "Test table");

            IFeatureClass featureClass = gdbFeatureClass;

            Assert.AreEqual(41, featureClass.ObjectClassID);
            Assert.AreEqual("TESTABLE", DatasetUtils.GetName(featureClass));
            Assert.AreEqual("Test table",
                            DatasetUtils.GetAliasName(featureClass));
            Assert.AreEqual(esriGeometryType.esriGeometryPoint,
                            featureClass.ShapeType);

            Assert.False(featureClass.HasOID);
            Assert.Null(featureClass.OIDFieldName);

            Assert.AreEqual(0, GdbQueryUtils.Count(featureClass, ""));

            // Add OID field
            gdbFeatureClass.AddField(FieldUtils.CreateOIDField());

            // Add Shape field
            gdbFeatureClass.AddField(
                FieldUtils.CreateShapeField(
                    esriGeometryType.esriGeometryPoint,
                    SpatialReferenceUtils.CreateSpatialReference(WellKnownHorizontalCS.LV95)));

            Assert.True(featureClass.HasOID);
            Assert.AreEqual("OBJECTID", featureClass.OIDFieldName);
            Assert.AreEqual("SHAPE", featureClass.ShapeFieldName);

            IQueryFilter queryFilter = GdbQueryUtils.CreateQueryFilter("OBJECTID");

            queryFilter.WhereClause = "OBJECTID < 0";

            Assert.AreEqual(0,
                            GdbQueryUtils.Count(featureClass, queryFilter));

            var backingDataset = gdbFeatureClass.BackingDataset as InMemoryDataset;

            Assert.NotNull(backingDataset);

            backingDataset.AllRows.Add(new GdbRow(1, gdbFeatureClass));

            Assert.AreEqual(0,
                            GdbQueryUtils.Count(featureClass, queryFilter));

            queryFilter.WhereClause = "OBJECTID > 0";

            Assert.AreEqual(1,
                            GdbQueryUtils.Count(featureClass, queryFilter));
        }
示例#7
0
        private static void TestReferenced(IFeatureWorkspace ws)
        {
            IFieldsEdit fields1 = new FieldsClass();

            fields1.AddField(FieldUtils.CreateOIDField());
            fields1.AddField(FieldUtils.CreateSmallIntegerField("Pk"));

            ITable tbl1 = DatasetUtils.CreateTable(ws, "TestReferenced1", null, fields1);

            IFieldsEdit fields2 = new FieldsClass();

            fields2.AddField(FieldUtils.CreateOIDField());
            fields2.AddField(FieldUtils.CreateSmallIntegerField("Fk"));

            ITable tbl2 = DatasetUtils.CreateTable(ws, "TestReferenced2", null, fields2);

            IFieldsEdit fields3 = new FieldsClass();

            fields3.AddField(FieldUtils.CreateOIDField());
            fields3.AddField(FieldUtils.CreateIntegerField("Fk"));

            ITable tbl3 = DatasetUtils.CreateTable(ws, "TestReferenced3", null, fields3);

            // make sure the table is known by the workspace
            ((IWorkspaceEdit)ws).StartEditing(false);
            ((IWorkspaceEdit)ws).StopEditing(true);

            CreateRow(tbl1, 1);
            CreateRow(tbl1, 2);
            CreateRow(tbl1, 3);
            CreateRow(tbl1, 4);
            CreateRow(tbl1, 5);

            CreateRow(tbl2, 1);
            CreateRow(tbl2, 3);
            CreateRow(tbl2, 5);

            CreateRow(tbl3, 2);
            CreateRow(tbl3, 4);

            var test = new QaUnreferencedRows(tbl1,
                                              new[] { tbl2, tbl3 },
                                              new[] { "pk,fk", "pk,fk" });

            using (var r = new QaTestRunner(test))
            {
                r.Execute();
                Assert.AreEqual(0, r.Errors.Count);
            }

            var container = new QaContainerTestRunner(10000, test);

            container.Execute();
            Assert.AreEqual(0, container.Errors.Count);
        }
示例#8
0
        private static void TestNMRelation(IFeatureWorkspace ws)
        {
            IFieldsEdit fields1 = new FieldsClass();

            fields1.AddField(FieldUtils.CreateOIDField());
            fields1.AddField(FieldUtils.CreateIntegerField("Pk"));

            ITable tbl1 = DatasetUtils.CreateTable(ws, "TestNMRelation1", null, fields1);

            IFieldsEdit fields2 = new FieldsClass();

            fields2.AddField(FieldUtils.CreateOIDField());
            fields2.AddField(FieldUtils.CreateIntegerField("Fk"));

            ITable tbl2 = DatasetUtils.CreateTable(ws, "TestNMRelation2", null, fields2);

            IRelationshipClass rel = CreateSimpleMNRelationship(ws, "TestNMRelationRel", tbl1,
                                                                tbl2, "Pk", "Fk");

            ((IWorkspaceEdit)ws).StartEditing(false);
            IRow r11 = CreateRow(tbl1, 8);
            IRow r12 = CreateRow(tbl1, 12);
            IRow r13 = CreateRow(tbl1, 7);

            IRow r21 = CreateRow(tbl2, 9);
            IRow r22 = CreateRow(tbl2, 5);
            IRow r23 = CreateRow(tbl2, 4);

            Assert.NotNull(r12);             // not used otherwise

            rel.CreateRelationship((IObject)r11, (IObject)r21);
            rel.CreateRelationship((IObject)r11, (IObject)r23);
            rel.CreateRelationship((IObject)r13, (IObject)r22);

            r22.set_Value(1, 6);
            r22.Store();

            ((IWorkspaceEdit)ws).StopEditing(true);

            var test = new QaUnreferencedRows(tbl1,
                                              new[] { tbl2 },
                                              new[] { "pk,pk,TestNMRelationRel,fk,fk" });

            using (var r = new QaTestRunner(test))
            {
                r.Execute();
                Assert.AreEqual(2, r.Errors.Count);
            }

            var container = new QaContainerTestRunner(10000, test);

            container.Execute();
            Assert.AreEqual(2, container.Errors.Count);
        }
        private static void TestConditionCoincidence(IFeatureWorkspace ws)
        {
            IFieldsEdit fields = new FieldsClass();

            fields.AddField(FieldUtils.CreateOIDField());
            fields.AddField(FieldUtils.CreateIntegerField("LandId"));
            fields.AddField(FieldUtils.CreateIntegerField("OtherId"));
            fields.AddField(FieldUtils.CreateShapeField(
                                "Shape", esriGeometryType.esriGeometryPolyline,
                                SpatialReferenceUtils.CreateSpatialReference
                                    ((int)esriSRProjCS2Type.esriSRProjCS_CH1903Plus_LV95,
                                    true), 1000, false, false));

            IFeatureClass fc1 =
                DatasetUtils.CreateSimpleFeatureClass(ws, "TestConditionCoincidence1",
                                                      fields,
                                                      null);
            IFeatureClass fc2 =
                DatasetUtils.CreateSimpleFeatureClass(ws, "TestConditionCoincidence2",
                                                      fields,
                                                      null);

            ((IWorkspaceEdit)ws).StartEditing(false);
            ((IWorkspaceEdit)ws).StopEditing(true);

            {
                IFeature row = fc1.CreateFeature();
                row.set_Value(1, 1);
                row.Shape = CurveConstruction.StartLine(100, 100).LineTo(200, 200).Curve;
                row.Store();
            }
            {
                IFeature row = fc2.CreateFeature();
                row.set_Value(1, 1);
                row.Shape = CurveConstruction
                            .StartLine(100.5, 100).LineTo(200.5, 200).Curve;
                row.Store();
            }

            // test without ignore conditions --> line is near, but not coincident
            var test       = new QaPartCoincidenceOther(fc1, fc2, 1, 10);
            var testRunner = new QaTestRunner(test);

            testRunner.Execute();
            Assert.AreEqual(1, testRunner.Errors.Count);

            // Same test with ignore conditions --> nothing near
            test = new QaPartCoincidenceOther(fc1, fc2, 1, 10);
            test.IgnoreNeighborCondition = "G1.LandID = G2.LandID";

            testRunner = new QaTestRunner(test);
            testRunner.Execute();
            Assert.AreEqual(0, testRunner.Errors.Count);
        }
        private static void TestValueInUniqueTable(IFeatureWorkspace ws)
        {
            ITable table1 =
                DatasetUtils.CreateTable(ws, "TestValueInUniqueTable1",
                                         FieldUtils.CreateOIDField(),
                                         FieldUtils.CreateField("RouteId",
                                                                esriFieldType
                                                                .esriFieldTypeInteger));

            ITable table2 =
                DatasetUtils.CreateTable(ws, "TestValueInUniqueTable2",
                                         FieldUtils.CreateOIDField(),
                                         FieldUtils.CreateField("OtherId",
                                                                esriFieldType
                                                                .esriFieldTypeInteger));

            // make sure the table is known by the workspace
            ((IWorkspaceEdit)ws).StartEditing(false);
            ((IWorkspaceEdit)ws).StopEditing(true);

            IRow row1 = table1.CreateRow();

            row1.set_Value(1, 3);
            row1.Store();

            for (int i = 0; i < 5; i++)
            {
                IRow r = table1.CreateRow();
                r.set_Value(1, 8);
                r.Store();
            }

            IRow row2 = table2.CreateRow();

            row2.set_Value(1, 3);
            row2.Store();

            const bool limitToTestedRows = false;
            var        test = new QaGroupConstraints(new[] { table1, table2 },
                                                     new[] { "RouteID", "OtherId" },
                                                     new[] { "'Haltung'", "'B'" },
                                                     1, limitToTestedRows);

            using (var runner = new QaTestRunner(test))
            {
                runner.Execute();
                Assert.AreEqual(1, runner.Errors.Count);
            }

            var containerRunner = new QaContainerTestRunner(100, test);

            containerRunner.Execute();
            Assert.AreEqual(1, containerRunner.Errors.Count);
        }
示例#11
0
        private static LinearNetworkGdbFeatureFinder CreateTestGdbSchema(
            string fgdbName,
            out IFeatureClass edgeClass, out IFeatureClass junctionClass)
        {
            const string unitTestDir = @"C:\Temp\UnitTestData";

            try
            {
                FileSystemUtils.DeleteDirectory(Path.Combine(unitTestDir, fgdbName), true,
                                                true);
            }
            catch (Exception)
            {
                // ignored
            }

            IWorkspaceName workspaceName =
                WorkspaceUtils.CreateFileGdbWorkspace(unitTestDir,
                                                      fgdbName);

            IWorkspace workspace = WorkspaceUtils.OpenWorkspace(workspaceName);

            ISpatialReference lv95 =
                SpatialReferenceUtils.CreateSpatialReference(WellKnownHorizontalCS.LV95);

            IFieldsEdit fieldsReference = new FieldsClass();

            fieldsReference.AddField(FieldUtils.CreateOIDField());
            fieldsReference.AddField(
                FieldUtils.CreateShapeField(esriGeometryType.esriGeometryPolyline, lv95));

            edgeClass = DatasetUtils.CreateSimpleFeatureClass(
                (IFeatureWorkspace)workspace, "Edges", string.Empty,
                FieldUtils.CreateOIDField(),
                FieldUtils.CreateShapeField(esriGeometryType.esriGeometryPolyline, lv95));

            junctionClass = DatasetUtils.CreateSimpleFeatureClass(
                (IFeatureWorkspace)workspace, "Junctions", string.Empty,
                FieldUtils.CreateOIDField(),
                FieldUtils.CreateShapeField(esriGeometryType.esriGeometryPoint, lv95));

            List <LinearNetworkClassDef> networkClassDefinitions =
                new List <LinearNetworkClassDef>
            {
                new LinearNetworkClassDef(edgeClass),
                new LinearNetworkClassDef(junctionClass)
            };

            LinearNetworkGdbFeatureFinder featureFinder =
                new LinearNetworkGdbFeatureFinder(networkClassDefinitions);

            return(featureFinder);
        }
示例#12
0
        private static IEnumerable <IField> CreateFields()
        {
            yield return(FieldUtils.CreateOIDField());

            yield return(FieldUtils.CreateDoubleField(_doubleFieldName));

            yield return(FieldUtils.CreateDateField(_dateFieldName));

            yield return(FieldUtils.CreateTextField(_textFieldName, 500));

            yield return(FieldUtils.CreateTextField(_stateFieldName, 2));
        }
示例#13
0
        public void CanUseMMinMaxAliasInMultiTableView()
        {
            IFeatureClass featureClass = CreateFeatureClass(
                "CanUseMMinMaxAliasInMultiTableView",
                esriGeometryType.esriGeometryPolyline,
                zAware: true, mAware: true);

            ITable table = CreateTable("CanUseMMinMaxAliasInMultiTableView_table",
                                       FieldUtils.CreateOIDField(),
                                       FieldUtils.CreateIntegerField("NUMBER"));

            IFeature f1 = featureClass.CreateFeature();

            f1.Shape = GeometryFactory.CreatePolyline(
                GeometryFactory.CreatePoint(0, 0, 1000, 100),
                GeometryFactory.CreatePoint(5, 5, 1000, 200));
            f1.Store();

            IFeature f2 = featureClass.CreateFeature();

            f2.Shape = GeometryFactory.CreatePolyline(
                GeometryFactory.CreatePoint(0, 0, 1000, 300),
                GeometryFactory.CreatePoint(5, 5, 1000, 400));
            f2.Store();

            int fieldIndexNumber = table.FindField("NUMBER");

            IRow r1 = table.CreateRow();

            r1.Value[fieldIndexNumber] = 100;
            r1.Store();

            IRow r2 = table.CreateRow();

            r2.Value[fieldIndexNumber] = 200;
            r2.Store();

            AssertFilteredMultiViewRowCount(1,
                                            "F.$ShapeMMin = 100 AND F.$ShapeMMax = 200 AND T.NUMBER = 100",
                                            featureClass, f1, table, r1);
            AssertFilteredMultiViewRowCount(0,
                                            "F.$ShapeMMin = 100 AND F.$ShapeMMax = 200 AND T.NUMBER = 10000",
                                            featureClass, f1, table, r1);

            AssertFilteredMultiViewRowCount(1,
                                            "F.$ShapeMMin = 300 AND F.$ShapeMMax = 400 AND T.NUMBER = 200",
                                            featureClass, f2, table, r2);
            AssertFilteredMultiViewRowCount(0,
                                            "F.$ShapeMMin = 300 AND F.$ShapeMMax = 400 AND T.NUMBER = 10000",
                                            featureClass, f2, table, r2);
        }
        private IFeatureClass CreateFeatureClass([NotNull] string name,
                                                 esriGeometryType geometryType)
        {
            IFieldsEdit fields = new FieldsClass();

            fields.AddField(FieldUtils.CreateOIDField());
            fields.AddField(FieldUtils.CreateShapeField(
                                "Shape", geometryType, _spatialReference, 1000));

            fields.AddField(FieldUtils.CreateTextField(_textFieldName, 200));

            return(DatasetUtils.CreateSimpleFeatureClass(
                       _testWs, name, fields));
        }
示例#15
0
        private static IFeatureClass CreateLineClass([NotNull] IFeatureWorkspace ws,
                                                     [NotNull] string name)
        {
            IFieldsEdit fields = new FieldsClass();

            fields.AddField(FieldUtils.CreateOIDField());
            fields.AddField(FieldUtils.CreateShapeField(
                                "Shape", esriGeometryType.esriGeometryPolyline,
                                SpatialReferenceUtils.CreateSpatialReference
                                    ((int)esriSRProjCS2Type.esriSRProjCS_CH1903Plus_LV95,
                                    true), 1000, true, false));

            return(DatasetUtils.CreateSimpleFeatureClass(ws, name, fields));
        }
        private static IFeatureClass CreateLineFeatureClass(
            [NotNull] IFeatureWorkspace workspace, [NotNull] string name)
        {
            ISpatialReference spatialReference = CreateSpatialReference();

            return(DatasetUtils.CreateSimpleFeatureClass(
                       workspace, name,
                       FieldUtils.CreateFields(
                           FieldUtils.CreateOIDField(),
                           FieldUtils.CreateShapeField(
                               "SHAPE", esriGeometryType.esriGeometryPolyline,
                               spatialReference, 1000, false, false)),
                       null));
        }
示例#17
0
        public void TestMultipart()
        {
            IFeatureWorkspace ws = TestWorkspaceUtils.CreateInMemoryWorkspace("Testmultipart");

            IFieldsEdit fields = new FieldsClass();

            fields.AddField(FieldUtils.CreateOIDField());
            fields.AddField(FieldUtils.CreateIntegerField("LineTyp", "LineTyp"));
            fields.AddField(FieldUtils.CreateShapeField(
                                "Shape", esriGeometryType.esriGeometryPolyline,
                                SpatialReferenceUtils.CreateSpatialReference
                                    ((int)esriSRProjCS2Type.esriSRProjCS_CH1903Plus_LV95,
                                    true), 1000, false, false));

            IFeatureClass fc =
                DatasetUtils.CreateSimpleFeatureClass(ws, "TestConnections", fields,
                                                      null);
            IList <ITable> tbls = new[] { (ITable)fc };

            {
                IFeature row = fc.CreateFeature();
                row.set_Value(1, 1);
                row.Shape =
                    CurveConstruction.StartLine(1, 1).LineTo(2, 2).MoveTo(3, 2).LineTo(4, 2).Curve;
                row.Store();
            }
            {
                IFeature row = fc.CreateFeature();
                row.set_Value(1, 2);
                row.Shape =
                    CurveConstruction.StartLine(1, 5).LineTo(2, 2).Curve;
                row.Store();
            }

            IList <QaConnectionRule> rules = new List <QaConnectionRule>
            {
                new QaConnectionRule(tbls, new[] { "LineTyp = 1" }),
                new QaConnectionRule(tbls, new[] { "LineTyp = 2" })
            };
            var test = new QaConnections(new[] { fc }, rules, 0);

            test.UseMultiParts = false;
            var runner = new QaContainerTestRunner(1000, test);

            Assert.AreEqual(0, runner.Execute());

            test.UseMultiParts = true;
            runner             = new QaContainerTestRunner(1000, test);
            Assert.AreEqual(1, runner.Execute());
        }
        private static void TestGroupContraints(IFeatureWorkspace ws)
        {
            ITable tbl =
                DatasetUtils.CreateTable(ws, "TestGroupContraints",
                                         FieldUtils.CreateOIDField(),
                                         FieldUtils.CreateTextField("Kostenstelle", 20));

            // make sure the table is known by the workspace
            ((IWorkspaceEdit)ws).StartEditing(false);
            ((IWorkspaceEdit)ws).StopEditing(true);

            IRow row1 = tbl.CreateRow();

            row1.set_Value(1, "123456-10");
            row1.Store();

            IRow row2 = tbl.CreateRow();

            row2.set_Value(1, "123456-11");
            row2.Store();

            IRow row3 = tbl.CreateRow();

            row3.set_Value(1, "123456-11");
            row3.Store();

            IRow row4 = tbl.CreateRow();

            row4.set_Value(1, "023456-10");
            row4.Store();

            const bool limitToTestedRows = false;
            var        test = new QaGroupConstraints(tbl,
                                                     "IIF(LEN(Kostenstelle) >=6, SUBSTRING(Kostenstelle, 1, 6), '')",
                                                     "SUBSTRING(Kostenstelle, 8, 9)",
                                                     1,
                                                     limitToTestedRows);

            using (var runner = new QaTestRunner(test))
            {
                runner.Execute();
                Assert.AreEqual(1, runner.Errors.Count);
            }

            var containerRunner = new QaContainerTestRunner(100, test);

            containerRunner.Execute();
            Assert.AreEqual(1, containerRunner.Errors.Count);
        }
示例#19
0
        public void TestUniqueGuid()
        {
            ISpatialReference sref = SpatialReferenceUtils.CreateSpatialReference
                                         ((int)esriSRProjCS2Type.esriSRProjCS_CH1903Plus_LV95,
                                         true);

            SpatialReferenceUtils.SetXYDomain(sref, -10000, -10000, 10000, 10000, 0.0001, 0.001);

            IFields fields = FieldUtils.CreateFields(
                FieldUtils.CreateOIDField(),
                FieldUtils.CreateField("UniqueValue", esriFieldType.esriFieldTypeGUID),
                FieldUtils.CreateShapeField(
                    "Shape", esriGeometryType.esriGeometryPoint,
                    sref, 1000));

            IFeatureClass featureClass1 = DatasetUtils.CreateSimpleFeatureClass(_fgdbWorkspace,
                                                                                "TestUniqueGuid",
                                                                                fields);

            for (var i = 0; i < 10; i++)
            {
                IFeature feature = featureClass1.CreateFeature();
                feature.set_Value(1, Guid.NewGuid().ToString("B"));
                feature.Shape = GeometryFactory.CreatePoint(100, 100, sref);
                feature.Store();
            }

            for (var i = 0; i < 2; i++)
            {
                IFeature emptyFeature = featureClass1.CreateFeature();
                emptyFeature.set_Value(1, null);
                emptyFeature.Shape = GeometryFactory.CreatePoint(100, 100, sref);
                emptyFeature.Store();
            }

            foreach (bool forceInMemoryTableSort in new[] { true, false })
            {
                var test = new QaUnique((ITable)featureClass1, "UniqueValue")
                {
                    ForceInMemoryTableSorting = forceInMemoryTableSort
                };

                var runner = new QaTestRunner(test);
                runner.Execute();
                Assert.AreEqual(2, runner.Errors.Count);
            }
        }
示例#20
0
        public void CanFindDanglingSimpleKey()
        {
            const string key  = "KEY1";
            const string fkey = "FKEY1";

            ITable referencedTable = DatasetUtils.CreateTable(
                _workspace,
                string.Format("{0}_key", MethodBase.GetCurrentMethod().Name),
                FieldUtils.CreateOIDField(),
                FieldUtils.CreateIntegerField(key));

            ITable referencingTable = DatasetUtils.CreateTable(
                _workspace,
                string.Format("{0}_fkey", MethodBase.GetCurrentMethod().Name),
                FieldUtils.CreateOIDField(),
                FieldUtils.CreateTextField(fkey, 10));

            GdbObjectUtils.CreateRow(referencedTable,
                                     new Dictionary <string, object> {
                { key, 1000 }
            }).Store();
            GdbObjectUtils.CreateRow(referencedTable,
                                     new Dictionary <string, object> {
                { key, 2000 }
            }).Store();

            GdbObjectUtils.CreateRow(referencingTable,
                                     new Dictionary <string, object> {
                { fkey, "1000" }
            }).Store();
            GdbObjectUtils.CreateRow(referencingTable,
                                     new Dictionary <string, object> {
                { fkey, "2000" }
            }).Store();
            // dangling reference:
            GdbObjectUtils.CreateRow(referencingTable,
                                     new Dictionary <string, object> {
                { fkey, "3000" }
            }).Store();

            var runner = new QaTestRunner(
                new QaForeignKey(referencingTable, fkey, referencedTable, key));

            runner.Execute();

            Assert.AreEqual(1, runner.Errors.Count);
        }
        public void TestExcludedFields()
        {
            IFeatureWorkspace initTestWs = _testWs;

            try
            {
                _testWs = TestWorkspaceUtils.CreateInMemoryWorkspace("QaRegularExpression");

                IFieldsEdit fields = new FieldsClass();
                fields.AddField(FieldUtils.CreateOIDField());
                fields.AddField(FieldUtils.CreateIntegerField(_fkFieldName));
                fields.AddField(FieldUtils.CreateTextField(_textFieldName, 200));
                fields.AddField(FieldUtils.CreateTextField(_textFieldName2, 200));

                const string tableName = "RegEx_table_excluded";
                ITable       table     =
                    TestWorkspaceUtils.CreateSimpleTable(_testWs, tableName, fields);

                ((IWorkspaceEdit)_testWs).StartEditing(false);

                AddRow(table, textFieldValue: "A", textFieldValue2: "X");
                AddRow(table, textFieldValue: "B", textFieldValue2: "X");
                AddRow(table, textFieldValue: "A", textFieldValue2: "X");

                ((IWorkspaceEdit)_testWs).StopEditing(true);

                var test =
                    new QaRegularExpression(table, "A", _textFieldName2)
                {
                    FieldListType = FieldListType.IgnoredFields
                };

                IList <QaError> errors = Run(test, 1000);
                AssertErrors(1, errors);

                IList <InvolvedRow> involvedRows = errors[0].InvolvedRows;
                Assert.AreEqual(1, involvedRows.Count);
                Assert.AreEqual($"{_textFieldName}", errors[0].AffectedComponent);
                Assert.AreEqual("RegularExpression.FieldValueDoesNotMatchRegularExpression",
                                errors[0].IssueCode?.ID);
            }
            finally
            {
                _testWs = initTestWs;
            }
        }
示例#22
0
        private IFeatureClass CreateFeatureClass(string name, esriGeometryType geometryType)
        {
            IFieldsEdit fields = new FieldsClass();

            fields.AddField(FieldUtils.CreateOIDField());
            fields.AddField(FieldUtils.CreateShapeField(
                                "Shape", geometryType, _spatialReference, 1000));

            fields.AddField(FieldUtils.CreateTextField(_stateIdFieldName, 100));

            fields.AddField(FieldUtils.CreateTextField(_textFieldName, 200));
            fields.AddField(FieldUtils.CreateDoubleField(_doubleFieldName));
            fields.AddField(FieldUtils.CreateDateField(_dateFieldName));

            return(DatasetUtils.CreateSimpleFeatureClass(
                       _featureWorkspace, name, fields));
        }
示例#23
0
        private IFeatureClass CreateFeatureClass([NotNull] string name,
                                                 esriGeometryType type,
                                                 bool zAware = false)
        {
            ISpatialReference sref = SpatialReferenceUtils.CreateSpatialReference
                                         ((int)esriSRProjCS2Type.esriSRProjCS_CH1903Plus_LV95,
                                         setDefaultXyDomain: true);

            SpatialReferenceUtils.SetXYDomain(sref, -10000, -10000, 10000, 10000,
                                              0.0001, 0.001);

            IFields fields = FieldUtils.CreateFields(
                FieldUtils.CreateOIDField(),
                FieldUtils.CreateShapeField("Shape", type, sref, 1000, zAware));

            return(DatasetUtils.CreateSimpleFeatureClass(_testWs, name, fields));
        }
示例#24
0
        public void CanUseObjectIdAliasInMultiTableView()
        {
            IFeatureClass featureClass = CreateFeatureClass(
                "CanUseObjectIdAliasInMultiTableView",
                esriGeometryType.esriGeometryPoint);

            ITable table = CreateTable("CanUseObjectIdAliasInMultiTableView_table",
                                       FieldUtils.CreateOIDField(),
                                       FieldUtils.CreateIntegerField("NUMBER"));

            IFeature f1 = featureClass.CreateFeature();

            f1.Shape = GeometryFactory.CreatePoint(0, 0);
            f1.Store();

            IFeature f2 = featureClass.CreateFeature();

            f2.Shape = GeometryFactory.CreatePoint(5, 5);
            f2.Store();

            int fieldIndexNumber = table.FindField("NUMBER");

            IRow r1 = table.CreateRow();

            r1.Value[fieldIndexNumber] = 100;
            r1.Store();

            IRow r2 = table.CreateRow();

            r2.Value[fieldIndexNumber] = 200;
            r2.Store();

            AssertFilteredMultiViewRowCount(1,
                                            "F.$ObjectId = 1 AND T.$ObjectId = 1 AND T.NUMBER = 100",
                                            featureClass, f1, table, r1);
            AssertFilteredMultiViewRowCount(0,
                                            "F.$ObjectId = 1 AND T.$ObjectId = 1 AND T.NUMBER = 10000",
                                            featureClass, f1, table, r1);

            AssertFilteredMultiViewRowCount(1,
                                            "F.$ObjectId = 2 AND T.$ObjectId = 2 AND T.NUMBER = 200",
                                            featureClass, f2, table, r2);
            AssertFilteredMultiViewRowCount(0,
                                            "F.$ObjectId = 2 AND T.$ObjectId = 2 AND T.NUMBER = 10000",
                                            featureClass, f2, table, r2);
        }
        public void TooLong()
        {
            ITable table = DatasetUtils.CreateTable(
                _workspace, MethodBase.GetCurrentMethod().Name,
                FieldUtils.CreateOIDField(),
                FieldUtils.CreateTextField("FIELD1", 10),
                FieldUtils.CreateTextField("FIELD2_1234", 10),
                FieldUtils.CreateTextField("FIELD3", 10));

            const int maxLength    = 10;
            const int uniqueLength = 6;
            var       runner       = new QaTestRunner(
                new QaSchemaFieldNames(table, maxLength, ExpectedCase.AllUpper, uniqueLength));

            runner.Execute();

            Assert.AreEqual(1, runner.Errors.Count);
        }
        public void InvalidCaseExpectedNotAllLower()
        {
            ITable table = DatasetUtils.CreateTable(
                _workspace, MethodBase.GetCurrentMethod().Name,
                FieldUtils.CreateOIDField(),
                FieldUtils.CreateTextField("FIELD1", 10),
                FieldUtils.CreateTextField("field2", 10),
                FieldUtils.CreateTextField("Field3", 10));

            const int maxLength    = 15;
            const int uniqueLength = 6;
            var       runner       = new QaTestRunner(
                new QaSchemaFieldNames(table, maxLength, ExpectedCase.NotAllLower, uniqueLength));

            runner.Execute();

            Assert.AreEqual(1, runner.Errors.Count);
        }
示例#27
0
        public static IFeatureClass CreateSimpleFeatureClass(
            [NotNull] IFeatureWorkspace workspace,
            [NotNull] string name,
            [CanBeNull] IFieldsEdit fieldsWithoutShapeField,
            esriGeometryType geometryType,
            esriSRProjCS2Type projType,
            double xyTolerance = 0,
            bool hasZ          = false)
        {
            if (fieldsWithoutShapeField == null)
            {
                fieldsWithoutShapeField = new FieldsClass();
                fieldsWithoutShapeField.AddField(FieldUtils.CreateOIDField());
            }

            ISpatialReference spatialReference = SpatialReferenceUtils
                                                 .CreateSpatialReference
                                                     ((int)projType, true);

            if (xyTolerance > 0)
            {
                ((ISpatialReferenceTolerance)spatialReference).XYTolerance =
                    xyTolerance;
            }

            if (hasZ)
            {
                SpatialReferenceUtils.SetZDomain(spatialReference, -10000, 10000,
                                                 0.0001, 0.001);
            }

            fieldsWithoutShapeField.AddField(
                FieldUtils.CreateShapeField("Shape", geometryType, spatialReference, 1000, hasZ));

            IFeatureClass featureClass =
                DatasetUtils.CreateSimpleFeatureClass(
                    workspace, name, fieldsWithoutShapeField);

            // make sure the table is known by the workspace
            ((IWorkspaceEdit)workspace).StartEditing(false);
            ((IWorkspaceEdit)workspace).StopEditing(true);

            return(featureClass);
        }
示例#28
0
        public void CanCreateGdbTable()
        {
            // An in-memory backing dataset is created automatically, if no factory method is provided
            GdbTable gdbTable = new GdbTable(41, "TESTABLE", "Test table");

            IObjectClass objectClass = gdbTable;

            Assert.AreEqual(41, objectClass.ObjectClassID);
            Assert.AreEqual("TESTABLE", DatasetUtils.GetName(objectClass));
            Assert.AreEqual("Test table", DatasetUtils.GetAliasName(objectClass));

            Assert.False(objectClass.HasOID);
            Assert.Null(objectClass.OIDFieldName);

            Assert.AreEqual(0, GdbQueryUtils.Count(objectClass, ""));

            // Add OID field
            gdbTable.AddField(FieldUtils.CreateOIDField());

            Assert.True(objectClass.HasOID);
            Assert.AreEqual("OBJECTID", objectClass.OIDFieldName);

            IQueryFilter queryFilter = GdbQueryUtils.CreateQueryFilter("OBJECTID");

            queryFilter.WhereClause = "OBJECTID < 0";

            Assert.AreEqual(0,
                            GdbQueryUtils.Count(objectClass, queryFilter));

            var backingDataset = gdbTable.BackingDataset as InMemoryDataset;

            Assert.NotNull(backingDataset);

            backingDataset.AllRows.Add(new GdbRow(1, gdbTable));

            Assert.AreEqual(0,
                            GdbQueryUtils.Count(objectClass, queryFilter));

            queryFilter.WhereClause = "OBJECTID > 0";

            Assert.AreEqual(1,
                            GdbQueryUtils.Count(objectClass, queryFilter));
        }
示例#29
0
        public void NameTooLong()
        {
            IDomain domain1 = DomainUtils.AddDomain(_workspace,
                                                    DomainUtils.CreateCodedValueDomain(
                                                        "DOM_FIELD1",
                                                        esriFieldType.esriFieldTypeInteger,
                                                        new CodedValue(1, "Value 1 abc"),
                                                        new CodedValue(2, "Value 2")));
            IDomain domain2 = DomainUtils.AddDomain(_workspace,
                                                    DomainUtils.CreateCodedValueDomain(
                                                        "DOM_FIELD2",
                                                        esriFieldType.esriFieldTypeInteger,
                                                        new CodedValue(1, "Value 1"),
                                                        new CodedValue(2, "Value 2 123")));

            IField field1 = FieldUtils.CreateField("FIELD1", esriFieldType.esriFieldTypeInteger);
            IField field2 = FieldUtils.CreateField("FIELD2", esriFieldType.esriFieldTypeInteger);
            IField field3 = FieldUtils.CreateField("FIELD3", esriFieldType.esriFieldTypeInteger);

            ((IFieldEdit)field1).Domain_2 = domain1;
            ((IFieldEdit)field2).Domain_2 = domain2;
            ((IFieldEdit)field3).Domain_2 = domain2;
            // reuse domain2 - to test if error is reported only once

            ITable table = DatasetUtils.CreateTable(_workspace,
                                                    MethodBase.GetCurrentMethod().Name,
                                                    FieldUtils.CreateOIDField(),
                                                    field1, field2, field3);

            const int  maxLength                     = 10;
            const int  minimumValueCount             = 1;
            const int  minimumNonEqualNameValueCount = 1;
            const bool allowEmptyName                = false;
            var        runner = new QaTestRunner(new QaSchemaFieldDomainCodedValues(
                                                     table, maxLength,
                                                     UniqueStringsConstraint.UniqueAnyCase,
                                                     minimumValueCount, minimumNonEqualNameValueCount,
                                                     allowEmptyName));

            runner.Execute();

            Assert.AreEqual(2, runner.Errors.Count);
        }
        public void AllValid()
        {
            ITable table = DatasetUtils.CreateTable(
                _workspace, MethodBase.GetCurrentMethod().Name,
                FieldUtils.CreateOIDField("OBJECTID", "Object ID"),
                FieldUtils.CreateTextField("FIELD1", 10, "Field 1"),
                FieldUtils.CreateTextField("FIELD2", 10, "Field 2"),
                FieldUtils.CreateTextField("FIELD3", 10, "Field 3"));

            const bool requireUniqueAliasNames     = true;
            const bool allowCustomSystemFieldAlias = true;
            var        runner = new QaTestRunner(
                new QaSchemaFieldAliases(table, 30, ExpectedCase.Mixed,
                                         requireUniqueAliasNames, allowCustomSystemFieldAlias));

            runner.Execute();

            NoErrors(runner.Errors);
        }