本文整理汇总了C#中MockType.AsCollection方法的典型用法代码示例。如果您正苦于以下问题:C# MockType.AsCollection方法的具体用法?C# MockType.AsCollection怎么用?C# MockType.AsCollection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MockType
的用法示例。
在下文中一共展示了MockType.AsCollection方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Configure_should_uniquify_unconfigured_assocation_function_names
public void Configure_should_uniquify_unconfigured_assocation_function_names()
{
var typeA = new MockType("A");
var typeB = new MockType("B").Property(typeA.AsCollection(), "As");
var mockPropertyInfo = typeB.GetProperty("As");
typeA.Property(typeB.AsCollection(), "Bs");
var modelConfiguration = new ModelConfiguration();
var navigationPropertyConfiguration
= modelConfiguration.Entity(typeB).Navigation(mockPropertyInfo);
navigationPropertyConfiguration.ModificationFunctionsConfiguration
= new ModificationFunctionsConfiguration();
var modificationFunctionConfiguration = new ModificationFunctionConfiguration();
modificationFunctionConfiguration.HasName("M2M_Delete");
navigationPropertyConfiguration.ModificationFunctionsConfiguration
.Insert(modificationFunctionConfiguration);
var model = new EdmModel(DataSpace.CSpace);
var entityA = model.AddEntityType("A");
entityA.Annotations.SetClrType(typeA);
entityA.SetConfiguration(modelConfiguration.Entity(typeA));
var entityB = model.AddEntityType("B");
entityB.Annotations.SetClrType(typeB);
entityB.SetConfiguration(modelConfiguration.Entity(typeB));
model.AddEntitySet("AS", entityA);
model.AddEntitySet("BS", entityB);
var associationType
= model.AddAssociationType(
"M2M",
entityA,
RelationshipMultiplicity.Many,
entityB,
RelationshipMultiplicity.Many);
associationType.SetConfiguration(navigationPropertyConfiguration);
var navigationProperty
= entityB.AddNavigationProperty("As", associationType);
navigationProperty.SetClrPropertyInfo(mockPropertyInfo);
model.AddAssociationSet("M2MSet", associationType);
var databaseMapping
= new DatabaseMappingGenerator(ProviderRegistry.Sql2008_ProviderManifest)
.Generate(model);
modelConfiguration.Configure(databaseMapping, ProviderRegistry.Sql2008_ProviderManifest);
Assert.True(databaseMapping.Database.Functions.Any(f => f.Name == "M2M_Delete"));
Assert.True(databaseMapping.Database.Functions.Any(f => f.Name == "M2M_Delete1"));
}
示例2: Apply_finds_inverse_when_many_to_many
public void Apply_finds_inverse_when_many_to_many()
{
var mockTypeA = new MockType("A");
var mockTypeB = new MockType("B").Property(mockTypeA.AsCollection(), "As");
var mockPropertyInfo = mockTypeB.GetProperty("As");
mockTypeA.Property(mockTypeB.AsCollection(), "Bs");
var modelConfiguration = new ModelConfiguration();
new InversePropertyAttributeConvention()
.Apply(mockPropertyInfo, modelConfiguration, new InversePropertyAttribute("Bs"));
var navigationPropertyConfiguration
= modelConfiguration.Entity(mockTypeB).Navigation(mockPropertyInfo);
Assert.Same(mockTypeA.GetProperty("Bs"), navigationPropertyConfiguration.InverseNavigationProperty);
}
示例3: ComplexType_Containing_EntityCollection_Throws
public void ComplexType_Containing_EntityCollection_Throws()
{
MockType entityType = new MockType("EntityType");
MockType complexType =
new MockType("ComplexTypeWithEntityCollection")
.Property(entityType.AsCollection(), "CollectionProperty");
var modelBuilder = new ODataConventionModelBuilder();
modelBuilder.AddEntity(entityType);
modelBuilder.AddComplexType(complexType);
Assert.Throws<InvalidOperationException>(
() => modelBuilder.GetEdmModel(),
"The complex type 'DefaultNamespace.ComplexTypeWithEntityCollection' refers to the entity type 'DefaultNamespace.EntityType' through the property 'CollectionProperty'.");
}
示例4: ODataConventionModelBuilder_Sets_IsAddedExplicitly_Appropriately
public void ODataConventionModelBuilder_Sets_IsAddedExplicitly_Appropriately()
{
// Arrange
MockType relatedEntity =
new MockType("RelatedEntity")
.Property<int>("ID");
MockType relatedComplexType =
new MockType("RelatedComplexType");
MockType type =
new MockType()
.Property<int>("ID")
.Property<int>("ExplicitlyAddedPrimitive")
.Property<int>("InferredPrimitive")
.Property<int[]>("ExplicitlyAddedPrimitiveCollection")
.Property<int[]>("InferredAddedPrimitiveCollection")
.Property(relatedComplexType, "ExplicitlyAddedComplex")
.Property(relatedComplexType, "InferredComplex")
.Property(relatedComplexType.AsCollection(), "ExplicitlyAddedComplexCollection")
.Property(relatedComplexType.AsCollection(), "InferredComplexCollection")
.Property(relatedEntity, "ExplicitlyAddedNavigation")
.Property(relatedEntity, "InferredNavigation")
.Property(relatedEntity.AsCollection(), "ExplicitlyAddedNavigationCollection")
.Property(relatedEntity.AsCollection(), "InferredNavigationCollection");
var builder = new ODataConventionModelBuilder();
var entity = builder.AddEntity(type);
entity.AddProperty(type.GetProperty("ExplicitlyAddedPrimitive"));
entity.AddCollectionProperty(type.GetProperty("ExplicitlyAddedPrimitiveCollection"));
entity.AddComplexProperty(type.GetProperty("ExplicitlyAddedComplex"));
entity.AddCollectionProperty(type.GetProperty("ExplicitlyAddedComplexCollection"));
entity.AddNavigationProperty(type.GetProperty("ExplicitlyAddedNavigation"), EdmMultiplicity.ZeroOrOne);
entity.AddNavigationProperty(type.GetProperty("ExplicitlyAddedNavigationCollection"), EdmMultiplicity.Many);
builder.OnModelCreating = (b) =>
{
var explicitlyAddedProperties = entity.Properties.Where(p => p.Name.Contains("ExplicitlyAdded"));
var inferredProperties = entity.Properties.Where(p => p.Name.Contains("Inferred"));
Assert.Equal(13, entity.Properties.Count());
Assert.Equal(6, explicitlyAddedProperties.Count());
Assert.Equal(6, inferredProperties.Count());
foreach (var explicitlyAddedProperty in explicitlyAddedProperties)
{
Assert.True(explicitlyAddedProperty.AddedExplicitly);
}
foreach (var inferredProperty in inferredProperties)
{
Assert.False(inferredProperty.AddedExplicitly);
}
};
Assert.DoesNotThrow(() => builder.GetEdmModel());
}