public void Throws_if_required_related_end_is_missing() { var entityReferenceMock = MockHelper.CreateMockEntityReference <object>(refreshedValue: null); var associationType = new AssociationType( name: "associationName", namespaceName: "associationNamespace", foreignKey: false, dataSpace: DataSpace.CSpace); entityReferenceMock.Setup(m => m.RelationMetadata).Returns(associationType); var refType = new RefType(new EntityType(name: "entityTypeName", namespaceName: "entityTypeNamespace", dataSpace: DataSpace.CSpace)); var toEndMember = new AssociationEndMember( name: "toEndMember", endRefType: refType, multiplicity: RelationshipMultiplicity.One); entityReferenceMock.Setup(m => m.ToEndMember).Returns(toEndMember); Assert.Equal( Strings.EntityReference_LessThanExpectedRelatedEntitiesFound, Assert.Throws <InvalidOperationException>( () => ExceptionHelpers.UnwrapAggregateExceptions( () => entityReferenceMock.Object.LoadAsync(MergeOption.NoTracking, CancellationToken.None).Wait())).Message); }
public void FK_association_with_nothing_to_load_and_NoTracking_option_does_nothing() { var entityReference = MockHelper.CreateMockEntityReference <object>(refreshedValue: null).Object; Assert.False(entityReference.IsLoaded); entityReference.Load(MergeOption.NoTracking); Assert.True(entityReference.IsLoaded); }
public void FK_association_with_nothing_to_load_and_AppendOnly_option_does_nothing() { var entityReference = MockHelper.CreateMockEntityReference <object>(refreshedValue: null).Object; Assert.False(entityReference.IsLoaded); entityReference.LoadAsync(MergeOption.AppendOnly, CancellationToken.None).Wait(); Assert.True(entityReference.IsLoaded); }
public void Throws_on_multiple_refreshed_values() { var entityReferenceMock = MockHelper.CreateMockEntityReference(refreshedValue: new object()); var objectQueryMock = Objects.MockHelper.CreateMockObjectQuery(refreshedValues: new[] { new object(), new object() }); var hasResults = true; entityReferenceMock.Setup(m => m.ValidateLoad <object>(It.IsAny <MergeOption>(), It.IsAny <string>(), out hasResults)) .Returns(() => objectQueryMock.Object); Assert.Equal( Strings.EntityReference_MoreThanExpectedRelatedEntitiesFound, Assert.Throws <InvalidOperationException>( () => entityReferenceMock.Object.Load(MergeOption.NoTracking)).Message); }
private void Calls_merge_if_an_entity_is_available(MergeOption mergeOption) { var entityReferenceMock = MockHelper.CreateMockEntityReference(refreshedValue: new object()); var timesMergeCalled = 0; entityReferenceMock.Setup(m => m.Merge(It.IsAny <IEnumerable <object> >(), It.IsAny <MergeOption>(), true)) .Callback( (IEnumerable <object> collection, MergeOption actualMergeOption, bool setIsLoaded) => { timesMergeCalled++; Assert.Equal(mergeOption, actualMergeOption); }); var entityReference = entityReferenceMock.Object; entityReference.LoadAsync(mergeOption, CancellationToken.None).Wait(); Assert.True(1 == timesMergeCalled, "Expected Merge to be called once for MergeOption." + mergeOption); }
public void FK_association_with_nothing_to_load_and_PreserveChanges_option_calls_RemoveRelationships() { var entityReference = MockHelper.CreateMockEntityReference <object>(refreshedValue: null).Object; Assert.False(entityReference.IsLoaded); entityReference.Load(MergeOption.PreserveChanges); Assert.True(entityReference.IsLoaded); var objectContext = entityReference.ObjectContext; var objectStateManagerMock = Mock.Get(objectContext.ObjectStateManager); objectStateManagerMock.Verify( m => m.RemoveRelationships( MergeOption.PreserveChanges, (AssociationSet)entityReference.RelationshipSet, entityReference.WrappedOwner.EntityKey, (AssociationEndMember)entityReference.FromEndMember)); }