Beispiel #1
0
        public void CreatePart()
        {
            Type        expectedType     = typeof(TestPart);
            Lazy <Type> expectedLazyType = expectedType.AsLazy();
            IDictionary <string, object> expectedMetadata = new Dictionary <string, object>();

            expectedMetadata["Key1"] = 1;
            expectedMetadata["Key2"] = "Value2";

            IEnumerable <ImportDefinition> expectedImports = CreateImports(expectedType);
            IEnumerable <ExportDefinition> expectedExports = CreateExports(expectedType);

            ICompositionElement expectedOrigin = new MockOrigin();

            ReflectionComposablePartDefinition definition = CreateReflectionPartDefinition(
                expectedLazyType,
                false,
                () => expectedImports,
                () => expectedExports,
                expectedMetadata,
                expectedOrigin);

            var part = definition.CreatePart();

            Assert.NotNull(part);
            Assert.False(part is IDisposable);
        }
Beispiel #2
0
        public void CreatePart_DoesntLoadType()
        {
            Type        expectedType     = typeof(TestPart);
            Lazy <Type> expectedLazyType = new Lazy <Type>(() => { throw new NotImplementedException(); /*"Part should not be loaded" */ });
            IDictionary <string, object> expectedMetadata = new Dictionary <string, object>();

            expectedMetadata["Key1"] = 1;
            expectedMetadata["Key2"] = "Value2";

            IEnumerable <ImportDefinition> expectedImports = CreateImports(expectedType);
            IEnumerable <ExportDefinition> expectedExports = CreateExports(expectedType);

            ICompositionElement expectedOrigin = new MockOrigin();

            ReflectionComposablePartDefinition definition = CreateReflectionPartDefinition(
                expectedLazyType,
                true,
                () => expectedImports,
                () => expectedExports,
                expectedMetadata,
                expectedOrigin);

            var part = definition.CreatePart();

            Assert.NotNull(part);
            Assert.True(part is IDisposable);
        }