Esempio n. 1
0
 public static IEnumerable <ReflectionComposablePartDefinition> GetAttributedDefinitions()
 {
     foreach (var type in GetAttributedTypes())
     {
         yield return(PartDefinitionFactory.CreateAttributed(type));
     }
 }
 public void Constructor2_ValueTypeAsAttributedPartArgument_ShouldThrowArgument()
 {
     Assert.Throws <ArgumentException>("attributedPart", () =>
     {
         new ReflectionComposablePart(PartDefinitionFactory.CreateAttributed(), 42);
     });
 }
 public void Constructor2_NullAsAttributedPartArgument_ShouldThrowArgumentNull()
 {
     Assert.Throws <ArgumentNullException>("attributedPart", () =>
     {
         new ReflectionComposablePart(PartDefinitionFactory.CreateAttributed(), (object)null);
     });
 }
Esempio n. 4
0
        public void SetDefinition_PartDefinitionDoesNotContainCreationPolicy_CreationPolicyShouldNotBeInMetadata()
        {
            var expectedPartDefinition = PartDefinitionFactory.CreateAttributed(typeof(object));
            var exportDefinition       = CreateReflectionExportDefinition(new LazyMemberInfo(this.GetType()), "ContractName", null);

            Assert.False(exportDefinition.Metadata.ContainsKey(CompositionConstants.PartCreationPolicyMetadataName));
        }
Esempio n. 5
0
        public void SetDefinition_OriginIsSet()
        {
            var expectedPartDefinition = PartDefinitionFactory.CreateAttributed(typeof(object));
            var exportDefinition       = CreateReflectionExportDefinition(new LazyMemberInfo(this.GetType()), "ContractName", null, expectedPartDefinition);

            Assert.Same(expectedPartDefinition, ((ICompositionElement)exportDefinition).Origin);
        }
        public void SetDefinition_OriginIsSet()
        {
            LazyMemberInfo member = CreateLazyMemberInfo();
            var            expectedPartDefinition       = PartDefinitionFactory.CreateAttributed(typeof(object));
            ReflectionMemberImportDefinition definition = new ReflectionMemberImportDefinition(
                member, "Contract", (string)null, null, ImportCardinality.ZeroOrMore, true, false, CreationPolicy.NonShared, null, expectedPartDefinition);

            Assert.Same(expectedPartDefinition, ((ICompositionElement)definition).Origin);
        }
        public void Constructor1_AttributedComposablePartDefintion_Disposable_ShouldProduceValidObject()
        {
            var definition = PartDefinitionFactory.CreateAttributed(typeof(DisposablePart));
            var part       = new DisposableReflectionComposablePart(definition);

            Assert.Equal(definition, part.Definition);
            Assert.NotNull(part.Metadata);

            Assert.True(part is IDisposable);
        }
        public void ExportOnAbstractBase_DoesNotReturnNull()
        {   // 499393 - Classes inheriting from an exported
            // abstract class are exported as 'null'

            var container          = ContainerFactory.Create();
            CompositionBatch batch = new CompositionBatch();

            var definition = PartDefinitionFactory.CreateAttributed(typeof(Derived));

            batch.AddPart(definition.CreatePart());
            container.Compose(batch);

            Assert.NotNull(container.GetExportedValueOrDefault <Base>());
        }
        private ReflectionComposablePart CreatePart(object instance)
        {
            if (instance is Type)
            {
                var definition = PartDefinitionFactory.CreateAttributed((Type)instance);

                return((ReflectionComposablePart)definition.CreatePart());
            }
            else
            {
                var definition = PartDefinitionFactory.CreateAttributed(instance.GetType());

                return(new ReflectionComposablePart(definition, instance));
            }
        }
 public void Constructor1_Object_ShouldProduceValidObject()
 {
     var part = new ReflectionComposablePart(PartDefinitionFactory.CreateAttributed(typeof(MyExport)), new MyExport());
 }