コード例 #1
0
        /// <summary>
        ///     Creates a <see cref="DbCollectionEntry{TEntity,TElement}" /> from information in the given
        ///     <see
        ///         cref="InternalCollectionEntry" />
        ///     .
        ///     Use this method in preference to the constructor since it may potentially create a subclass depending on
        ///     the type of member represented by the InternalCollectionEntry instance.
        /// </summary>
        /// <param name="internalCollectionEntry"> The internal collection entry. </param>
        /// <returns> The new entry. </returns>
        internal static DbCollectionEntry <TEntity, TElement> Create(InternalCollectionEntry internalCollectionEntry)
        {
            DebugCheck.NotNull(internalCollectionEntry);

            // Note that the implementation of this Create method is different than for the other DbMemberEntry classes.
            // This is because the DbMemberEntry is defined in terms of the ICollection<TElement> while this class
            // is defined in terms of just TElement.  This means that we can't just call the CreateDbMemberEntry factory
            // method on InternalMemberEntry.  Instead we call the special factory method on InternalCollectionEntry.
            return(internalCollectionEntry.CreateDbCollectionEntry <TEntity, TElement>());
        }
コード例 #2
0
                InternalCollectionEntry_gets_current_value_that_is_the_RelatedEnd_if_navigation_property_has_been_removed_from_entity()
            {
                var relatedCollection = new EntityCollection<FakeEntity>();
                var internalEntry =
                    new InternalCollectionEntry(
                        MockHelper.CreateMockInternalEntityEntry(new FakeEntity(), entityCollection: relatedCollection).Object,
                        FakeWithProps.CollectionMetadata);

                var propValue = internalEntry.CurrentValue;

                Assert.Same(relatedCollection, propValue);
            }
コード例 #3
0
            private void InternalCollectionEntry_sets_current_value_onto_entity_if_property_exists_implementation(bool isDetached)
            {
                var entity = new FakeWithProps
                                 {
                                     Collection = new List<FakeEntity>()
                                 };
                var internalEntry = new InternalCollectionEntry(
                    MockHelper.CreateMockInternalEntityEntry(
                        entity, isDetached).Object, FakeWithProps.CollectionMetadata);

                var relatedCollection = new List<FakeEntity>();
                internalEntry.CurrentValue = relatedCollection;

                Assert.Same(relatedCollection, entity.Collection);
            }
コード例 #4
0
        public void DbMemberEntry_Create_can_be_called_from_multiple_threads()
        {
            ExecuteInParallel(
                () =>
            {
                var collectionMetadata = new NavigationEntryMetadata(
                    typeof(FakeWithProps), typeof(FakeEntity), "Collection", isCollection: true);
                var internalEntry =
                    new InternalCollectionEntry(
                        new Mock <InternalEntityEntryForMock <FakeEntity> >().Object, collectionMetadata);

                var entry = internalEntry.CreateDbMemberEntry <FakeWithProps, ICollection <FakeEntity> >();

                Assert.IsAssignableFrom <DbMemberEntry <FakeWithProps, ICollection <FakeEntity> > >(entry);
            });
        }
コード例 #5
0
            public void Generic_DbCollectionEntry_Name_returns_name_of_property_from_internal_entry()
            {
                var internalEntry = new InternalCollectionEntry(
                    new Mock<InternalEntityEntryForMock<FakeEntity>>().Object, FakeWithProps.CollectionMetadata);

                Assert.Equal("Collection", internalEntry.Name);
            }
コード例 #6
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="DbCollectionEntry{TEntity, TProperty}" /> class.
        /// </summary>
        /// <param name="internalCollectionEntry"> The internal entry. </param>
        internal DbCollectionEntry(InternalCollectionEntry internalCollectionEntry)
        {
            DebugCheck.NotNull(internalCollectionEntry);

            _internalCollectionEntry = internalCollectionEntry;
        }
コード例 #7
0
        // <summary>
        // Creates a <see cref="DbCollectionEntry" /> from information in the given <see cref="InternalCollectionEntry" />.
        // Use this method in preference to the constructor since it may potentially create a subclass depending on
        // the type of member represented by the InternalCollectionEntry instance.
        // </summary>
        // <param name="internalCollectionEntry"> The internal collection entry. </param>
        // <returns> The new entry. </returns>
        internal static DbCollectionEntry Create(InternalCollectionEntry internalCollectionEntry)
        {
            DebugCheck.NotNull(internalCollectionEntry);

            return((DbCollectionEntry)internalCollectionEntry.CreateDbMemberEntry());
        }
コード例 #8
0
                InternalCollectionEntry_does_nothing_if_attempting_to_set_the_actual_EntityCollection_as_a_current_value_when_navigation_property_has_been_removed_from_entity
                ()
            {
                var relatedCollection = new EntityCollection<FakeEntity>();
                var internalEntry =
                    new InternalCollectionEntry(
                        MockHelper.CreateMockInternalEntityEntry(new FakeEntity(), entityCollection: relatedCollection).Object,
                        FakeWithProps.CollectionMetadata);

                internalEntry.CurrentValue = relatedCollection; // Test that it doesn't throw
            }
コード例 #9
0
            public void InternalCollectionEntry_Query_throws_if_used_with_Detached_entity()
            {
                var mockInternalEntry = MockHelper.CreateMockInternalEntityEntry(
                    new FakeEntity(), isDetached: true);
                var internalEntry = new InternalCollectionEntry(mockInternalEntry.Object, FakeWithProps.CollectionMetadata);

                Assert.Equal(
                    Strings.DbPropertyEntry_NotSupportedForDetached("Query", "Collection", "FakeEntity"),
                    Assert.Throws<InvalidOperationException>(() => internalEntry.Query()).Message);
            }
コード例 #10
0
            public void InternalCollectionEntry_throws_setting_current_value_from_detached_entity_if_navigation_property_has_been_removed()
            {
                var mockInternalEntry = MockHelper.CreateMockInternalEntityEntry(
                    new FakeEntity(), isDetached: true);
                var internalEntry = new InternalCollectionEntry(mockInternalEntry.Object, FakeWithProps.CollectionMetadata);

                Assert.Equal(
                    Strings.DbCollectionEntry_CannotSetCollectionProp("Collection", typeof(FakeEntity).ToString()),
                    Assert.Throws<NotSupportedException>(() => { internalEntry.CurrentValue = null; }).Message);
            }
コード例 #11
0
            public void InternalCollectionEntry_Name_works_even_when_used_with_Detached_entity()
            {
                var mockInternalEntry = MockHelper.CreateMockInternalEntityEntry(
                    new FakeEntity(), isDetached: true);
                var internalEntry = new InternalCollectionEntry(mockInternalEntry.Object, FakeWithProps.CollectionMetadata);

                Assert.Equal("Collection", internalEntry.Name);
            }
コード例 #12
0
            public void InternalCollectionEntry_throws_getting_current_value_from_detached_entity_if_navigation_property_has_been_removed()
            {
                var mockInternalEntry = MockHelper.CreateMockInternalEntityEntry(
                    new FakeEntity(), isDetached: true);
                var internalEntry = new InternalCollectionEntry(mockInternalEntry.Object, FakeWithProps.CollectionMetadata);

                Assert.Equal(
                    Strings.DbPropertyEntry_NotSupportedForDetached("CurrentValue", "Collection", "FakeEntity"),
                    Assert.Throws<InvalidOperationException>(() => { var _ = internalEntry.CurrentValue; }).Message);
            }
コード例 #13
0
                InternalCollectionEntry_throws_when_attempting_to_set_a_new_collection_when_navigation_property_has_been_removed_from_entity
                ()
            {
                var internalEntry =
                    new InternalCollectionEntry(
                        MockHelper.CreateMockInternalEntityEntry(new FakeEntity(), entityCollection: new EntityCollection<FakeEntity>()).
                            Object, FakeWithProps.CollectionMetadata);

                Assert.Equal(
                    Strings.DbCollectionEntry_CannotSetCollectionProp("Collection", typeof(FakeEntity).ToString()),
                    Assert.Throws<NotSupportedException>(() => internalEntry.CurrentValue = new List<FakeEntity>()).Message);
            }
コード例 #14
0
 internal DbCollectionEntry(InternalCollectionEntry internalCollectionEntry)
 {
     this._internalCollectionEntry = internalCollectionEntry;
 }
コード例 #15
0
 internal static DbCollectionEntry Create(
     InternalCollectionEntry internalCollectionEntry)
 {
     return((DbCollectionEntry)internalCollectionEntry.CreateDbMemberEntry());
 }
コード例 #16
0
 internal static DbCollectionEntry <TEntity, TElement> Create(
     InternalCollectionEntry internalCollectionEntry)
 {
     return(internalCollectionEntry.CreateDbCollectionEntry <TEntity, TElement>());
 }