/// <summary>
        /// Determines whether the <see cref="DomainObjectCollection"/> contains a reference to the specified <paramref name="domainObject"/>.
        /// </summary>
        /// <param name="domainObject">The <see cref="DomainObject"/> to locate in the <see cref="DomainObjectCollection"/>. Must not be <see langword="null"/>.</param>
        /// <returns><see langword="true"/> if <paramref name="domainObject"/> is found in the <see cref="DomainObjectCollection"/>; otherwise, false;</returns>
        /// <exception cref="System.ArgumentNullException"><paramref name="domainObject"/> is <see langword="null"/></exception>
        /// <remarks>
        /// <para>This method only returns <see langword="true" /> if the same reference is found in the collection. It returns <see langword="false" />
        /// when the collection contains no matching object or another object reference (from another <see cref="ClientTransaction"/>) with the same
        /// <see cref="DomainObject.ID"/>.
        /// </para>
        /// </remarks>
        public bool ContainsObject(DomainObject domainObject)
        {
            ArgumentUtility.CheckNotNull("domainObject", domainObject);

            var existingObject = _dataStrategy.GetObject(domainObject.ID);

            return(existingObject != null && ReferenceEquals(existingObject, domainObject));
        }
Ejemplo n.º 2
0
        public void Insert_InvalidatesCache()
        {
            WarmUpCache(_decoratorWithRealData, false);
            Assert.That(_decoratorWithRealData.IsCacheUpToDate, Is.True);

            var domainObject = DomainObjectMother.CreateFakeObject <Order>();

            _decoratorWithRealData.Insert(0, domainObject);

            Assert.That(_wrappedData.GetObject(0), Is.SameAs(domainObject));
            Assert.That(_decoratorWithRealData.IsCacheUpToDate, Is.False);
        }
        public static bool SetEquals(this IDomainObjectCollectionData collection, IEnumerable <DomainObject> comparedSet)
        {
            ArgumentUtility.CheckNotNull("collection", collection);
            ArgumentUtility.CheckNotNull("comparedSet", comparedSet);

            var setOfComparedObjects = new HashSet <DomainObject> (); // this is used to get rid of all duplicates to get a correct result

            foreach (var domainObject in comparedSet)
            {
                if (collection.GetObject(domainObject.ID) != domainObject)
                {
                    return(false);
                }

                setOfComparedObjects.Add(domainObject);
            }

            // the collection must contain exactly the same number of items as the comparedSet (duplicates ignored)
            return(collection.Count == setOfComparedObjects.Count);
        }
 public virtual DomainObject GetObject(int index)
 {
     return(_wrappedData.GetObject(index));
 }