public void Factory_sets_override_flag_appropriately_for_pure_POCO_entities()
        {
            var wrappedEntity = EntityWrapperFactory.CreateNewWrapper(new object(), new EntityKey());

            Assert.Same(typeof(EntityWrapperWithoutRelationships <>), wrappedEntity.GetType().GetGenericTypeDefinition());
            Assert.False(wrappedEntity.OverridesEqualsOrGetHashCode);

            wrappedEntity = EntityWrapperFactory.CreateNewWrapper(new Mock <PocoWithEquals>().Object, new EntityKey());
            Assert.Same(typeof(EntityWrapperWithoutRelationships <>), wrappedEntity.GetType().GetGenericTypeDefinition());
            Assert.True(wrappedEntity.OverridesEqualsOrGetHashCode);
        }
        public void Factory_sets_override_flag_appropriately_for_entities_with_relationships()
        {
            var wrappedEntity = EntityWrapperFactory.CreateNewWrapper(new EntityWithRelationshipsButWithoutEquals(), new EntityKey());

            Assert.Same(typeof(EntityWrapperWithRelationships <>), wrappedEntity.GetType().GetGenericTypeDefinition());
            Assert.False(wrappedEntity.OverridesEqualsOrGetHashCode);

            wrappedEntity = EntityWrapperFactory.CreateNewWrapper(new EntityWithRelationshipsAndEquals(), new EntityKey());
            Assert.Same(typeof(EntityWrapperWithRelationships <>), wrappedEntity.GetType().GetGenericTypeDefinition());
            Assert.True(wrappedEntity.OverridesEqualsOrGetHashCode);
        }
        public void Factory_sets_override_flag_appropriately_for_IPOCO_EntityObject_entities()
        {
            var wrappedEntity = EntityWrapperFactory.CreateNewWrapper(new EntityObjectWithoutEquals(), new EntityKey());

            Assert.Same(typeof(LightweightEntityWrapper <>), wrappedEntity.GetType().GetGenericTypeDefinition());
            Assert.False(wrappedEntity.OverridesEqualsOrGetHashCode);

            wrappedEntity = EntityWrapperFactory.CreateNewWrapper(new EntityObjectWithEquals(), new EntityKey());
            Assert.Same(typeof(LightweightEntityWrapper <>), wrappedEntity.GetType().GetGenericTypeDefinition());
            Assert.True(wrappedEntity.OverridesEqualsOrGetHashCode);
        }
        internal virtual IEntityWrapper WrapEntityUsingStateManagerGettingEntry(
            object entity,
            ObjectStateManager stateManager,
            out EntityEntry existingEntry)
        {
            IEntityWrapper wrapper = (IEntityWrapper)null;

            existingEntry = (EntityEntry)null;
            if (entity == null)
            {
                return(NullEntityWrapper.NullWrapper);
            }
            if (stateManager != null)
            {
                existingEntry = stateManager.FindEntityEntry(entity);
                if (existingEntry != null)
                {
                    return(existingEntry.WrappedEntity);
                }
                if (stateManager.TransactionManager.TrackProcessedEntities && stateManager.TransactionManager.WrappedEntities.TryGetValue(entity, out wrapper))
                {
                    return(wrapper);
                }
            }
            IEntityWithRelationships withRelationships = entity as IEntityWithRelationships;

            if (withRelationships != null)
            {
                RelationshipManager relationshipManager = withRelationships.RelationshipManager;
                if (relationshipManager == null)
                {
                    throw new InvalidOperationException(Strings.RelationshipManager_UnexpectedNull);
                }
                IEntityWrapper wrappedOwner = relationshipManager.WrappedOwner;
                if (!object.ReferenceEquals(wrappedOwner.Entity, entity))
                {
                    throw new InvalidOperationException(Strings.RelationshipManager_InvalidRelationshipManagerOwner);
                }
                return(wrappedOwner);
            }
            EntityProxyFactory.TryGetProxyWrapper(entity, out wrapper);
            if (wrapper == null)
            {
                IEntityWithKey entityWithKey = entity as IEntityWithKey;
                wrapper = EntityWrapperFactory.CreateNewWrapper(entity, entityWithKey == null ? (EntityKey)null : entityWithKey.EntityKey);
            }
            if (stateManager != null && stateManager.TransactionManager.TrackProcessedEntities)
            {
                stateManager.TransactionManager.WrappedEntities.Add(entity, wrapper);
            }
            return(wrapper);
        }
Exemple #5
0
        public void Factory_sets_override_flag_appropriately_for_entities_with_relationships()
        {
            var mockWithRelationships = new Mock <IEntityWithRelationships>();

            mockWithRelationships.Setup(m => m.RelationshipManager).Returns(RelationshipManager.Create(mockWithRelationships.Object));
            var wrappedEntity = EntityWrapperFactory.CreateNewWrapper(mockWithRelationships.Object, new EntityKey());

            Assert.Same(typeof(EntityWrapperWithRelationships <>), wrappedEntity.GetType().GetGenericTypeDefinition());
            Assert.False(wrappedEntity.OverridesEqualsOrGetHashCode);

            wrappedEntity = EntityWrapperFactory.CreateNewWrapper(new Mock <EntityWithRelationshipsAndEquals>().Object, new EntityKey());
            Assert.Same(typeof(EntityWrapperWithRelationships <>), wrappedEntity.GetType().GetGenericTypeDefinition());
            Assert.True(wrappedEntity.OverridesEqualsOrGetHashCode);
        }