当前位置: 首页>>代码示例>>C#>>正文


C# MockType.Setup方法代码示例

本文整理汇总了C#中MockType.Setup方法的典型用法代码示例。如果您正苦于以下问题:C# MockType.Setup方法的具体用法?C# MockType.Setup怎么用?C# MockType.Setup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MockType的用法示例。


在下文中一共展示了MockType.Setup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Apply_DoesnotSetRequiredProperty_IfTypeIsNotADataContract

        public void Apply_DoesnotSetRequiredProperty_IfTypeIsNotADataContract()
        {
            // Arrange
            MockType type =
                new MockType("Mocktype")
                .Property(typeof(string), "Property", new[] { new DataMemberAttribute { IsRequired = true } });
            type.Setup(t => t.GetCustomAttributes(It.IsAny<Type>(), It.IsAny<bool>())).Returns(new object[0]);

            PropertyInfo property = type.GetProperty("Property");
            Mock<StructuralTypeConfiguration> structuralType = new Mock<StructuralTypeConfiguration>();
            Mock<StructuralPropertyConfiguration> structuralProperty = new Mock<StructuralPropertyConfiguration>(property, structuralType.Object);
            structuralType.Setup(t => t.ClrType).Returns(type);

            // Act
            new DataMemberAttributeEdmPropertyConvention().Apply(structuralProperty.Object, structuralType.Object);

            // Assert
            Assert.True(structuralProperty.Object.OptionalProperty);
        }
开发者ID:Swethach,项目名称:aspnetwebstack,代码行数:19,代码来源:DataMemberAttributeEdmPropertyConventionTest.cs

示例2: Apply_SetsRequiredProperty

        public void Apply_SetsRequiredProperty()
        {
            // Arrange
            MockType type =
                new MockType("Mocktype")
                .Property(typeof(string), "Property", new[] { new DataMemberAttribute { IsRequired = true } });
            type.Setup(t => t.GetCustomAttributes(It.IsAny<Type>(), It.IsAny<bool>())).Returns(new[] { new DataContractAttribute() });

            Mock<StructuralTypeConfiguration> structuralType = new Mock<StructuralTypeConfiguration>();
            structuralType.Setup(t => t.ClrType).Returns(type);

            PropertyInfo property = type.GetProperty("Property");
            Mock<StructuralPropertyConfiguration> structuralProperty = new Mock<StructuralPropertyConfiguration>(property, structuralType.Object);
            structuralProperty.Object.AddedExplicitly = false;

            // Act
            new DataMemberAttributeEdmPropertyConvention().Apply(structuralProperty.Object, structuralType.Object, new ODataConventionModelBuilder());

            // Assert
            Assert.False(structuralProperty.Object.OptionalProperty);
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:21,代码来源:DataMemberAttributeEdmPropertyConventionTest.cs

示例3: PropertyFilter_rejects_enum_properties_if_V2_builder_version_is_used

        public void PropertyFilter_rejects_enum_properties_if_V2_builder_version_is_used()
        {
            var mockType = new MockType("BadType");
            mockType.Setup(m => m.IsEnum).Returns(true);

            var properties = new List<PropertyInfo>
                                 {
                                     new MockPropertyInfo(mockType, "EnumProp")
                                 };

            Assert.Equal(
                Strings.UnsupportedUseOfV3Type("BadType", "EnumProp"),
                Assert.Throws<NotSupportedException>(
                    () => new PropertyFilter(DbModelBuilderVersion.V4_1).ValidatePropertiesForModelVersion(mockType, properties)).Message);
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:15,代码来源:PropertyFilterTests.cs

示例4: PropertyFilter_validates_enum_types

        private void PropertyFilter_validates_enum_types(PropertyFilter filter)
        {
            var mockType = new MockType();
            mockType.Setup(m => m.IsEnum).Returns(true);

            var properties = new List<PropertyInfo>
                                 {
                                     new MockPropertyInfo(mockType, "EnumProp")
                                 };

            filter.ValidatePropertiesForModelVersion(mockType, properties);
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:12,代码来源:PropertyFilterTests.cs

示例5: DataMemberAttributeEdmPropertyConvention_ConfiguresRequiredDataMembersAsRequired

        public void DataMemberAttributeEdmPropertyConvention_ConfiguresRequiredDataMembersAsRequired()
        {
            MockType type =
                new MockType("Entity")
                .Property(typeof(int), "ID", new DataMemberAttribute())
                .Property(typeof(string), "Name", new DataMemberAttribute { IsRequired = true });
            type.Setup(t => t.GetCustomAttributes(It.IsAny<Type>(), It.IsAny<bool>())).Returns(new[] { new DataContractAttribute() });

            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            builder.AddEntity(type);

            IEdmModel model = builder.GetEdmModel();
            IEdmEntityType entity = model.AssertHasEntityType(type);
            entity.AssertHasKey(model, "ID", EdmPrimitiveTypeKind.Int32);
            entity.AssertHasPrimitiveProperty(model, "Name", EdmPrimitiveTypeKind.String, isNullable: false);
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:16,代码来源:DataMemberAttributeEdmPropertyConventionTest.cs

示例6: DerivedType_DataMemberRequired_IsHonored_IfDerivedtypeIsDataContract

        public void DerivedType_DataMemberRequired_IsHonored_IfDerivedtypeIsDataContract()
        {
            // Arrange
            MockType baseType = new MockType("BaseMocktype");
            baseType.Setup(t => t.GetCustomAttributes(It.IsAny<Type>(), It.IsAny<bool>())).Returns(new[] { new DataContractAttribute() });

            MockType derivedType =
                new MockType("DerivedMockType")
                .Property(typeof(int), "Property", new[] { new DataMemberAttribute { IsRequired = true } })
                .BaseType(baseType);

            PropertyInfo property = derivedType.GetProperty("Property");
            Mock<StructuralTypeConfiguration> structuralType = new Mock<StructuralTypeConfiguration>();
            Mock<StructuralPropertyConfiguration> structuralProperty = new Mock<StructuralPropertyConfiguration>(property, structuralType.Object);
            structuralType.Setup(t => t.ClrType).Returns(derivedType);

            // Act
            new DataMemberAttributeEdmPropertyConvention().Apply(structuralProperty.Object, structuralType.Object);

            // Assert
            Assert.False(structuralProperty.Object.OptionalProperty);
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:22,代码来源:DataMemberAttributeEdmPropertyConventionTest.cs

示例7: DataMemberAttributeEdmPropertyConvention_DoesnotOverwriteExistingConfiguration

        public void DataMemberAttributeEdmPropertyConvention_DoesnotOverwriteExistingConfiguration()
        {
            MockType type =
                new MockType("Entity")
                .Property(typeof(int), "ID", new DataMemberAttribute())
                .Property(typeof(int), "Count", new DataMemberAttribute { IsRequired = true });
            type.Setup(t => t.GetCustomAttributes(It.IsAny<Type>(), It.IsAny<bool>())).Returns(new[] { new DataContractAttribute() });

            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            builder.AddEntity(type).AddProperty(type.GetProperty("Count")).IsOptional();

            IEdmModel model = builder.GetEdmModel();
            IEdmEntityType entity = model.AssertHasEntityType(type);
            entity.AssertHasPrimitiveProperty(model, "Count", EdmPrimitiveTypeKind.Int32, isNullable: true);
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:15,代码来源:DataMemberAttributeEdmPropertyConventionTest.cs

示例8: DataMemberAttributeEdmPropertyConvention_ConfiguresNavigationDataMembers

        public void DataMemberAttributeEdmPropertyConvention_ConfiguresNavigationDataMembers(bool isRequired)
        {
            MockType relatedType =
                new MockType("RelatedEntity")
                .Property<int>("ID");
            MockType type =
                new MockType("Entity")
                .Property(typeof(int), "ID")
                .Property(relatedType, "RelatedEntity", new DataMemberAttribute { IsRequired = isRequired });
            type.Setup(t => t.GetCustomAttributes(It.IsAny<Type>(), It.IsAny<bool>())).Returns(new[] { new DataContractAttribute() });

            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            builder.AddEntity(type);

            IEdmModel model = builder.GetEdmModel();
            IEdmEntityType entity = model.AssertHasEntityType(type);
            entity.AssertHasKey(model, "ID", EdmPrimitiveTypeKind.Int32);
            entity.AssertHasNavigationProperty(model, "RelatedEntity", relatedType, isNullable: !isRequired, multiplicity: isRequired ? EdmMultiplicity.One : EdmMultiplicity.ZeroOrOne);
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:19,代码来源:DataMemberAttributeEdmPropertyConventionTest.cs

示例9: DataMemberAttributeEdmPropertyConvention_DerivedClassPropertyAliased_IfEnabled

        public void DataMemberAttributeEdmPropertyConvention_DerivedClassPropertyAliased_IfEnabled(string propertyAlias, bool modelAliasing)
        {
            // Arrange
            MockType baseType = new MockType("BaseMocktype")
                .Property<int>("ID");
            baseType.Setup(t => t.GetCustomAttributes(It.IsAny<Type>(), It.IsAny<bool>()))
                .Returns(new[] { new DataContractAttribute() });

            MockType relatedType =
                new MockType("RelatedEntity")
                .Property<int>("ID");

            MockType derivedType =
                new MockType("DerivedMockType")
                .Property(relatedType, "RelatedEntity", new DataMemberAttribute { Name = "AliasRelatedEntity" })
                .BaseType(baseType);
            derivedType.Setup(t => t.GetCustomAttributes(It.IsAny<Type>(), It.IsAny<bool>()))
                .Returns(new[] { new DataContractAttribute() });

            // Act
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder { ModelAliasingEnabled = modelAliasing };
            builder.AddEntityType(derivedType);
            IEdmModel model = builder.GetEdmModel();

            // Assert
            IEdmEntityType entity = model.AssertHasEntityType(derivedType);
            entity.AssertHasKey(model, "ID", EdmPrimitiveTypeKind.Int32);
            entity.AssertHasNavigationProperty(
                model,
                propertyAlias,
                relatedType,
                isNullable: true,
                multiplicity: EdmMultiplicity.ZeroOrOne);
        }
开发者ID:tlycken,项目名称:aspnetwebstack,代码行数:34,代码来源:DataMemberAttributeEdmPropertyConventionTest.cs

示例10: MapEnumType_should_create_enum_type_with_clr_type_name_and_add_to_model

        public void MapEnumType_should_create_enum_type_with_clr_type_name_and_add_to_model()
        {
            var model = new EdmModel(DataSpace.CSpace);
            var mockType = new MockType("Foo");

            mockType.SetupGet(t => t.IsEnum).Returns(true);
            mockType.Setup(t => t.GetEnumUnderlyingType()).Returns(typeof(int));
            mockType.Setup(t => t.GetEnumNames()).Returns(new string[] { });
            mockType.Setup(t => t.GetEnumValues()).Returns(new int[] { });

            var modelConfiguration = new ModelConfiguration();

            var typeMapper = new TypeMapper(new MappingContext(modelConfiguration, new ConventionsConfiguration(), model));

            var enumType = typeMapper.MapEnumType(mockType);

            Assert.NotNull(enumType);
            Assert.Same(enumType, model.GetEnumType("Foo"));
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:19,代码来源:TypeMapperTests.cs

示例11: MapEnumType_should_set_namespace_when_provided_via_model_configuration

        public void MapEnumType_should_set_namespace_when_provided_via_model_configuration()
        {
            var model = new EdmModel(DataSpace.CSpace);
            var mockType = new MockType("Foo");

            mockType.SetupGet(t => t.IsEnum).Returns(true);
            mockType.Setup(t => t.GetEnumUnderlyingType()).Returns(typeof(int));
            mockType.Setup(t => t.GetEnumNames()).Returns(new string[] { });
            mockType.Setup(t => t.GetEnumValues()).Returns(new int[] { });

            var modelConfiguration = new ModelConfiguration
                                         {
                                             ModelNamespace = "Bar"
                                         };

            var typeMapper = new TypeMapper(new MappingContext(modelConfiguration, new ConventionsConfiguration(), model));

            var enumType = typeMapper.MapEnumType(mockType);

            Assert.NotNull(enumType);
            Assert.Equal("Bar", enumType.NamespaceName);
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:22,代码来源:TypeMapperTests.cs

示例12: MapEnumType_should_should_throw_for_new_type_if_enum_type_with_same_simple_name_already_used

        public void MapEnumType_should_should_throw_for_new_type_if_enum_type_with_same_simple_name_already_used()
        {
            var model = new EdmModel(DataSpace.CSpace);

            var mockType1 = new MockType("Foo");
            var mockType2 = new MockType("Foo");

            mockType1.SetupGet(t => t.IsEnum).Returns(true);
            mockType1.Setup(t => t.GetEnumUnderlyingType()).Returns(typeof(int));
            mockType1.Setup(t => t.GetEnumNames()).Returns(new string[] { });
            mockType1.Setup(t => t.GetEnumValues()).Returns(new int[] { });
            mockType2.SetupGet(t => t.IsEnum).Returns(true);

            var typeMapper = new TypeMapper(new MappingContext(new ModelConfiguration(), new ConventionsConfiguration(), model));

            Assert.NotNull(typeMapper.MapEnumType(mockType1));

            Assert.Equal(
                Strings.SimpleNameCollision("Foo", "Foo", "Foo"),
                Assert.Throws<NotSupportedException>(() => typeMapper.MapEnumType(mockType2)).Message);
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:21,代码来源:TypeMapperTests.cs

示例13: MapEnumType_should_ignore_new_type_if_type_name_already_used

        public void MapEnumType_should_ignore_new_type_if_type_name_already_used()
        {
            var model = new EdmModel().Initialize();

            var mockType1 = new MockType("Foo");
            var mockType2 = new MockType("Foo");

            mockType1.SetupGet(t => t.IsEnum).Returns(true);
            mockType1.Setup(t => t.GetEnumUnderlyingType()).Returns(typeof(int));
            mockType1.Setup(t => t.GetEnumNames()).Returns(new string[] { });
            mockType1.Setup(t => t.GetEnumValues()).Returns(new int[] { });
            mockType2.SetupGet(t => t.IsEnum).Returns(true);

            var modelConfiguration = new ModelConfiguration();
            var typeMapper = new TypeMapper(new MappingContext(modelConfiguration, new ConventionsConfiguration(), model));

            Assert.NotNull(typeMapper.MapEnumType(mockType1));
            Assert.Null(typeMapper.MapEnumType(mockType2));
        }
开发者ID:WangWilliam,项目名称:EntityFramework5,代码行数:19,代码来源:TypeMapperTests.cs

示例14: Apply_AliasNotSet_NoPropertyAlias

        public void Apply_AliasNotSet_NoPropertyAlias(bool modelAliasing)
        {
            // Arrange
            ODataConventionModelBuilder modelBuilder = new ODataConventionModelBuilder() { ModelAliasingEnabled = modelAliasing };

            MockType type =
                new MockType("Mocktype")
                .Property(typeof(string), "Property", new[] { new DataMemberAttribute() });
            type.Setup(t => t.GetCustomAttributes(It.IsAny<Type>(), It.IsAny<bool>())).Returns(new[] { new DataContractAttribute() });

            Mock<StructuralTypeConfiguration> structuralType = new Mock<StructuralTypeConfiguration>();
            structuralType.Setup(t => t.ClrType).Returns(type);

            PropertyInfo property = type.GetProperty("Property");
            Mock<StructuralPropertyConfiguration> structuralProperty = new Mock<StructuralPropertyConfiguration>(property, structuralType.Object);
            structuralProperty.Object.AddedExplicitly = false;

            // Act
            new DataMemberAttributeEdmPropertyConvention().Apply(structuralProperty.Object, structuralType.Object, modelBuilder);

            // Assert
            Assert.Equal("Property", structuralProperty.Object.Name);
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:23,代码来源:DataMemberAttributeEdmPropertyConventionTest.cs

示例15: PropertyFilter_includes_enum_and_spatial_properties_if_V3_features_are_supported

        public void PropertyFilter_includes_enum_and_spatial_properties_if_V3_features_are_supported()
        {
            var mockType = new MockType();
            mockType.Setup(m => m.IsEnum).Returns(true);

            var properties = new PropertyInfo[]
                                 {
                                     new MockPropertyInfo(typeof(DbGeography), "Geography"),
                                     new MockPropertyInfo(typeof(DbGeometry), "Geometry"),
                                     new MockPropertyInfo(mockType, "EnumProp")
                                 };

            mockType.Setup(m => m.GetProperties(It.IsAny<BindingFlags>())).Returns(properties);

            var filteredProperties = new PropertyFilter().GetProperties(mockType, declaredOnly: false);

            properties.All(p => filteredProperties.Select(f => f.Name).Contains(p.Name));
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:18,代码来源:PropertyFilterTests.cs


注:本文中的MockType.Setup方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。