public void ClonedObjectContext_disposes_of_connections_in_correct_order() { var myConnectionInterceptor = new ConnectionDisposingInterceptor(); DbInterception.Add(myConnectionInterceptor); try { var mockClonedContext = new Mock <ObjectContextProxy>(); var storeConnection = new SqlConnection(); var mockEntityConnection = new Mock <EntityConnectionProxy>(); mockEntityConnection.Setup(m => m.StoreConnection).Returns(storeConnection); mockEntityConnection.Setup(m => m.CreateNew(It.IsAny <SqlConnection>())).Returns <SqlConnection>( c => { var mockClonedConnection = new Mock <EntityConnectionProxy>(); mockClonedConnection.Setup(cc => cc.StoreConnection).Returns(c); mockClonedConnection.Setup(m => m.Dispose()).Callback(() => myConnectionInterceptor.IsClonedEntityConnectionDisposed = true); return(mockClonedConnection.Object); }); var mockContext = CreateMockObjectContext(mockEntityConnection, mockClonedContext); var clonedContext = new ClonedObjectContext(mockContext.Object, null, "Database=PinkyDinkyDo"); clonedContext.Dispose(); } finally { DbInterception.Remove(myConnectionInterceptor); } }
public void ClonedObjectContext_disposes_of_connections_in_correct_order() { var myConnectionInterceptor = new ConnectionDisposingInterceptor(); DbInterception.Add(myConnectionInterceptor); try { var mockClonedContext = new Mock<ObjectContextProxy>(); var storeConnection = new SqlConnection(); var mockEntityConnection = new Mock<EntityConnectionProxy>(); mockEntityConnection.Setup(m => m.StoreConnection).Returns(storeConnection); mockEntityConnection.Setup(m => m.CreateNew(It.IsAny<SqlConnection>())).Returns<SqlConnection>( c => { var mockClonedConnection = new Mock<EntityConnectionProxy>(); mockClonedConnection.Setup(cc => cc.StoreConnection).Returns(c); mockClonedConnection.Setup(m => m.Dispose()).Callback(() => myConnectionInterceptor.IsClonedEntityConnectionDisposed = true); return mockClonedConnection.Object; }); var mockContext = CreateMockObjectContext(mockEntityConnection, mockClonedContext); var clonedContext = new ClonedObjectContext(mockContext.Object, null, "Database=PinkyDinkyDo"); clonedContext.Dispose(); } finally { DbInterception.Remove(myConnectionInterceptor); } }