Example #1
0
        public void AddRemovePart_SharedPart_ShouldCollectOnlyRoot()
        {
            var container = GetContainer();

            var exportedValue = new SharedImporter();

            CompositionBatch batch = new CompositionBatch();
            var part = batch.AddPart(exportedValue);

            container.Compose(batch);
            batch = null;

            batch = new CompositionBatch();
            batch.RemovePart(part);
            container.Compose(batch);
            batch = null;

            var refTracker = new ReferenceTracker();

            refTracker.AddReferencesExpectedToBeCollected(
                exportedValue);

            refTracker.AddReferencesNotExpectedToBeCollected(
                exportedValue.AnyPartDisposable,
                exportedValue.AnyPartDisposableRecomposable,
                exportedValue.AnyPartRecomposable,
                exportedValue.AnyPartSimple);

            part          = null;
            exportedValue = null;

            refTracker.CollectAndAssert();

            GC.KeepAlive(container);
        }
Example #2
0
        public void AddRemovePart_SharedRoot_ShouldNotDisposeChain()
        {
            var container = GetContainer();

            var exportedValue = new SharedImporter();

            CompositionBatch batch = new CompositionBatch();
            var part = batch.AddPart(exportedValue);

            container.Compose(batch);

            batch = new CompositionBatch();
            batch.RemovePart(part);
            container.Compose(batch);

            Assert.IsFalse(exportedValue.AnyPartDisposable.IsDisposed);
            Assert.IsFalse(exportedValue.AnyPartDisposableRecomposable.IsDisposed);
        }
Example #3
0
        public void AddRemovePart_SharedPart_ShouldCollectOnlyRoot()
        {
            var container = GetContainer();
            
            var exportedValue = new SharedImporter();

            CompositionBatch batch = new CompositionBatch();
            var part = batch.AddPart(exportedValue);
            container.Compose(batch);
            batch = null;

            batch = new CompositionBatch();
            batch.RemovePart(part);
            container.Compose(batch);
            batch = null;

            var refTracker = new ReferenceTracker();

            refTracker.AddReferencesExpectedToBeCollected(
             exportedValue);

            refTracker.AddReferencesNotExpectedToBeCollected(
                exportedValue.AnyPartDisposable,
                exportedValue.AnyPartDisposableRecomposable,
                exportedValue.AnyPartRecomposable,
                exportedValue.AnyPartSimple);

            part = null;
            exportedValue = null;

            refTracker.CollectAndAssert();

            GC.KeepAlive(container);
        }
Example #4
0
        public void AddRemovePart_SharedRoot_ShouldNotDisposeChain()
        {
            var container = GetContainer();

            var exportedValue = new SharedImporter();

            CompositionBatch batch = new CompositionBatch();
            var part = batch.AddPart(exportedValue);
            container.Compose(batch);

            batch = new CompositionBatch();
            batch.RemovePart(part);
            container.Compose(batch);

            Assert.IsFalse(exportedValue.AnyPartDisposable.IsDisposed);
            Assert.IsFalse(exportedValue.AnyPartDisposableRecomposable.IsDisposed);
        }