Ejemplo n.º 1
0
 private static ICodedValueDomain CreateCVDomain(string name)
 {
     return(DomainUtils.CreateCodedValueDomain(name,
                                               esriFieldType.esriFieldTypeInteger,
                                               new CodedValue(1, "Value 1"),
                                               new CodedValue(2, "Value 2")));
 }
        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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public void CanCreateDoubleCodedValueDomainConstraint()
        {
            ICodedValueDomain doubleCvDomain = DomainUtils.CreateCodedValueDomain(
                "CanCreateDoubleCodedValueDomainConstraint",
                esriFieldType.esriFieldTypeDouble, null,
                esriSplitPolicyType.esriSPTDuplicate,
                esriMergePolicyType.esriMPTDefaultValue,
                new CodedValue(1.00000000001, "Value 1.00000000001"),
                new CodedValue(2.00000000002, "Value 2.00000000002"),
                new CodedValue(3.00000000003, "Value 3.00000000003"));

            DomainUtils.AddDomain(_testWs, doubleCvDomain);

            IField doubleField = FieldUtils.CreateDoubleField("DoubleField");

            ((IFieldEdit)doubleField).Domain_2 = (IDomain)doubleCvDomain;

            ITable table = DatasetUtils.CreateTable(_testWs,
                                                    "CanCreateDoubleCodedValueDomainConstraint",
                                                    FieldUtils.CreateOIDField(),
                                                    doubleField);

            List <ConstraintNode> constraints =
                GdbConstraintUtils.GetGdbConstraints(table);

            Assert.NotNull(constraints);

            foreach (ConstraintNode constraint in constraints)
            {
                Console.WriteLine(constraint);
            }

            Assert.AreEqual(2, constraints.Count);

            Assert.AreEqual(
                "DoubleField IS NULL OR (Convert(DoubleField, 'System.Single') IN " +
                "(Convert(1.00000000001, 'System.Single'), " +
                "Convert(2.00000000002, 'System.Single'), " +
                "Convert(3.00000000003, 'System.Single')))",
                constraints[0].Condition);
            Assert.AreEqual("OBJECTID >= 0", constraints[1].Condition);
        }
Ejemplo n.º 5
0
        public void CanCreateStringCodedValueDomainConstraintNotNull()
        {
            ICodedValueDomain stringCvDomain = DomainUtils.CreateCodedValueDomain(
                "CanCreateStringCodedValueDomainConstraintNotNull",
                esriFieldType.esriFieldTypeString, null,
                esriSplitPolicyType.esriSPTDuplicate,
                esriMergePolicyType.esriMPTDefaultValue,
                new CodedValue("a", "Value a"),
                new CodedValue("b", "Value b"),
                new CodedValue("c", "Value c"));

            DomainUtils.AddDomain(_testWs, stringCvDomain);

            IField textField = FieldUtils.CreateTextField("TextField", 100);

            ((IFieldEdit)textField).Domain_2 = (IDomain)stringCvDomain;

            ITable table = DatasetUtils.CreateTable(_testWs,
                                                    "CanCreateStringCodedValueDomainConstraintNotNull",
                                                    FieldUtils.CreateOIDField(),
                                                    textField);

            List <ConstraintNode> constraints =
                GdbConstraintUtils.GetGdbConstraints(
                    table, allowNullForCodedValueDomains: false);

            Assert.NotNull(constraints);

            foreach (ConstraintNode constraint in constraints)
            {
                Console.WriteLine(constraint);
            }

            Assert.AreEqual(2, constraints.Count);

            Assert.AreEqual("TextField IN ('a', 'b', 'c')",
                            constraints[0].Condition);
            Assert.AreEqual("OBJECTID >= 0", constraints[1].Condition);
        }
Ejemplo n.º 6
0
        private ITable CreateTestTable([NotNull] string tableName, out int cvFieldIndex,
                                       out int rangeFieldIndex)
        {
            IRangeDomain rangeDomain = DomainUtils.CreateRangeDomain(
                tableName + "_range",
                esriFieldType.esriFieldTypeInteger, 0, 100);

            DomainUtils.AddDomain(_testWs, rangeDomain);

            ICodedValueDomain cvDomain = DomainUtils.CreateCodedValueDomain(
                tableName + "_cv",
                esriFieldType.esriFieldTypeInteger, null,
                esriSplitPolicyType.esriSPTDuplicate,
                esriMergePolicyType.esriMPTDefaultValue,
                new CodedValue(1, "Value 1"),
                new CodedValue(2, "Value 2"),
                new CodedValue(3, "Value 3"));

            DomainUtils.AddDomain(_testWs, cvDomain);

            IField cvField = FieldUtils.CreateIntegerField("CvField");

            ((IFieldEdit)cvField).Domain_2 = (IDomain)cvDomain;

            IField rangeField = FieldUtils.CreateIntegerField("RangeField");

            ((IFieldEdit)rangeField).Domain_2 = (IDomain)rangeDomain;

            ITable table = DatasetUtils.CreateTable(_testWs,
                                                    tableName,
                                                    FieldUtils.CreateOIDField(),
                                                    cvField,
                                                    rangeField);

            cvFieldIndex    = table.FindField(cvField.Name);
            rangeFieldIndex = table.FindField(rangeField.Name);

            return(table);
        }
Ejemplo n.º 7
0
        public void CanCreateIntegerCodedValueDomainConstraint()
        {
            ICodedValueDomain integerCvDomain = DomainUtils.CreateCodedValueDomain(
                "CanCreateIntegerCodedValueDomainConstraint",
                esriFieldType.esriFieldTypeInteger, null,
                esriSplitPolicyType.esriSPTDuplicate,
                esriMergePolicyType.esriMPTDefaultValue,
                new CodedValue(1, "Value 1"),
                new CodedValue(2, "Value 2"),
                new CodedValue(3, "Value 3"));

            DomainUtils.AddDomain(_testWs, integerCvDomain);

            IField integerField = FieldUtils.CreateIntegerField("IntegerField");

            ((IFieldEdit)integerField).Domain_2 = (IDomain)integerCvDomain;

            ITable table = DatasetUtils.CreateTable(_testWs,
                                                    "CanCreateIntegerCodedValueDomainConstraint",
                                                    FieldUtils.CreateOIDField(),
                                                    integerField);

            List <ConstraintNode> constraints =
                GdbConstraintUtils.GetGdbConstraints(table);

            Assert.NotNull(constraints);

            foreach (ConstraintNode constraint in constraints)
            {
                Console.WriteLine(constraint);
            }

            Assert.AreEqual(2, constraints.Count);

            Assert.AreEqual("IntegerField IS NULL OR (IntegerField IN (1, 2, 3))",
                            constraints[0].Condition);
            Assert.AreEqual("OBJECTID >= 0", constraints[1].Condition);
        }
        public void DuplicatesInOtherWorkspace()
        {
            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 - this should not be reported since duplicates are searched in target (?)
            DomainUtils.AddDomain(_workspace,
                                  DomainUtils.CreateCodedValueDomain("DOM_FIELD3",
                                                                     esriFieldType
                                                                     .esriFieldTypeInteger,
                                                                     "Description of DOM_FIELD2",
                                                                     new CodedValue(1,
                                                                                    "Value 1"),
                                                                     new CodedValue(2,
                                                                                    "Value 2")));

            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);

            // add domains/table to target workspace

            IFeatureWorkspace targetWorkspace =
                TestWorkspaceUtils.CreateTestFgdbWorkspace($"{GetType().Name}_target");

            // same name, same description --> should be considered equal, no duplicate
            DomainUtils.AddDomain(targetWorkspace,
                                  DomainUtils.CreateCodedValueDomain("DOM_FIELD1",
                                                                     esriFieldType
                                                                     .esriFieldTypeInteger,
                                                                     "Description of DOM_FIELD1",
                                                                     new CodedValue(1,
                                                                                    "Value 1"),
                                                                     new CodedValue(2,
                                                                                    "Value 2")));

            // different name, same description --> should be reported
            DomainUtils.AddDomain(targetWorkspace,
                                  DomainUtils.CreateCodedValueDomain("DOM_FIELD4",
                                                                     esriFieldType
                                                                     .esriFieldTypeInteger,
                                                                     "Description of DOM_FIELD2",
                                                                     new CodedValue(1,
                                                                                    "Value 1"),
                                                                     new CodedValue(2,
                                                                                    "Value 2")));

            // different name, same description --> should be reported
            DomainUtils.AddDomain(targetWorkspace,
                                  DomainUtils.CreateRangeDomain("DOM_FIELD5",
                                                                esriFieldType.esriFieldTypeInteger,
                                                                0, 100,
                                                                "Description of DOM_FIELD2"));

            ITable targetTable = DatasetUtils.CreateTable(targetWorkspace,
                                                          MethodBase.GetCurrentMethod().Name,
                                                          FieldUtils.CreateOIDField(),
                                                          FieldUtils.CreateTextField("FIELD1",
                                                                                     10));

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

            runner.Execute();

            Assert.AreEqual(1, runner.Errors.Count);
        }