Esempio n. 1
0
        public void NoNotificationsAfterDispose()
        {
            var catalog1 = CreateSubCatalog1();
            var catalog2 = CreateSubCatalog2();
            var catalog  = new AggregateCatalog(catalog1, catalog2);

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

            filter1.Changing += (s, e) =>
            {
                throw new NotImplementedException();
            };

            filter1.Changed += (s, e) =>
            {
                throw new NotImplementedException();
            };

            filter1.Dispose();

            Assert.True(catalog.Catalogs.Remove(catalog1));
            Assert.True(catalog.Catalogs.Remove(catalog2));
        }
Esempio n. 2
0
        public void NoNotificationsAfterDispose()
        {
            var catalog1 = CreateSubCatalog1();
            var catalog2 = CreateSubCatalog2();
            var catalog  = new AggregateCatalog(catalog1, catalog2);

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

            filter1.Changing += (s, e) =>
            {
                Assert.Fail("No events should be fired");
            };

            filter1.Changed += (s, e) =>
            {
                Assert.Fail("No events should be fired");
            };

            filter1.Dispose();

            Assert.IsTrue(catalog.Catalogs.Remove(catalog1));
            Assert.IsTrue(catalog.Catalogs.Remove(catalog2));
        }
Esempio n. 3
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.Same(filter1, s);
                Assert.False(filter1Ing);
                Assert.False(filter1Ed);
                Assert.Null(ingArgs);
                Assert.Null(edArgs);

                filter1Ing = true;
                ingArgs    = a;
            };

            filter1.Changed += (object s, ComposablePartCatalogChangeEventArgs a) =>
            {
                Assert.True(filter1Ing);
                Assert.False(filter1Ed);
                Assert.NotNull(ingArgs);
                Assert.Null(edArgs);

                filter1Ed = true;
                edArgs    = a;
                EqualityExtensions.CheckEquals(ingArgs.AddedDefinitions, edArgs.AddedDefinitions);
                EqualityExtensions.CheckEquals(ingArgs.RemovedDefinitions, edArgs.RemovedDefinitions);
            };

            filter2.Changing += (object s, ComposablePartCatalogChangeEventArgs a) =>
            {
                Assert.Same(filter2, s);
                Assert.False(filter2Ing);
                Assert.False(filter2Ed);
                Assert.Null(ingArgs);
                Assert.Null(edArgs);

                filter2Ing = true;
                ingArgs    = a;
            };

            filter2.Changed += (object s, ComposablePartCatalogChangeEventArgs a) =>
            {
                Assert.True(filter2Ing);
                Assert.False(filter2Ed);
                Assert.NotNull(ingArgs);
                Assert.Null(edArgs);

                filter2Ed = true;
                edArgs    = a;
                EqualityExtensions.CheckEquals(ingArgs.AddedDefinitions, edArgs.AddedDefinitions);
                EqualityExtensions.CheckEquals(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.True(filter1Ing);
            Assert.True(filter1Ed);
            Assert.False(filter2Ing);
            Assert.False(filter2Ed);

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

            EqualityExtensions.CheckEquals(ingArgs.AddedDefinitions, catalog1.Parts);
            EqualityExtensions.CheckEquals(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.True(filter2Ing);
            Assert.True(filter2Ed);
            Assert.False(filter1Ing);
            Assert.False(filter1Ed);

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

            EqualityExtensions.CheckEquals(ingArgs.AddedDefinitions, catalog2.Parts);
            EqualityExtensions.CheckEquals(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.True(filter2Ing);
            Assert.True(filter2Ed);
            Assert.False(filter1Ing);
            Assert.False(filter1Ed);

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

            EqualityExtensions.CheckEquals(ingArgs.RemovedDefinitions, catalog2.Parts);
            EqualityExtensions.CheckEquals(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.True(filter1Ing);
            Assert.True(filter1Ed);
            Assert.False(filter2Ing);
            Assert.False(filter2Ed);

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

            EqualityExtensions.CheckEquals(ingArgs.RemovedDefinitions, catalog1.Parts);
            EqualityExtensions.CheckEquals(edArgs.RemovedDefinitions, catalog1.Parts);
        }