public void Can_add_type_mapped_parameter_by_property(bool nullable)
    {
        var typeMapper = new TestRelationalTypeMappingSource(
            TestServiceFactory.Instance.Create <TypeMappingSourceDependencies>(),
            TestServiceFactory.Instance.Create <RelationalTypeMappingSourceDependencies>());

        var modelBuilder = RelationalTestHelpers.Instance.CreateConventionBuilder();

        modelBuilder.Entity("MyType").Property <string>("MyProp").IsRequired(!nullable);

        var model = modelBuilder.FinalizeModel(designTime: false, skipValidation: true);

        var property = model.GetEntityTypes().Single().FindProperty("MyProp");

        var parameterBuilder = new RelationalCommandBuilder(
            new RelationalCommandBuilderDependencies(typeMapper, new ExceptionDetector()));

        parameterBuilder.AddParameter(
            "InvariantName",
            "Name",
            property.GetRelationalTypeMapping(),
            property.IsNullable);

        Assert.Equal(1, parameterBuilder.Parameters.Count);

        var parameter = parameterBuilder.Parameters[0] as TypeMappedRelationalParameter;

        Assert.NotNull(parameter);
        Assert.Equal("InvariantName", parameter.InvariantName);
        Assert.Equal("Name", parameter.Name);
        Assert.Equal(property.GetTypeMapping(), parameter.RelationalTypeMapping);
        Assert.Equal(nullable, parameter.IsNullable);
    }
    public void Can_add_type_mapped_parameter_by_type(bool nullable)
    {
        var typeMapper = (IRelationalTypeMappingSource) new TestRelationalTypeMappingSource(
            TestServiceFactory.Instance.Create <TypeMappingSourceDependencies>(),
            TestServiceFactory.Instance.Create <RelationalTypeMappingSourceDependencies>());
        var typeMapping = typeMapper.FindMapping(nullable ? typeof(int?) : typeof(int));

        var parameterBuilder = new RelationalCommandBuilder(
            new RelationalCommandBuilderDependencies(
                typeMapper,
                new ExceptionDetector()));

        parameterBuilder.AddParameter(
            "InvariantName",
            "Name",
            typeMapping,
            nullable);

        Assert.Equal(1, parameterBuilder.Parameters.Count);

        var parameter = parameterBuilder.Parameters[0] as TypeMappedRelationalParameter;

        Assert.NotNull(parameter);
        Assert.Equal("InvariantName", parameter.InvariantName);
        Assert.Equal("Name", parameter.Name);
        Assert.Equal(typeMapping, parameter.RelationalTypeMapping);
        Assert.Equal(nullable, parameter.IsNullable);
    }
Пример #3
0
        protected virtual void PopulateParameters(
            [NotNull] RelationalCommandBuilder commandBuilder,
            [NotNull] ColumnModification columnModification)
        {
            if (columnModification.ParameterName != null)
            {
                commandBuilder.AddParameter(
                    columnModification.ParameterName,
                    columnModification.Value,
                    columnModification.Property);
            }

            if (columnModification.OriginalParameterName != null)
            {
                commandBuilder.AddParameter(
                    columnModification.OriginalParameterName,
                    columnModification.OriginalValue,
                    columnModification.Property);
            }
        }
    public void Can_add_dynamic_parameter()
    {
        var typeMapper = new TestRelationalTypeMappingSource(
            TestServiceFactory.Instance.Create <TypeMappingSourceDependencies>(),
            TestServiceFactory.Instance.Create <RelationalTypeMappingSourceDependencies>());

        var parameterBuilder = new RelationalCommandBuilder(
            new RelationalCommandBuilderDependencies(
                typeMapper));

        parameterBuilder.AddParameter(
            "InvariantName",
            "Name");

        Assert.Equal(1, parameterBuilder.Parameters.Count);

        var parameter = parameterBuilder.Parameters[0] as DynamicRelationalParameter;

        Assert.NotNull(parameter);
        Assert.Equal("InvariantName", parameter.InvariantName);
        Assert.Equal("Name", parameter.Name);
    }