Пример #1
0
        public void CompareBinaryFromStringEqualsTest()
        {
            ValueOperator valueOperator    = ValueOperator.Equals;
            string        actualValue      = "AAECAwQ=";
            string        matchingValue    = "AAECAwQ=";
            string        nonMatchingValue = "AAACAwQ=";

            Assert.AreEqual(true, ComparisonEngine.CompareBinary(actualValue, matchingValue, valueOperator));
            Assert.AreEqual(false, ComparisonEngine.CompareBinary(actualValue, nonMatchingValue, valueOperator));
        }
Пример #2
0
        public void CompareBinaryNoPresenceTest()
        {
            ValueOperator valueOperator = ValueOperator.NotPresent;

            byte[] actualValue      = null;
            byte[] matchingValue    = new byte[] { 0, 1, 2, 3 };
            byte[] nonMatchingValue = new byte[] { 0, 1, 2, 4 };

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

            actualValue = new byte[] { 0, 1, 2, 3, 4 };
            Assert.AreEqual(false, ComparisonEngine.CompareBinary(actualValue, matchingValue, valueOperator));
        }
        /// <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 byte[] GetValueFromMvBinary(IList <object> source)
        {
            foreach (object value in source)
            {
                byte[] valueByte = TypeConverter.ConvertData <byte[]>(value);

                if (ComparisonEngine.CompareBinary(valueByte, this.SelectorValue, this.SelectorOperator))
                {
                    return(valueByte);
                }
            }

            throw new NotFoundException();
        }
Пример #4
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);
        }