public void change_tracking_is_applied_when_entity_set_in_constructor() { var metadataFactory = new AttributeMetadataFactory(new NullLogger()); var queryExecutorFactory = new Mock <IQueryExecutorFactory>(); var mapper = new Mock <IMapper <Parent> >(); var repositoryFactory = new Mock <IRepositoryFactory>(); repositoryFactory.Setup(x => x.Create(It.IsAny <IGraphSession>(), It.IsAny <Type>())).Returns <IGraphSession, Type>((s, t) => new GenericAbstractRepository <Parent>(mapper.Object, s, new DynamicProxyFactory(metadataFactory, new NullLogger()))); var stateTracker = new EntityStateCache(); var proxyFactory = new DynamicProxyFactory(metadataFactory, new NullLogger()); using (var session = new GraphSession(new UnitOfWork(stateTracker), new List <IListener>(), queryExecutorFactory.Object, repositoryFactory.Object, stateTracker, proxyFactory)) { var proxy = session.Create(new Parent { Id = "1", Child = new Child { Id = "2" } }); var state = stateTracker.Get(proxy.Child); Assert.Equal(EntityStatus.New, state.Status); } }
public void interceptors_are_not_created_for_re_entrant_proxies() { var metadataFactory = new AttributeMetadataFactory(new NullLogger()); var proxyFactory = new DynamicProxyFactory(metadataFactory, new NullLogger()); var queryExecutorFactory = new Mock <IQueryExecutorFactory>(); var repositoryFactory = new RepositoryFactory(proxyFactory); var parentMapper = new Mock <IMapper <Parent> >(); repositoryFactory.Register <Parent>(x => parentMapper.Object); var childMapper = new Mock <IMapper <Child> >(); repositoryFactory.Register <Child>(x => childMapper.Object); var stateTracker = new EntityStateCache(); using (var session = new GraphSession(new UnitOfWork(stateTracker), new List <IListener>(), queryExecutorFactory.Object, repositoryFactory, stateTracker, proxyFactory)) { var proxy = session.Create(new Parent { Id = "1" }); proxy.Child = session.Create(new Child { Id = "1" }); var metadata = metadataFactory.Create(proxy); var deleted = ProxyUtils.Flush(proxy, metadata["Child"].Relationship); Assert.Equal(0, deleted.SelectMany(x => x.Flush().Cast <object>()).Count()); var reentrant = session.Create(proxy); Assert.Equal(proxy, reentrant); metadata = metadataFactory.Create(reentrant); deleted = ProxyUtils.Flush(reentrant, metadata["Child"].Relationship); Assert.Equal(0, deleted.SelectMany(x => x.Flush().Cast <object>()).Count()); proxy.Child = session.Create(new Child { Id = "2" }); metadata = metadataFactory.Create(reentrant); deleted = ProxyUtils.Flush(reentrant, metadata["Child"].Relationship); Assert.Equal(1, deleted.SelectMany(x => x.Flush().Cast <object>()).Count()); } }