Esempio n. 1
0
            public void OnChanged(object sender, ComposablePartCatalogChangeEventArgs args)
            {
                Assert.IsTrue(this._expectedAdds != null || this._expectedRemoves != null);

                if (this._expectedAdds == null)
                {
                    EnumerableAssert.IsEmpty(args.AddedDefinitions);
                }
                else
                {
                    EnumerableAssert.AreSequenceEqual(this._expectedAdds, GetDisplayNames(args.AddedDefinitions));
                }

                if (this._expectedRemoves == null)
                {
                    EnumerableAssert.IsEmpty(args.RemovedDefinitions);
                }
                else
                {
                    EnumerableAssert.AreSequenceEqual(this._expectedRemoves, GetDisplayNames(args.RemovedDefinitions));
                }

                Assert.IsNull(args.AtomicComposition);
                Assert.IsTrue(ContainsChanges(), "The catalog should contain the changes");

                this._changedEventCount++;
            }
Esempio n. 2
0
        internal static void AreEqual(CompositionResult expected, CompositionResult actual)
        {
            Assert.AreEqual(expected.Succeeded, actual.Succeeded);

            EnumerableAssert.AreSequenceEqual(expected.Errors, actual.Errors, (index, expectedError, actualError) =>
            {
                AreEqual(expectedError, actualError);
            });
        }
Esempio n. 3
0
        public void Constructor_ValueAsCatalogArgument_ShouldSetPartsProperty()
        {
            var expectations = Expectations.GetCatalogs();

            foreach (var e in expectations)
            {
                var proxy = new ComposablePartCatalogDebuggerProxy(e);

                EnumerableAssert.AreSequenceEqual(e.Parts, proxy.Parts);
            }
        }
Esempio n. 4
0
        public void Parts_DelegateToCatalog()
        {
            var         parts   = new TypeCatalog(typeof(FooImpl), typeof(FooImpl2), typeof(FooImpl2)).Parts;
            var         exports = parts.Select(p => Tuple.Create(p, p.ExportDefinitions.First()));
            TestCatalog catalog = new TestCatalog(
                () => parts,
                () => exports);

            CompositionScopeDefinition scope = new CompositionScopeDefinition(catalog, null);

            EnumerableAssert.AreSequenceEqual(parts, scope.Parts);
        }
        public void Constructor_ValueAsCatalogArgument_ShouldSetPartsProperty()
        {
            var expectations = Expectations.GetAssemblies();

            foreach (var e in expectations)
            {
                var catalog = CreateAssemblyCatalog(e);

                var proxy = new AssemblyCatalogDebuggerProxy(catalog);

                EnumerableAssert.AreSequenceEqual(catalog.Parts, proxy.Parts);
            }
        }
Esempio n. 6
0
        public void Constructor2_PropertiesShouldBeSetAndMatchArguments()
        {
            ComposablePart[] partsToAdd    = new ComposablePart[] { PartFactory.Create(), PartFactory.Create(), PartFactory.Create() };
            ComposablePart[] partsToRemove = new ComposablePart[] { PartFactory.Create(), PartFactory.Create(), PartFactory.Create() };


            CompositionBatch batch = new CompositionBatch(partsToAdd, partsToRemove);

            Assert.IsNotNull(batch.PartsToAdd);
            Assert.IsNotNull(batch.PartsToRemove);

            EnumerableAssert.AreSequenceEqual(batch.PartsToAdd, partsToAdd);
            EnumerableAssert.AreSequenceEqual(batch.PartsToRemove, partsToRemove);
        }
        public void Constructor_ValueAsCatalogArgument_ShouldSetPartsProperty()
        {
            var expectations = Expectations.GetAssemblies();

            foreach (var e in expectations)
            {
                using (TemporaryFileCopier copier = new TemporaryFileCopier(e.Location))
                {
                    var catalog = CreateDirectoryCatalog(copier.DirectoryPath);

                    var proxy = new DirectoryCatalog.DirectoryCatalogDebuggerProxy(catalog);

                    EnumerableAssert.AreSequenceEqual(catalog.Parts, proxy.Parts);
                }
            }
        }
        public void Errors_CanBeSerialized()
        {
            var expectations = Expectations.GetCompositionErrors();

            foreach (var e in expectations)
            {
                var exception = CreateCompositionException(e);

                var result = SerializationTestServices.RoundTrip(exception);

                EnumerableAssert.AreSequenceEqual(exception.Errors, result.Errors, (index, expected, actual) =>
                {
                    CompositionAssert.AreEqual(expected, actual);
                });
            }
        }
Esempio n. 9
0
        public void Parts_ShouldNotCacheUnderlyingParts()
        {
            var catalog = CatalogFactory.CreateAggregateCatalog();
            var proxy   = CreateComposablePartCatalogDebuggerProxy(catalog);

            EnumerableAssert.IsEmpty(proxy.Parts);

            var expectations = Expectations.GetCatalogs();

            foreach (var e in expectations)
            {
                catalog.Catalogs.Add(e);

                EnumerableAssert.AreSequenceEqual(catalog.Parts, proxy.Parts);

                catalog.Catalogs.Remove(e);
            }
        }
Esempio n. 10
0
        public void FilteredNotifications()
        {
            var catalog1 = CreateSubCatalog1();
            var catalog2 = CreateSubCatalog2();
            var catalog  = new AggregateCatalog();

            var filter1 = catalog.Filter(p => p.Exports <IContract1>());
            var filter2 = catalog.Filter(p => p.Exports <IContract2>());

            bool filter1Ing = false;
            bool filter1Ed  = false;
            bool filter2Ing = false;
            bool filter2Ed  = false;

            ComposablePartCatalogChangeEventArgs edArgs  = null;
            ComposablePartCatalogChangeEventArgs ingArgs = null;

            filter1.Changing += (object s, ComposablePartCatalogChangeEventArgs a) =>
            {
                Assert.AreSame(filter1, s);
                Assert.IsFalse(filter1Ing);
                Assert.IsFalse(filter1Ed);
                Assert.IsNull(ingArgs);
                Assert.IsNull(edArgs);

                filter1Ing = true;
                ingArgs    = a;
            };

            filter1.Changed += (object s, ComposablePartCatalogChangeEventArgs a) =>
            {
                Assert.IsTrue(filter1Ing);
                Assert.IsFalse(filter1Ed);
                Assert.IsNotNull(ingArgs);
                Assert.IsNull(edArgs);

                filter1Ed = true;
                edArgs    = a;
                EnumerableAssert.AreSequenceEqual(ingArgs.AddedDefinitions, edArgs.AddedDefinitions);
                EnumerableAssert.AreSequenceEqual(ingArgs.RemovedDefinitions, edArgs.RemovedDefinitions);
            };

            filter2.Changing += (object s, ComposablePartCatalogChangeEventArgs a) =>
            {
                Assert.AreSame(filter2, s);
                Assert.IsFalse(filter2Ing);
                Assert.IsFalse(filter2Ed);
                Assert.IsNull(ingArgs);
                Assert.IsNull(edArgs);

                filter2Ing = true;
                ingArgs    = a;
            };

            filter2.Changed += (object s, ComposablePartCatalogChangeEventArgs a) =>
            {
                Assert.IsTrue(filter2Ing);
                Assert.IsFalse(filter2Ed);
                Assert.IsNotNull(ingArgs);
                Assert.IsNull(edArgs);

                filter2Ed = true;
                edArgs    = a;
                EnumerableAssert.AreSequenceEqual(ingArgs.AddedDefinitions, edArgs.AddedDefinitions);
                EnumerableAssert.AreSequenceEqual(ingArgs.RemovedDefinitions, edArgs.RemovedDefinitions);
            };


            //at first everything is empty

            // add the first one
            filter1Ing = false;
            filter1Ed  = false;
            filter2Ing = false;
            filter2Ed  = false;
            ingArgs    = null;
            edArgs     = null;

            catalog.Catalogs.Add(catalog1);
            Assert.IsTrue(filter1Ing);
            Assert.IsTrue(filter1Ed);
            Assert.IsFalse(filter2Ing);
            Assert.IsFalse(filter2Ed);

            Assert.AreEqual(edArgs.AddedDefinitions.Count(), 2);
            Assert.AreEqual(edArgs.RemovedDefinitions.Count(), 0);
            Assert.AreEqual(0, filter2.Parts.Count());
            Assert.AreEqual(2, filter1.Parts.Count());

            EnumerableAssert.AreSequenceEqual(ingArgs.AddedDefinitions, catalog1.Parts);
            EnumerableAssert.AreSequenceEqual(edArgs.AddedDefinitions, catalog1.Parts);

            // add the second one
            filter1Ing = false;
            filter1Ed  = false;
            filter2Ing = false;
            filter2Ed  = false;
            ingArgs    = null;
            edArgs     = null;

            catalog.Catalogs.Add(catalog2);
            Assert.IsTrue(filter2Ing);
            Assert.IsTrue(filter2Ed);
            Assert.IsFalse(filter1Ing);
            Assert.IsFalse(filter1Ed);

            Assert.AreEqual(edArgs.AddedDefinitions.Count(), 2);
            Assert.AreEqual(edArgs.RemovedDefinitions.Count(), 0);
            Assert.AreEqual(2, filter2.Parts.Count());
            Assert.AreEqual(2, filter1.Parts.Count());

            EnumerableAssert.AreSequenceEqual(ingArgs.AddedDefinitions, catalog2.Parts);
            EnumerableAssert.AreSequenceEqual(edArgs.AddedDefinitions, catalog2.Parts);


            // remove the second one
            filter1Ing = false;
            filter1Ed  = false;
            filter2Ing = false;
            filter2Ed  = false;
            ingArgs    = null;
            edArgs     = null;

            catalog.Catalogs.Remove(catalog2);
            Assert.IsTrue(filter2Ing);
            Assert.IsTrue(filter2Ed);
            Assert.IsFalse(filter1Ing);
            Assert.IsFalse(filter1Ed);

            Assert.AreEqual(edArgs.AddedDefinitions.Count(), 0);
            Assert.AreEqual(edArgs.RemovedDefinitions.Count(), 2);
            Assert.AreEqual(0, filter2.Parts.Count());
            Assert.AreEqual(2, filter1.Parts.Count());

            EnumerableAssert.AreSequenceEqual(ingArgs.RemovedDefinitions, catalog2.Parts);
            EnumerableAssert.AreSequenceEqual(edArgs.RemovedDefinitions, catalog2.Parts);


            // remove the first one
            filter1Ing = false;
            filter1Ed  = false;
            filter2Ing = false;
            filter2Ed  = false;
            ingArgs    = null;
            edArgs     = null;

            catalog.Catalogs.Remove(catalog1);
            Assert.IsTrue(filter1Ing);
            Assert.IsTrue(filter1Ed);
            Assert.IsFalse(filter2Ing);
            Assert.IsFalse(filter2Ed);

            Assert.AreEqual(edArgs.AddedDefinitions.Count(), 0);
            Assert.AreEqual(edArgs.RemovedDefinitions.Count(), 2);
            Assert.AreEqual(0, filter2.Parts.Count());
            Assert.AreEqual(0, filter1.Parts.Count());

            EnumerableAssert.AreSequenceEqual(ingArgs.RemovedDefinitions, catalog1.Parts);
            EnumerableAssert.AreSequenceEqual(edArgs.RemovedDefinitions, catalog1.Parts);
        }