Beispiel #1
0
        public void MissingPrefix()
        {
            IDomain domain1 = DomainUtils.AddDomain(TestWorkspace, CreateCVDomain("PRE_FIELD1"));
            IDomain domain2 = DomainUtils.AddDomain(TestWorkspace, CreateRangeDomain("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(TestWorkspace,
                                                    MethodBase.GetCurrentMethod().Name,
                                                    FieldUtils.CreateOIDField(),
                                                    field1, field2, field3);

            const int  maxLength            = 10;
            const bool mustContainFieldName = true;
            var        runner = new QaTestRunner(
                new QaSchemaFieldDomainNames(table, "PRE_", maxLength, mustContainFieldName,
                                             ExpectedCase.AllUpper));

            runner.Execute();

            Assert.AreEqual(1, runner.Errors.Count);
        }
        public void CanCreateIntegerRangeDomainConstraintNotNull()
        {
            IRangeDomain integerRangeDomain = DomainUtils.CreateRangeDomain(
                "CanCreateIntegerRangeDomainConstraintNotNull",
                esriFieldType.esriFieldTypeInteger, 0, 100);

            DomainUtils.AddDomain(_testWs, integerRangeDomain);

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

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

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

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

            Assert.NotNull(constraints);

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

            Assert.AreEqual(2, constraints.Count);

            Assert.AreEqual("IntegerField >= 0 AND IntegerField <= 100",
                            constraints[0].Condition);
            Assert.AreEqual("OBJECTID >= 0", constraints[1].Condition);
        }
Beispiel #3
0
        public void DoesNotContainFieldName()
        {
            IDomain domain1 = DomainUtils.AddDomain(TestWorkspace, CreateCVDomain("PRE_Field1"));
            IDomain domain2 = DomainUtils.AddDomain(TestWorkspace,
                                                    CreateRangeDomain("PRE_FIELD2"));

            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;              // case mismatch
            ((IFieldEdit)field2).Domain_2 = domain2;
            ((IFieldEdit)field3).Domain_2 = domain2;              // assign again - different field name

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

            const int  maxLength            = 20;
            const bool mustContainFieldName = true;
            var        runner = new QaTestRunner(
                new QaSchemaFieldDomainNames(table, "PRE_", maxLength, mustContainFieldName,
                                             ExpectedCase.Any));

            runner.Execute();

            Assert.AreEqual(2, runner.Errors.Count);
        }
        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);
        }
Beispiel #5
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 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);
        }
        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);
        }
Beispiel #8
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);
        }
        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 CanCreateDateTimeRangeDomainConstraintNotNull()
        {
            IRangeDomain dateRangeDomain = DomainUtils.CreateRangeDomain(
                "CanCreateDateTimeRangeDomainConstraintNotNull",
                esriFieldType.esriFieldTypeDate,
                new DateTime(2011, 12, 31),
                new DateTime(2012, 1, 31, 23, 55, 59));

            DomainUtils.AddDomain(_testWs, dateRangeDomain);

            IField dateField = FieldUtils.CreateDateField("DateField");

            ((IFieldEdit)dateField).Domain_2 = (IDomain)dateRangeDomain;

            ITable table = DatasetUtils.CreateTable(_testWs,
                                                    "CanCreateDateTimeRangeDomainConstraintNotNull",
                                                    FieldUtils.CreateOIDField(),
                                                    dateField);

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

            Assert.NotNull(constraints);

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

            Assert.AreEqual(2, constraints.Count);

            Assert.AreEqual(
                "DateField >= #12/31/2011 00:00:00# AND DateField <= #01/31/2012 23:55:59#",
                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);
        }