Esempio n. 1
0
        internal static Mock <InternalEntityEntryForMock <FakeWithProps> > CreateMockInternalEntityEntry(
            InternalPropertyValues currentValues  = null,
            InternalPropertyValues originalValues = null)
        {
            currentValues = currentValues ?? CreateSimpleValues(10);
            var entity            = (FakeWithProps)currentValues.ToObject();
            var mockInternalEntry = MockHelper.CreateMockInternalEntityEntry(
                entity, new EntityReference <FakeEntity>(), new EntityCollection <FakeEntity>(), isDetached: false);

            mockInternalEntry.Setup(e => e.ValidateAndGetPropertyMetadata("ValueTypeProp", It.IsAny <Type>(), It.IsAny <Type>())).Returns(
                ValueTypePropertyMetadata);
            mockInternalEntry.Setup(e => e.ValidateAndGetPropertyMetadata("RefTypeProp", It.IsAny <Type>(), It.IsAny <Type>())).Returns(
                RefTypePropertyMetadata);
            mockInternalEntry.Setup(e => e.ValidateAndGetPropertyMetadata("ComplexProp", It.IsAny <Type>(), It.IsAny <Type>())).Returns(
                ComplexPropertyMetadata);
            mockInternalEntry.Setup(e => e.ValidateAndGetPropertyMetadata("Reference", It.IsAny <Type>(), It.IsAny <Type>()));
            mockInternalEntry.Setup(e => e.ValidateAndGetPropertyMetadata("Collection", It.IsAny <Type>(), It.IsAny <Type>()));
            mockInternalEntry.Setup(e => e.ValidateAndGetPropertyMetadata("Missing", It.IsAny <Type>(), It.IsAny <Type>()));
            mockInternalEntry.Setup(e => e.GetNavigationMetadata("ValueTypeProp"));
            mockInternalEntry.Setup(e => e.GetNavigationMetadata("RefTypeProp"));
            mockInternalEntry.Setup(e => e.GetNavigationMetadata("ComplexProp"));
            mockInternalEntry.Setup(e => e.GetNavigationMetadata("Reference")).Returns(ReferenceMetadata);
            mockInternalEntry.Setup(e => e.GetNavigationMetadata("Collection")).Returns(CollectionMetadata);
            mockInternalEntry.Setup(e => e.GetNavigationMetadata("ValueTypeProp"));
            mockInternalEntry.Setup(e => e.GetNavigationMetadata("RefTypeProp"));
            mockInternalEntry.Setup(e => e.GetNavigationMetadata("ComplexProp"));
            mockInternalEntry.SetupGet(e => e.CurrentValues).Returns(currentValues);
            mockInternalEntry.SetupGet(e => e.OriginalValues).Returns(originalValues ?? CreateSimpleValues(20));
            mockInternalEntry.CallBase = true;
            return(mockInternalEntry);
        }
Esempio n. 2
0
            protected override Mock <InternalReferenceEntry> CreateInternalEntryMock()
            {
                var internalEntryMock = new Mock <InternalReferenceEntry>(
                    MockHelper.CreateMockInternalEntityEntry(new object()).Object,
                    new NavigationEntryMetadataForMock());

                internalEntryMock.Setup(e => e.InternalEntityEntry).Throws(new NotImplementedException());

                return(internalEntryMock);
            }
Esempio n. 3
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
            }
            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);
            }
            public void InternalCollectionEntry_LoadAsync_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("LoadAsync", "Collection", "FakeEntity"),
                    Assert.Throws <InvalidOperationException>(
                        () =>
                        internalEntry.LoadAsync(CancellationToken.None)).Message);
            }
            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);
            }
Esempio n. 7
0
            InternalReferenceEntry_gets_current_value_from_RelatedEnd_if_navigation_property_has_been_removed_from_entity_implementation
                (FakeEntity relatedEntity)
            {
                var mockRelatedEnd = Core.Objects.DataClasses.MockHelper.CreateMockEntityReference(relatedEntity);

                var internalEntry =
                    new InternalReferenceEntry(
                        MockHelper.CreateMockInternalEntityEntry(new FakeEntity(), mockRelatedEnd.Object).Object,
                        FakeWithProps.ReferenceMetadata);

                var propValue = internalEntry.CurrentValue;

                Assert.Same(relatedEntity, propValue);
            }
Esempio n. 8
0
            public void InternalReferenceEntry_IsLoaded_throws_if_used_with_Detached_entity()
            {
                var mockInternalEntry = MockHelper.CreateMockInternalEntityEntry(
                    new FakeEntity(), isDetached: true);
                var internalEntry = new InternalReferenceEntry(mockInternalEntry.Object, FakeWithProps.ReferenceMetadata);

                Assert.Equal(
                    Strings.DbPropertyEntry_NotSupportedForDetached("IsLoaded", "Reference", "FakeEntity"),
                    Assert.Throws <InvalidOperationException>(() => { var _ = internalEntry.IsLoaded; }).Message);

                Assert.Equal(
                    Strings.DbPropertyEntry_NotSupportedForDetached("IsLoaded", "Reference", "FakeEntity"),
                    Assert.Throws <InvalidOperationException>(() => { internalEntry.IsLoaded = true; }).Message);
            }
            private void InternalCollectionEntry_gets_current_value_from_entity_if_property_exists_implementation(bool isDetached)
            {
                var relatedCollection = new List <FakeEntity>();
                var entity            = new FakeWithProps
                {
                    Collection = relatedCollection
                };
                var internalEntry = new InternalCollectionEntry(
                    MockHelper.CreateMockInternalEntityEntry(
                        entity, isDetached).Object, FakeWithProps.CollectionMetadata);

                var propValue = internalEntry.CurrentValue;

                Assert.Same(relatedCollection, propValue);
            }
Esempio n. 10
0
            private void InternalReferenceEntry_sets_current_value_onto_entity_if_property_exists_implementation(bool isDetached)
            {
                var entity = new FakeWithProps
                {
                    Reference = new FakeEntity()
                };
                var internalEntry = new InternalReferenceEntry(
                    MockHelper.CreateMockInternalEntityEntry(entity, isDetached).Object, FakeWithProps.ReferenceMetadata);

                var relatedEntity = new FakeEntity();

                internalEntry.CurrentValue = relatedEntity;

                Assert.Same(relatedEntity, entity.Reference);
            }
Esempio n. 11
0
            InternalReferenceEntry_sets_current_value_onto_RelatedEnd_if_navigation_property_has_been_removed_from_entity_implementation
                (FakeEntity currentRelatedEntity, FakeEntity newRelatedEntity)
            {
                var mockRelatedEnd = Core.Objects.DataClasses.MockHelper.CreateMockEntityReference(currentRelatedEntity);

                var internalEntry =
                    new FakeInternalReferenceEntry(
                        MockHelper.CreateMockInternalEntityEntry(new FakeEntity(), mockRelatedEnd.Object).Object,
                        FakeWithProps.ReferenceMetadata);

                internalEntry.CurrentValue = newRelatedEntity;

                Assert.Equal(1, internalEntry.SetCount);
                Assert.Same(newRelatedEntity, internalEntry.ValueSet);
            }
 protected override Mock <InternalReferenceEntry> CreateInternalEntryMock()
 {
     return(new Mock <InternalReferenceEntry>(
                MockHelper.CreateMockInternalEntityEntry(new object()).Object,
                new NavigationEntryMetadataForMock()));
 }