Ejemplo n.º 1
0
        public void TryCompareTo()
        {
            int result;

            Assert.AreEqual(true, ComparableUtils.TryCompareTo(new SourceComparable(1), new TargetComparable(2), out result));
            Assert.AreEqual(-1, result);
        }
Ejemplo n.º 2
0
        public int CompareTo(AppVersion other)
        {
            AssertUtils.AssertNotNull(other);

            var compare = ComparableUtils.Compare(this.Major, other.Major);

            if (compare != 0)
            {
                return(compare);
            }

            compare = ComparableUtils.Compare(this.Minor, other.Minor);
            if (compare != 0)
            {
                return(compare);
            }

            compare = ComparableUtils.Compare(this.Build ?? 0, other.Build ?? 0);
            if (compare != 0)
            {
                return(compare);
            }

            return(ComparableUtils.Compare(this.Revision ?? 0, other.Revision ?? 0));
        }
Ejemplo n.º 3
0
        public void TryCompareTo(
            [Values(1, 0, 5, 0, 0, -1, 1)]
            IComparable sourceValue,
            [Values(3, 1, 5, 0, -1, 0, "2")]
            IComparable targetValue,
            [Values(true, true, true, true, true, true, false)]
            bool canCompare,
            [Values(-1, -1, 0, 0, 1, -1, 0)]
            int expectedResult)
        {
            int result;

            Assert.AreEqual(canCompare, ComparableUtils.TryCompareTo(sourceValue, targetValue, out result));
            Assert.AreEqual(expectedResult, result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Determines whether the specified value is valid.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns><c>true</c> if the specified value is valid otherwise <c>false</c></returns>
        public override bool IsValid(object value)
        {
            if (value == null)
            {
                return(true);
            }

            IComparable comparableValue = value as IComparable;

            if (comparableValue == null)
            {
                return(false);
            }

            int compareResult;

            if (ComparableUtils.TryCompareTo(m_ValueToCompare, comparableValue, out compareResult))
            {
                return(compareResult < 0);
            }

            return(false);
        }
        /// <summary>
        /// Determines whether the specified value is valid.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns><c>true</c> if the specified value is valid otherwise <c>false</c></returns>
        public override bool IsValid(object value)
        {
            if (value == null)
            {
                return(true);
            }

            IComparable comparableValue = value as IComparable;

            if (comparableValue == null)
            {
                return(false);
            }

            int compareWithFromValueResult, compareWithToValueResult;

            if (ComparableUtils.TryCompareTo(comparableValue, FromValue, out compareWithFromValueResult) &&
                ComparableUtils.TryCompareTo(comparableValue, ToValue, out compareWithToValueResult))
            {
                return(compareWithFromValueResult >= 0 && compareWithToValueResult <= 0);
            }

            return(false);
        }
        /// <summary>
        /// Determines whether [are equal] [the specified values].
        /// </summary>
        /// <param name="sourceValue">The source value.</param>
        /// <param name="destinationValue">The destination value.</param>
        /// <param name="comparer">The comparer.</param>
        /// <returns><c>true</c> if the specified values are equal otherwise <c>false</c></returns>
        private static bool AreEqual(object sourceValue, object destinationValue, IEqualityComparer comparer = null)
        {
            if (comparer != null)
            {
                return(comparer.Equals(sourceValue, destinationValue));
            }

            IComparable sourceComparable = sourceValue as IComparable;

            if (sourceComparable != null)
            {
                IComparable destinationComparable = destinationValue as IComparable;
                if (destinationComparable != null)
                {
                    int compareResult;
                    if (ComparableUtils.TryCompareTo(sourceComparable, destinationComparable, out compareResult))
                    {
                        return(compareResult == 0);
                    }
                }
            }

            return(sourceValue == destinationValue);
        }
Ejemplo n.º 7
0
        public void TryCompareToMustThrowArgumentNullExceptionWhenTargetValueIsNull()
        {
            int result;

            ComparableUtils.TryCompareTo(1, null, out result);
        }
Ejemplo n.º 8
0
        public void TryCompareToMustThrowArgumentNullExceptionWhenSourceValueIsNull()
        {
            int result;

            ComparableUtils.TryCompareTo(null, 1, out result);
        }