示例#1
0
        public void ImportCompletedTest()
        {
            var container = ContainerFactory.Create(); 
            CompositionBatch batch = new CompositionBatch();
            var entrypoint = new UpperCaseStringComponent();

            batch.AddParts(new LowerCaseString("abc"), entrypoint);
            container.Compose(batch);

            batch = new CompositionBatch();
            batch.AddParts(new object());
            container.Compose(batch);

            Assert.AreEqual(entrypoint.LowerCaseStrings.Count, 1);
            Assert.AreEqual(entrypoint.ImportCompletedCallCount, 1);
            Assert.AreEqual(entrypoint.UpperCaseStrings.Count, 1);
            Assert.AreEqual(entrypoint.LowerCaseStrings[0].Value.String, "abc");
            Assert.AreEqual(entrypoint.UpperCaseStrings[0], "ABC");
        }
示例#2
0
        public void ImportCompletedTest()
        {
            var container          = ContainerFactory.Create();
            CompositionBatch batch = new CompositionBatch();
            var entrypoint         = new UpperCaseStringComponent();

            batch.AddParts(new LowerCaseString("abc"), entrypoint);
            container.Compose(batch);

            batch = new CompositionBatch();
            batch.AddParts(new object());
            container.Compose(batch);

            Assert.Equal(entrypoint.LowerCaseStrings.Count, 1);
            Assert.Equal(entrypoint.ImportCompletedCallCount, 1);
            Assert.Equal(entrypoint.UpperCaseStrings.Count, 1);
            Assert.Equal(entrypoint.LowerCaseStrings[0].Value.String, "abc");
            Assert.Equal(entrypoint.UpperCaseStrings[0], "ABC");
        }
示例#3
0
        public void ImportCompletedUsingSatisfyImportsOnce()
        {
            var container          = ContainerFactory.Create();
            CompositionBatch batch = new CompositionBatch();
            var entrypoint         = new UpperCaseStringComponent();
            var entrypointPart     = AttributedModelServices.CreatePart(entrypoint);

            batch.AddParts(new LowerCaseString("abc"));
            container.Compose(batch);
            container.SatisfyImportsOnce(entrypointPart);

            Assert.Equal(1, entrypoint.LowerCaseStrings.Count);
            Assert.Equal(1, entrypoint.ImportCompletedCallCount);
            Assert.Equal(1, entrypoint.UpperCaseStrings.Count);
            Assert.Equal("abc", entrypoint.LowerCaseStrings[0].Value.String);
            Assert.Equal("ABC", entrypoint.UpperCaseStrings[0]);

            batch = new CompositionBatch();
            batch.AddParts(new object());
            container.Compose(batch);
            container.SatisfyImportsOnce(entrypointPart);

            Assert.Equal(1, entrypoint.LowerCaseStrings.Count);
            Assert.Equal(1, entrypoint.ImportCompletedCallCount);
            Assert.Equal(1, entrypoint.UpperCaseStrings.Count);
            Assert.Equal("abc", entrypoint.LowerCaseStrings[0].Value.String);
            Assert.Equal("ABC", entrypoint.UpperCaseStrings[0]);

            batch.AddParts(new LowerCaseString("def"));
            container.Compose(batch);
            container.SatisfyImportsOnce(entrypointPart);

            Assert.Equal(2, entrypoint.LowerCaseStrings.Count);
            Assert.Equal(2, entrypoint.ImportCompletedCallCount);
            Assert.Equal(2, entrypoint.UpperCaseStrings.Count);
            Assert.Equal("abc", entrypoint.LowerCaseStrings[0].Value.String);
            Assert.Equal("ABC", entrypoint.UpperCaseStrings[0]);
            Assert.Equal("def", entrypoint.LowerCaseStrings[1].Value.String);
            Assert.Equal("DEF", entrypoint.UpperCaseStrings[1]);
        }
示例#4
0
        public void ImportCompletedWithRecomposing()
        {
            var container = ContainerFactory.Create(); 
            CompositionBatch batch = new CompositionBatch();
            var entrypoint = new UpperCaseStringComponent();

            batch.AddParts(new LowerCaseString("abc"), entrypoint);
            container.Compose(batch);

            Assert.AreEqual(entrypoint.LowerCaseStrings.Count, 1);
            Assert.AreEqual(entrypoint.ImportCompletedCallCount, 1);
            Assert.AreEqual(entrypoint.UpperCaseStrings.Count, 1);
            Assert.AreEqual(entrypoint.LowerCaseStrings[0].Value.String, "abc");
            Assert.AreEqual(entrypoint.UpperCaseStrings[0], "ABC");

            // Add another component to verify recomposing
            batch = new CompositionBatch();
            batch.AddParts(new LowerCaseString("def"));
            container.Compose(batch);

            Assert.AreEqual(entrypoint.LowerCaseStrings.Count, 2);
            Assert.AreEqual(entrypoint.ImportCompletedCallCount, 2);
            Assert.AreEqual(entrypoint.UpperCaseStrings.Count, 2);
            Assert.AreEqual(entrypoint.LowerCaseStrings[1].Value.String, "def");
            Assert.AreEqual(entrypoint.UpperCaseStrings[1], "DEF");

            // Verify that adding a random component doesn't cause
            // the OnImportsSatisfied to be called again.
            batch = new CompositionBatch();
            batch.AddParts(new object());
            container.Compose(batch);

            Assert.AreEqual(entrypoint.LowerCaseStrings.Count, 2);
            Assert.AreEqual(entrypoint.ImportCompletedCallCount, 2);
            Assert.AreEqual(entrypoint.UpperCaseStrings.Count, 2);
        }
示例#5
0
        public void ImportCompletedWithRecomposing()
        {
            var container          = ContainerFactory.Create();
            CompositionBatch batch = new CompositionBatch();
            var entrypoint         = new UpperCaseStringComponent();

            batch.AddParts(new LowerCaseString("abc"), entrypoint);
            container.Compose(batch);

            Assert.Equal(entrypoint.LowerCaseStrings.Count, 1);
            Assert.Equal(entrypoint.ImportCompletedCallCount, 1);
            Assert.Equal(entrypoint.UpperCaseStrings.Count, 1);
            Assert.Equal(entrypoint.LowerCaseStrings[0].Value.String, "abc");
            Assert.Equal(entrypoint.UpperCaseStrings[0], "ABC");

            // Add another component to verify recomposing
            batch = new CompositionBatch();
            batch.AddParts(new LowerCaseString("def"));
            container.Compose(batch);

            Assert.Equal(entrypoint.LowerCaseStrings.Count, 2);
            Assert.Equal(entrypoint.ImportCompletedCallCount, 2);
            Assert.Equal(entrypoint.UpperCaseStrings.Count, 2);
            Assert.Equal(entrypoint.LowerCaseStrings[1].Value.String, "def");
            Assert.Equal(entrypoint.UpperCaseStrings[1], "DEF");

            // Verify that adding a random component doesn't cause
            // the OnImportsSatisfied to be called again.
            batch = new CompositionBatch();
            batch.AddParts(new object());
            container.Compose(batch);

            Assert.Equal(entrypoint.LowerCaseStrings.Count, 2);
            Assert.Equal(entrypoint.ImportCompletedCallCount, 2);
            Assert.Equal(entrypoint.UpperCaseStrings.Count, 2);
        }
示例#6
0
        public void ImportCompletedUsingSatisfyImportsOnce()
        {
            var container = ContainerFactory.Create();
            CompositionBatch batch = new CompositionBatch();
            var entrypoint = new UpperCaseStringComponent();
            var entrypointPart = AttributedModelServices.CreatePart(entrypoint);

            batch.AddParts(new LowerCaseString("abc"));
            container.Compose(batch);
            container.SatisfyImportsOnce(entrypointPart);
            
            Assert.AreEqual(1, entrypoint.LowerCaseStrings.Count);
            Assert.AreEqual(1, entrypoint.ImportCompletedCallCount);
            Assert.AreEqual(1, entrypoint.UpperCaseStrings.Count);
            Assert.AreEqual("abc", entrypoint.LowerCaseStrings[0].Value.String);
            Assert.AreEqual("ABC", entrypoint.UpperCaseStrings[0]);

            batch = new CompositionBatch();
            batch.AddParts(new object());
            container.Compose(batch);
            container.SatisfyImportsOnce(entrypointPart);

            Assert.AreEqual(1, entrypoint.LowerCaseStrings.Count);
            Assert.AreEqual(1, entrypoint.ImportCompletedCallCount);
            Assert.AreEqual(1, entrypoint.UpperCaseStrings.Count);
            Assert.AreEqual("abc", entrypoint.LowerCaseStrings[0].Value.String);
            Assert.AreEqual("ABC", entrypoint.UpperCaseStrings[0]);
            
            batch.AddParts(new LowerCaseString("def"));
            container.Compose(batch);
            container.SatisfyImportsOnce(entrypointPart);
            
            Assert.AreEqual(2, entrypoint.LowerCaseStrings.Count);
            Assert.AreEqual(2, entrypoint.ImportCompletedCallCount);
            Assert.AreEqual(2, entrypoint.UpperCaseStrings.Count);
            Assert.AreEqual("abc", entrypoint.LowerCaseStrings[0].Value.String);
            Assert.AreEqual("ABC", entrypoint.UpperCaseStrings[0]);
            Assert.AreEqual("def", entrypoint.LowerCaseStrings[1].Value.String);
            Assert.AreEqual("DEF", entrypoint.UpperCaseStrings[1]);
        }