Ejemplo n.º 1
0
        public void Constructor1_ShouldSetContractNamePropertyToEmptyString()
        {
            var attribute = new ImportAttribute();

            Assert.Null(attribute.ContractName);
            Assert.Null(attribute.ContractType);
        }
Ejemplo n.º 2
0
        public void Constructor1_ShouldSetContractNamePropertyToEmptyString()
        {
            var attribute = new ImportAttribute();

            Assert.IsNull(attribute.ContractName);
            Assert.IsNull(attribute.ContractType);
        }
Ejemplo n.º 3
0
        public void Constructor4_NullAsContractTypeArgument_ShouldSetContractNamePropertyToEmptyString()
        {
            var attribute = new ImportAttribute((string)null, (Type)null);

            Assert.Null(attribute.ContractName);
            Assert.Null(attribute.ContractType);
        }
Ejemplo n.º 4
0
        public void Constructor4_NullAsContractTypeArgument_ShouldSetContractNamePropertyToEmptyString()
        {
            var attribute = new ImportAttribute((string)null, (Type)null);

            Assert.IsNull(attribute.ContractName);
            Assert.IsNull(attribute.ContractType);
        }
Ejemplo n.º 5
0
        public void AsContractName_AndContractType_SetsContractNameAndType()
        {
            var builder = new ConventionBuilder();

            builder.ForType <FooImpl>().ImportProperty((p) => p.IFooProperty, (c) => c.AsContractName("hey"));

            ImportAttribute importAtt = GetImportAttribute(builder);

            Assert.Equal("hey", importAtt.ContractName);
        }
Ejemplo n.º 6
0
        public void AsContractName_AndContractType_ComputeContractNameFromType()
        {
            var builder = new ConventionBuilder();

            builder.ForType <FooImpl>().ImportProperty((p) => p.IFooProperty, c => c.AsContractName(t => "Contract:" + t.FullName));

            ImportAttribute importAtt = GetImportAttribute(builder);

            Assert.Equal("Contract:" + typeof(IFoo).FullName, importAtt.ContractName);
        }
Ejemplo n.º 7
0
        public void Constructor2_ValueAsContractNameArgument_ShouldSetContractNameProperty()
        {
            var expectations = Expectations.GetContractNamesWithEmpty();

            foreach (var e in expectations)
            {
                var attribute = new ImportAttribute(e);

                Assert.AreEqual(e, attribute.ContractName);
            }
        }
Ejemplo n.º 8
0
        public void Constructor2_ValueAsContractNameArgument_ShouldSetContractNameProperty()
        {
            var expectations = Expectations.GetContractNamesWithEmpty();

            foreach (var e in expectations)
            {
                var attribute = new ImportAttribute(e);

                Assert.Equal(e, attribute.ContractName);
            }
        }
Ejemplo n.º 9
0
        public void AllowDefault_SetsAllowDefaultProperty()
        {
            var builder = new ConventionBuilder();

            builder.ForType <FooImpl>().ImportProperty((p) => p.IFooProperty, (c) => c.AllowDefault());

            ImportAttribute importAtt = GetImportAttribute(builder);

            Assert.True(importAtt.AllowDefault);
            Assert.Null(importAtt.ContractName);
        }
Ejemplo n.º 10
0
        public void AsContractName_SetsContractName()
        {
            var builder = new ConventionBuilder();

            builder.ForType <FooImpl>().ImportProperty((p) => p.IFooProperty, (c) => c.AsContractName("hey"));

            ImportAttribute importAtt = GetImportAttribute(builder);

            Assert.AreEqual("hey", importAtt.ContractName);
            Assert.IsFalse(importAtt.AllowDefault);
        }
Ejemplo n.º 11
0
        public void AsContractName_AndContractType_SetsContractNameAndType()
        {
            var builder = new ImportBuilder();

            builder.AsContractName("hey");
            builder.AsContractType(typeof(IFoo));

            ImportAttribute importAtt = GetImportAttribute(builder);

            Assert.AreEqual("hey", importAtt.ContractName);
            Assert.AreEqual(typeof(IFoo), importAtt.ContractType);
        }
Ejemplo n.º 12
0
        public void AllowRecomposition_ValueAsValueArgument_ShouldSetProperty()
        {
            var expectations = Expectations.GetBooleans();

            var attribute = new ImportAttribute();

            foreach (var e in expectations)
            {
                attribute.AllowRecomposition = e;
                Assert.Equal(e, attribute.AllowRecomposition);
            }
        }
Ejemplo n.º 13
0
        public void AllowRecomposition_SetsAllowRecompositionProperty()
        {
            var builder = new ImportBuilder();

            builder.AllowRecomposition();

            ImportAttribute importAtt = GetImportAttribute(builder);

            Assert.IsTrue(importAtt.AllowRecomposition);
            Assert.IsNull(importAtt.ContractType);
            Assert.IsNull(importAtt.ContractName);
        }
Ejemplo n.º 14
0
        public void AsContractName_SetsContractName()
        {
            var builder = new ImportBuilder();

            builder.AsContractName("hey");

            ImportAttribute importAtt = GetImportAttribute(builder);

            Assert.AreEqual("hey", importAtt.ContractName);
            Assert.IsFalse(importAtt.AllowDefault);
            Assert.IsFalse(importAtt.AllowRecomposition);
            Assert.IsNull(importAtt.ContractType);
        }
Ejemplo n.º 15
0
        public void RequiredCreationPolicy_SetsRequiredCreationPolicyProperty()
        {
            var builder = new ImportBuilder();

            builder.RequiredCreationPolicy(CreationPolicy.NonShared);

            ImportAttribute importAtt = GetImportAttribute(builder);

            Assert.AreEqual(CreationPolicy.NonShared, importAtt.RequiredCreationPolicy);
            Assert.IsFalse(importAtt.AllowDefault);
            Assert.IsFalse(importAtt.AllowRecomposition);
            Assert.IsNull(importAtt.ContractType);
            Assert.IsNull(importAtt.ContractName);
        }
Ejemplo n.º 16
0
Archivo: MEF.cs Proyecto: blqw/blqw.IOC
        /// <summary>
        /// 根据 <see cref="ImportAttribute" />,返回导入插件的描述信息
        /// </summary>
        /// <param name="import"> 导入描述 </param>
        /// <param name="memberType"> 属性或字段的类型 </param>
        /// <returns> </returns>
        private static ImportDefinitionImpl GetImportDefinition(ImportAttribute import, Type memberType)
        {
            if (import == null)
            {
                return null;
            }

            var name = import.ContractName ?? AttributedModelServices.GetTypeIdentity(import.ContractType ?? memberType);
            return new ImportDefinitionImpl(
                GetExpression(name, import.ContractType ?? memberType),
                import.ContractName,
                ImportCardinality.ZeroOrOne,
                false,
                true,
                null)
            {
                MemberType = memberType,
                ExportedType = memberType
            };
        }
Ejemplo n.º 17
0
        public void Constructor1_ShouldSetAllowDefaultPropertyToFalse()
        {
            var attribute = new ImportAttribute();

            Assert.False(attribute.AllowDefault);
        }
Ejemplo n.º 18
0
        public void AllowRecomposition_ValueAsValueArgument_ShouldSetProperty()
        {
            var expectations = Expectations.GetBooleans();

            var attribute = new ImportAttribute();

            foreach (var e in expectations)
            {
                attribute.AllowRecomposition = e;
                Assert.AreEqual(e, attribute.AllowRecomposition);
            }
        }
Ejemplo n.º 19
0
        public void Constructor2_ShouldSetAllowDefaultPropertyToFalse()
        {
            var attribute = new ImportAttribute("ContractName");

            Assert.IsFalse(attribute.AllowDefault);
        }
Ejemplo n.º 20
0
        public void Constructor3_ShouldSetAllowDefaultPropertyToFalse()
        {
            var attribute = new ImportAttribute(typeof(String));

            Assert.IsFalse(attribute.AllowDefault);
        }
Ejemplo n.º 21
0
        public void Constructor3_ShouldSetAllowRecompositionPropertyToFalse()
        {
            var attribute = new ImportAttribute(typeof(string));

            Assert.False(attribute.AllowRecomposition);
        }
Ejemplo n.º 22
0
        public void Constructor2_ShouldSetAllowRecompositionPropertyToFalse()
        {
            var attribute = new ImportAttribute("ContractName");

            Assert.False(attribute.AllowRecomposition);
        }
Ejemplo n.º 23
0
        public void Constructor1_ShouldSetAllowRecompositionPropertyToFalse()
        {
            var attribute = new ImportAttribute();

            Assert.IsFalse(attribute.AllowRecomposition);
        }
Ejemplo n.º 24
0
        public void Constructor2_ShouldSetAllowRecompositionPropertyToFalse()
        {
            var attribute = new ImportAttribute("ContractName");

            Assert.IsFalse(attribute.AllowRecomposition);
        }