Example #1
0
        public void Constructor_InvalidOperator_ThrowsInvalidEnumArgumentException()
        {
            // Setup
            const ValueCriterionOperator invalidOperator = (ValueCriterionOperator)9999;

            // Call
            TestDelegate call = () => new ValueCriterion(invalidOperator, "test");

            // Assert
            string expectedMessage = $"The value of argument 'valueOperator' ({invalidOperator}) is invalid for Enum type '{nameof(ValueCriterionOperator)}'.";
            string parameterName   = TestHelper.AssertThrowsArgumentExceptionAndTestMessage <InvalidEnumArgumentException>(call, expectedMessage).ParamName;

            Assert.AreEqual("valueOperator", parameterName);
        }
Example #2
0
        /// <summary>
        /// Creates a filter expression based for an attribute and the criteria to apply.
        /// </summary>
        /// <param name="attributeIndex">The index of the attribute in the metadata table.</param>
        /// <param name="criterion">The criterion to convert to an expression.</param>
        /// <returns>The filter expression based on the <paramref name="attributeIndex"/>
        /// and <paramref name="criterion"/>.</returns>
        /// <exception cref="NotSupportedException">Thrown when the <paramref name="criterion"/>
        /// cannot be used to create a filter expression.</exception>
        private static string CreateFilterExpression(int attributeIndex, ValueCriterion criterion)
        {
            ValueCriterionOperator valueOperator = criterion.ValueOperator;

            switch (valueOperator)
            {
            case ValueCriterionOperator.EqualValue:
                return($"[{attributeIndex}] = '{criterion.Value}'");

            case ValueCriterionOperator.UnequalValue:
                return($"NOT [{attributeIndex}] = '{criterion.Value}'");

            default:
                throw new NotSupportedException();
            }
        }
Example #3
0
        /// <summary>
        /// Creates a new instance of <see cref="ValueCriterion"/>.
        /// </summary>
        /// <param name="valueOperator">The <see cref="ValueCriterionOperator"/> belonging to this criterion.</param>
        /// <param name="value">The value to apply when using this criteria.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="value"/>
        /// is <c>null</c>.</exception>
        /// <exception cref="InvalidEnumArgumentException">Thrown when <paramref name="valueOperator"/>
        /// contains an invalid value for <see cref="ValueCriterionOperator"/>.</exception>
        public ValueCriterion(ValueCriterionOperator valueOperator, string value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            if (!Enum.IsDefined(typeof(ValueCriterionOperator), valueOperator))
            {
                throw new InvalidEnumArgumentException(nameof(valueOperator),
                                                       (int)valueOperator,
                                                       typeof(ValueCriterionOperator));
            }

            ValueOperator = valueOperator;
            Value         = value;
        }
Example #4
0
        public void Constructor_Always_ReturnExpectedValues(ValueCriterionOperator valueOperator,
                                                            string formatExpression)
        {
            // Setup
            const string attributeName = "AttributeName";
            const string value         = "random value 123";

            var criterion = new ValueCriterion(valueOperator, value);
            var theme     = new TestCategoryTheme(criterion);

            // Call
            var properties = new TestCategoryThemeProperties(attributeName, theme, new TestFeatureBasedMapData());

            // Assert
            string expectedValue = string.Format(formatExpression, attributeName, value);

            Assert.AreEqual(expectedValue, properties.Criterion);
        }
        public void ConvertLayerProperties_MapDataWithMapThemeAndVaryingValueCriteria_SetsCorrectFilterExpression(ValueCriterionOperator criterionOperator,
                                                                                                                  string expressionFormat)
        {
            // Setup
            const string metadataAttributeName = "Meta";
            const string value = "test value";

            var valueCriterion = new ValueCriterion(criterionOperator,
                                                    value);
            var theme = new MapTheme <TestCategoryTheme>(metadataAttributeName, new[]
            {
                new TestCategoryTheme(valueCriterion)
            });

            var mapData = new TestFeatureBasedMapData("test data", theme)
            {
                Features = new[]
                {
                    new MapFeature(Enumerable.Empty <MapGeometry>())
                    {
                        MetaData =
                        {
                            {
                                metadataAttributeName, new object()
                            }
                        }
                    }
                }
            };

            var featureScheme   = new PointScheme();
            var defaultCategory = new PointCategory();
            var category        = new PointCategory();
            var testConverter   = new TestFeatureBasedMapDataConverter
            {
                CreatedFeatureScheme         = featureScheme,
                CreatedDefaultCategory       = defaultCategory,
                CreatedCategoryThemeCategory = category
            };

            var mapLayer = new TestFeatureLayer();

            // Call
            testConverter.ConvertLayerProperties(mapData, mapLayer);

            // Assert
            Assert.IsNull(defaultCategory.FilterExpression);
            string expectedFilterExpression = string.Format(expressionFormat, value);

            Assert.AreEqual(expectedFilterExpression, category.FilterExpression);
        }