Esempio n. 1
0
        public void EnumerableEqualityComparerReturnsTrueIfFirstAndSecondAreBothNull()
        {
            var comparer = new EnumerableComparer <int>();

            IEnumerable <int> first  = null;
            IEnumerable <int> second = null;

            bool result = comparer.Equals(first, second);

            Assert.IsTrue(result);
        }
Esempio n. 2
0
        public void EnumerableEqualityComparerReturnsFalseIfFirstIsGreaterLengthThanSecond()
        {
            var comparer = new EnumerableComparer <int>();

            IEnumerable <int> first = new List <int> {
                1, 2, 3, 4, 5
            };
            IEnumerable <int> second = new List <int>();

            bool result = comparer.Equals(first, second);

            Assert.IsFalse(result);
        }
Esempio n. 3
0
        public void EnumerableEqualityComparerReturnsFalseIfSecondListIsNull()
        {
            var comparer = new EnumerableComparer <int>();

            IEnumerable <int> first = new List <int> {
                1, 2, 3, 4, 5
            };
            IEnumerable <int> second = null;

            bool result = comparer.Equals(first, second);

            Assert.IsFalse(result);
        }
Esempio n. 4
0
        public void EnumerableEqualityComparerReturnsTrueIfSequencesAreSameReference()
        {
            var comparer = new EnumerableComparer <int>();

            IEnumerable <int> first = new List <int> {
                1, 2, 3, 4, 5
            };
            IEnumerable <int> second = first;

            bool result = comparer.Equals(first, second);

            Assert.IsTrue(result);
        }
Esempio n. 5
0
        public void EnumerableEqualityComparerReturnsFalseIfFirstAndSecondSequenceElementsAreTheSameButDifferentOrder()
        {
            var comparer = new EnumerableComparer <int>();

            IEnumerable <int> first = new List <int> {
                1, 2, 3, 4, 5
            };
            IEnumerable <int> second = new List <int> {
                5, 4, 3, 2, 1
            };

            bool result = comparer.Equals(first, second);

            Assert.IsFalse(result);
        }
Esempio n. 6
0
        public void EnumerableEqualityComparerReturnsFalseIfFirstAndSecondSequenceElementsAreNotTheSame()
        {
            var comparer = new EnumerableComparer <int>();

            IEnumerable <int> first = new List <int> {
                1, 2, 3, 4, 5
            };
            IEnumerable <int> second = new List <int> {
                6, 7, 8, 9, 10
            };

            bool result = comparer.Equals(first, second);

            Assert.IsFalse(result);
        }
Esempio n. 7
0
        /// <summary>
        /// Tries to update the property that the selector uses.
        /// </summary>
        /// <param name="newDocument">
        /// The new version of the document. Only non-null items are updated in the current document.
        /// </param>
        /// <param name="delta">
        /// The delta document. Has all changes that differ from the document.
        /// </param>
        /// <param name="selector">
        /// Returns the <see cref="IEnumerable{T}"/> to update.
        /// </param>
        /// <typeparam name="T">
        /// The type of the items in the selector.
        /// </typeparam>
        /// <returns>
        /// True if the document was updated, false otherwise.
        /// </returns>
        private bool TryUpdate <T>(SerializableDocumentDescriptor newDocument, SerializableDocumentDescriptor delta, [NotNull] Expression <Func <SerializableDocumentDescriptor, IReadOnlyList <T> > > selector)
        {
            var propertyInfo  = (PropertyInfo)((MemberExpression)selector.Body).Member;
            var getValue      = selector.Compile();
            var newValue      = getValue(newDocument);
            var existingValue = getValue(this.Descriptor);

            if (newValue == null || existingValue != null && EnumerableComparer.Equals(newValue, existingValue))
            {
                return(false);
            }

            propertyInfo.SetValue(delta, newValue);
            propertyInfo.SetValue(this.Descriptor, newValue);

            return(true);
        }