/// <summary>
        /// Gets the matching single value from the multivalued attribute
        /// </summary>
        /// <param name="source">The source attribute array</param>
        /// <returns>An attribute value</returns>
        private long GetValueFromMvInteger(IList <object> source)
        {
            long?lastValue = null;

            foreach (object value in source)
            {
                long valueLong = TypeConverter.ConvertData <long>(value);

                switch (this.SelectorOperator)
                {
                case ValueOperator.Equals:
                case ValueOperator.NotEquals:
                case ValueOperator.GreaterThan:
                case ValueOperator.LessThan:
                case ValueOperator.GreaterThanOrEq:
                case ValueOperator.LessThanOrEq:
                case ValueOperator.And:
                case ValueOperator.Or:
                    if (ComparisonEngine.CompareLong(valueLong, this.SelectorValue, this.SelectorOperator))
                    {
                        return(valueLong);
                    }

                    break;

                case ValueOperator.Largest:
                    if (!lastValue.HasValue || valueLong > lastValue)
                    {
                        lastValue = valueLong;
                    }

                    break;

                case ValueOperator.Smallest:
                    if (!lastValue.HasValue || valueLong < lastValue)
                    {
                        lastValue = valueLong;
                    }

                    break;

                case ValueOperator.Contains:
                case ValueOperator.NotContains:
                case ValueOperator.StartsWith:
                case ValueOperator.EndsWith:
                case ValueOperator.IsPresent:
                case ValueOperator.NotPresent:
                default:
                    throw new UnknownOrUnsupportedValueOperatorException(this.SelectorOperator, typeof(long));
                }
            }

            if (lastValue.HasValue)
            {
                return(lastValue.Value);
            }

            throw new NotFoundException();
        }
예제 #2
0
        public void CompareLongOrTest()
        {
            ValueOperator valueOperator    = ValueOperator.Or;
            long          actualValue      = 514L;
            long          matchingValue    = 2L;
            long          nonMatchingValue = 5L;

            Assert.AreEqual(true, ComparisonEngine.CompareLong(actualValue, matchingValue, valueOperator));
            Assert.AreEqual(false, ComparisonEngine.CompareLong(actualValue, nonMatchingValue, valueOperator));
        }
예제 #3
0
        public void CompareLongLessThanTest()
        {
            ValueOperator valueOperator    = ValueOperator.LessThan;
            long          actualValue      = 10L;
            long          matchingValue    = 20L;
            long          nonMatchingValue = 5L;

            Assert.AreEqual(true, ComparisonEngine.CompareLong(actualValue, matchingValue, valueOperator));
            Assert.AreEqual(false, ComparisonEngine.CompareLong(actualValue, nonMatchingValue, valueOperator));
        }
예제 #4
0
        public void CompareLongNotEqualsTest()
        {
            ValueOperator valueOperator    = ValueOperator.NotEquals;
            long          actualValue      = 1234567890L;
            long          matchingValue    = 9876543210L;
            long          nonMatchingValue = 1234567890L;

            Assert.AreEqual(true, ComparisonEngine.CompareLong(actualValue, matchingValue, valueOperator));
            Assert.AreEqual(false, ComparisonEngine.CompareLong(actualValue, nonMatchingValue, valueOperator));
        }
예제 #5
0
        public void CompareLongFromStringEqualsTest()
        {
            ValueOperator valueOperator    = ValueOperator.Equals;
            string        actualValue      = "1234567890";
            string        matchingValue    = "1234567890";
            string        nonMatchingValue = "9876543210";

            Assert.AreEqual(true, ComparisonEngine.CompareLong(actualValue, matchingValue, valueOperator));
            Assert.AreEqual(false, ComparisonEngine.CompareLong(actualValue, nonMatchingValue, valueOperator));
        }
예제 #6
0
        public override bool Evaluate(CSEntry csentry, MVEntry mventry)
        {
            if (mventry == null)
            {
                throw new NotSupportedException(string.Format("The rule type {0} is not supported in this context", this.GetType().Name));
            }

            int actual = mventry.ConnectedMAs.OfType <ConnectedMA>().Count(t => t.Name == this.MAName);

            return(ComparisonEngine.CompareLong(actual, this.Count, this.Operator));
        }
예제 #7
0
        public void CompareLongGreaterThanOrEqTest()
        {
            ValueOperator valueOperator    = ValueOperator.GreaterThanOrEq;
            long          actualValue      = 20L;
            long          matchingValue    = 10L;
            long          nonMatchingValue = 30L;

            Assert.AreEqual(true, ComparisonEngine.CompareLong(actualValue, matchingValue, valueOperator));

            matchingValue = 20L;
            Assert.AreEqual(true, ComparisonEngine.CompareLong(actualValue, matchingValue, valueOperator));

            Assert.AreEqual(false, ComparisonEngine.CompareLong(actualValue, nonMatchingValue, valueOperator));
        }
예제 #8
0
        /// <summary>
        /// Evaluates a specific value against the rule
        /// </summary>
        /// <param name="actualValue">The value to evaluate</param>
        /// <returns>A value indicating whether the rule conditions were met</returns>
        protected bool EvaluateAttributeValue(object actualValue, IList <object> expectedValues)
        {
            if (actualValue == null)
            {
                if (this.CompareAs == ExtendedAttributeType.Boolean)
                {
                    actualValue = false;
                }
                else
                {
                    this.RaiseRuleFailure(string.Format("The source value was null"));
                    return(false);
                }
            }

            bool result = false;

            foreach (object expectedValue in expectedValues)
            {
                switch (this.CompareAs)
                {
                case ExtendedAttributeType.Binary:
                    result = ComparisonEngine.CompareBinary(TypeConverter.ConvertData <byte[]>(actualValue), TypeConverter.ConvertData <byte[]>(expectedValue), this.ValueOperator);
                    break;

                case ExtendedAttributeType.Boolean:
                    result = ComparisonEngine.CompareBoolean(TypeConverter.ConvertData <bool>(actualValue), TypeConverter.ConvertData <bool>(expectedValue), this.ValueOperator);
                    break;

                case ExtendedAttributeType.Integer:
                    result = ComparisonEngine.CompareLong(TypeConverter.ConvertData <long>(actualValue), TypeConverter.ConvertData <long>(expectedValue), this.ValueOperator);
                    break;

                case ExtendedAttributeType.DateTime:
                    result = ComparisonEngine.CompareDateTime(TypeConverter.ConvertData <DateTime>(actualValue), TypeConverter.ConvertData <DateTime>(expectedValue), this.ValueOperator);
                    break;

                case ExtendedAttributeType.String:
                    result = ComparisonEngine.CompareString(TypeConverter.ConvertData <string>(actualValue), TypeConverter.ConvertData <string>(expectedValue), this.ValueOperator);
                    break;

                case ExtendedAttributeType.Reference:
                    result = ComparisonEngine.CompareString(TypeConverter.ConvertData <string>(actualValue), TypeConverter.ConvertData <string>(expectedValue), this.ValueOperator);
                    break;

                default:
                    throw new UnknownOrUnsupportedDataTypeException();
                }

                if (result)
                {
                    break;
                }
            }

            if (!result)
            {
                this.RaiseRuleFailure("Comparison failed\nComparison Operator: {0}\nExpected Values: {1}\nActual Value: {2}", this.ValueOperator.ToString(), expectedValues.Select(t => t.ToSmartStringOrNull()).ToCommaSeparatedString(), actualValue.ToSmartString());
            }

            return(result);
        }