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


C# MockType类代码示例

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


MockType类属于命名空间,在下文中一共展示了MockType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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"));
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:60,代码来源:ModelConfigurationTests.cs

示例2: Apply_ignores_constraint_when_inverse_constraint_already_specified

        public void Apply_ignores_constraint_when_inverse_constraint_already_specified()
        {
            var mockTypeA = new MockType("A");
            var mockTypeB = new MockType("B").Property(mockTypeA, "A").Property<int>("AId1").Property<int>("AId2");
            mockTypeA.Property(mockTypeB, "B");

            var mockPropertyInfo = mockTypeA.GetProperty("B");
            var mockInversePropertyInfo = mockTypeB.GetProperty("A");

            var modelConfiguration = new ModelConfiguration();
            var navigationPropertyConfiguration
                = modelConfiguration.Entity(mockTypeA).Navigation(mockPropertyInfo);

            var inverseNavigationPropertyConfiguration
                = modelConfiguration.Entity(mockTypeB).Navigation(mockInversePropertyInfo);

            navigationPropertyConfiguration.InverseNavigationProperty = mockInversePropertyInfo;

            inverseNavigationPropertyConfiguration.Constraint
                = new ForeignKeyConstraintConfiguration(new[] { mockTypeB.GetProperty("AId1") });

            new ForeignKeyPrimitivePropertyAttributeConvention.ForeignKeyAttributeConventionImpl()
                .Apply(mockPropertyInfo, modelConfiguration, new ForeignKeyAttribute("AId2"));

            Assert.Null(navigationPropertyConfiguration.Constraint);
        }
开发者ID:junxy,项目名称:entityframework,代码行数:26,代码来源:ForeignKeyAttributeConventionTests.cs

示例3: Apply_SetsTimeSpanProperty_AsEdmTimeOfDay

        public void Apply_SetsTimeSpanProperty_AsEdmTimeOfDay(string typeName, bool expect)
        {
            // Arrange
            MockType type = new MockType("Customer")
                .Property(typeof(TimeSpan), "CreatedTime", new[] {new ColumnAttribute {TypeName = typeName}});

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

            PropertyInfo property = type.GetProperty("CreatedTime");
            Mock<PrimitivePropertyConfiguration> primitiveProperty = new Mock<PrimitivePropertyConfiguration>(property, structuralType.Object);
            primitiveProperty.Setup(p => p.RelatedClrType).Returns(typeof(TimeSpan));
            primitiveProperty.Object.AddedExplicitly = false;

            // Act
            new ColumnAttributeEdmPropertyConvention().Apply(primitiveProperty.Object, structuralType.Object,
                new ODataConventionModelBuilder());

            // Assert
            if (expect)
            {
                Assert.NotNull(primitiveProperty.Object.TargetEdmTypeKind);
                Assert.Equal(EdmPrimitiveTypeKind.TimeOfDay, primitiveProperty.Object.TargetEdmTypeKind);
            }
            else
            {
                Assert.Null(primitiveProperty.Object.TargetEdmTypeKind);
            }
        }
开发者ID:chinadragon0515,项目名称:WebApi,代码行数:29,代码来源:ColumnAttributeEdmPropertyConventionTest.cs

示例4: Ctor_ThrowsArgument_IfMultiplicityIsManyAndPropertyIsNotCollection

        public void Ctor_ThrowsArgument_IfMultiplicityIsManyAndPropertyIsNotCollection()
        {
            MockType mockEntity = new MockType().Property<int>("ID");

            Assert.Throws<ArgumentException>(
                () => new NavigationPropertyConfiguration(mockEntity.GetProperty("ID"), EdmMultiplicity.Many, new EntityTypeConfiguration()),
                "The property 'ID' on the type 'T' is being configured as a Many-to-Many navigation property. Many to Many navigation properties must be collections.\r\nParameter name: property");
        }
开发者ID:quentez,项目名称:aspnetwebstack,代码行数:8,代码来源:NavigationPropertyConfigurationTest.cs

示例5: Apply_should_ignore_type

        public void Apply_should_ignore_type()
        {
            var mockType = new MockType();
            var modelConfiguration = new ModelConfiguration();

            new NotMappedTypeAttributeConvention.NotMappedTypeAttributeConventionImpl()
                .Apply(mockType, modelConfiguration, new NotMappedAttribute());

            Assert.True(modelConfiguration.IsIgnoredType(mockType));
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:10,代码来源:NotMappedTypeAttributeConventionTests.cs

示例6: Apply_should_inline_type

        public void Apply_should_inline_type()
        {
            var mockType = new MockType();
            var modelConfiguration = new ModelConfiguration();

            new ComplexTypeAttributeConvention.ComplexTypeAttributeConventionImpl()
                .Apply(mockType, modelConfiguration, new ComplexTypeAttribute());

            Assert.True(modelConfiguration.IsComplexType(mockType));
        }
开发者ID:WangWilliam,项目名称:EntityFramework5,代码行数:10,代码来源:ComplexTypeAttributeConventionTests.cs

示例7: HasEntitySetName_evaluates_preconditions

        public void HasEntitySetName_evaluates_preconditions()
        {
            var type = new MockType();
            var innerConfig = new EntityTypeConfiguration(type);
            var config = new LightweightEntityConfiguration(type, () => innerConfig);

            var ex = Assert.Throws<ArgumentException>(
                () => config.HasEntitySetName(null));

            Assert.Equal(Strings.ArgumentIsNullOrWhitespace("entitySetName"), ex.Message);
        }
开发者ID:jwanagel,项目名称:jjwtest,代码行数:11,代码来源:LightweightEntityConfigurationTests.cs

示例8: HasEntitySetName_configures_when_unset

        public void HasEntitySetName_configures_when_unset()
        {
            var type = new MockType();
            var innerConfig = new EntityTypeConfiguration(type);
            var config = new LightweightEntityConfiguration(type, () => innerConfig);

            var result = config.HasEntitySetName("EntitySet1");

            Assert.Equal("EntitySet1", innerConfig.EntitySetName);
            Assert.Same(config, result);
        }
开发者ID:jwanagel,项目名称:jjwtest,代码行数:11,代码来源:LightweightEntityConfigurationTests.cs

示例9: MapComplexType_should_not_map_ignored_type

        public void MapComplexType_should_not_map_ignored_type()
        {
            var model = new EdmModel(DataSpace.CSpace);
            var mockModelConfiguration = new Mock<ModelConfiguration>();
            var typeMapper = new TypeMapper(new MappingContext(mockModelConfiguration.Object, new ConventionsConfiguration(), model));
            var mockType = new MockType("Foo");
            mockModelConfiguration.Setup(m => m.IsIgnoredType(mockType)).Returns(true);

            var complexType = typeMapper.MapComplexType(mockType);

            Assert.Null(complexType);
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:12,代码来源:TypeMapperTests.cs

示例10: GetConfiguredProperties_should_return_all_configured_properties

        public void GetConfiguredProperties_should_return_all_configured_properties()
        {
            var modelConfiguration = new ModelConfiguration();
            var mockType = new MockType();
            var mockPropertyInfo = new MockPropertyInfo(typeof(string), "S");

            Assert.False(modelConfiguration.GetConfiguredProperties(mockType).Any());

            modelConfiguration.Entity(mockType).Property(new PropertyPath(mockPropertyInfo));

            Assert.Same(mockPropertyInfo.Object, modelConfiguration.GetConfiguredProperties(mockType).Single());
        }
开发者ID:junxy,项目名称:entityframework,代码行数:12,代码来源:ModelConfigurationTests.cs

示例11: IsIgnoredProperty_should_return_true_if_property_is_ignored

        public void IsIgnoredProperty_should_return_true_if_property_is_ignored()
        {
            var modelConfiguration = new ModelConfiguration();
            var mockType = new MockType();
            var mockPropertyInfo = new MockPropertyInfo(typeof(string), "S");

            Assert.False(modelConfiguration.IsIgnoredProperty(mockType, mockPropertyInfo));

            modelConfiguration.Entity(mockType).Ignore(mockPropertyInfo);

            Assert.True(modelConfiguration.IsIgnoredProperty(mockType, mockPropertyInfo));
        }
开发者ID:junxy,项目名称:entityframework,代码行数:12,代码来源:ModelConfigurationTests.cs

示例12: Apply_does_not_invoke_action_when_single_predicate_false

        public void Apply_does_not_invoke_action_when_single_predicate_false()
        {
            var actionInvoked = false;
            var convention = new EntityConvention(
                new Func<Type, bool>[] { t => false },
                c => actionInvoked = true);
            var type = new MockType();
            var configuration = new EntityTypeConfiguration(type);

            convention.Apply(type, () => configuration);

            Assert.False(actionInvoked);
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:13,代码来源:EntityConventionTests.cs

示例13: Apply_invokes_action_when_no_predicates

        public void Apply_invokes_action_when_no_predicates()
        {
            var actionInvoked = false;
            var convention = new EntityConvention(
                Enumerable.Empty<Func<Type, bool>>(),
                c => actionInvoked = true);
            var type = new MockType();
            var configuration = new EntityTypeConfiguration(type);

            convention.Apply(type, () => configuration);

            Assert.True(actionInvoked);
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:13,代码来源:EntityConventionTests.cs

示例14: Invokes_action_when_single_predicate_true

            public void Invokes_action_when_single_predicate_true()
            {
                var actionInvoked = false;
                var convention = new TypeConvention(
                    new Func<Type, bool>[] { t => true },
                    c => actionInvoked = true);
                var type = new MockType();
                var configuration = new EntityTypeConfiguration(type);

                convention.Apply(type, () => configuration, new ModelConfiguration());

                Assert.True(actionInvoked);
            }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:13,代码来源:TypeConventionTests.cs

示例15: RequiredAttributeEdmPropertyConvention_ConfiguresRequiredPropertyAsRequired

        public void RequiredAttributeEdmPropertyConvention_ConfiguresRequiredPropertyAsRequired()
        {
            MockType type =
                new MockType("Entity")
                .Property(typeof(int), "ID")
                .Property(typeof(int?), "Count", new RequiredAttribute());

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

            IEdmModel model = builder.GetEdmModel();
            IEdmEntityType entity = model.AssertHasEntityType(type);
            entity.AssertHasPrimitiveProperty(model, "Count", EdmPrimitiveTypeKind.Int32, isNullable: false);
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:14,代码来源:RequiredAttributeEdmPropertyConventionTests.cs


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