本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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"));
}
示例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);
}
示例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);
}
示例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));
}
示例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);
}
示例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));
}