public void Can_add_type_mapped_parameter_by_type(bool nullable)
        {
            var typeMapper = new FakeRelationalTypeMapper();

            var type = nullable
                ? typeof(int?)
                : typeof(int);

            var parameterBuilder = new RelationalParameterBuilder(typeMapper);

            parameterBuilder.AddParameter(
                "InvariantName",
                "Name",
                type,
                unicode: true);

            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(typeMapper.GetMapping(typeof(int)), parameter.RelationalTypeMapping);
            Assert.Equal(nullable, parameter.Nullable);
        }
        /// <summary>
        ///     This API supports the Entity Framework Core infrastructure and is not intended to be used 
        ///     directly from your code. This API may change or be removed in future releases.
        /// </summary>
        public RelationalCommandBuilder(
            [NotNull] ISensitiveDataLogger logger,
            [NotNull] DiagnosticSource diagnosticSource,
            [NotNull] IRelationalTypeMapper typeMapper)
        {
            Check.NotNull(logger, nameof(logger));
            Check.NotNull(diagnosticSource, nameof(diagnosticSource));
            Check.NotNull(typeMapper, nameof(typeMapper));

            _logger = logger;
            _diagnosticSource = diagnosticSource;
            ParameterBuilder = new RelationalParameterBuilder(typeMapper);
        }
        public void Can_add_dynamic_parameter()
        {
            var typeMapper = new FakeRelationalTypeMapper();

            var parameterBuilder = new RelationalParameterBuilder(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);
        }
        public void Can_add_type_mapped_parameter_by_property(bool nullable)
        {
            var typeMapper = new FakeRelationalTypeMapper();

            var property = new Model().AddEntityType("MyType").AddProperty("MyProp", typeof(string));
            property.IsNullable = nullable;

            var parameterBuilder = new RelationalParameterBuilder(typeMapper);

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

            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(typeMapper.GetMapping(property), parameter.RelationalTypeMapping);
            Assert.Equal(nullable, parameter.IsNullable);
        }
        /// <summary>
        ///     This API supports the Entity Framework Core infrastructure and is not intended to be used 
        ///     directly from your code. This API may change or be removed in future releases.
        /// </summary>
        public virtual void AddCompositeParameter(string invariantName, Action<IRelationalParameterBuilder> buildAction)
        {
            Check.NotEmpty(invariantName, nameof(invariantName));
            Check.NotNull(buildAction, nameof(buildAction));

            var innerList = new RelationalParameterBuilder(TypeMapper);

            buildAction(innerList);

            if (innerList.Parameters.Count > 0)
            {
                _parameters.Add(
                    new CompositeRelationalParameter(
                        invariantName,
                        innerList.Parameters));
            }
        }
        public void Can_add_composite_parameter()
        {
            var typeMapper = new FakeRelationalTypeMapper();

            var parameterBuilder = new RelationalParameterBuilder(typeMapper);

            parameterBuilder.AddCompositeParameter(
                "CompositeInvariant",
                builder =>
                    {
                        builder.AddParameter(
                            "FirstInvariant",
                            "FirstName",
                            new RelationalTypeMapping("int", typeof(int)),
                            nullable: false);

                        builder.AddParameter(
                            "SecondInvariant",
                            "SecondName",
                            new RelationalTypeMapping("nvarchae(max)", typeof(string)),
                            nullable: true);
                    });

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

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

            Assert.NotNull(parameter);
            Assert.Equal("CompositeInvariant", parameter.InvariantName);
            Assert.Equal(2, parameter.RelationalParameters.Count);
        }
        public void Does_not_add_empty_composite_parameter()
        {
            var typeMapper = new FakeRelationalTypeMapper();

            var parameterBuilder = new RelationalParameterBuilder(typeMapper);

            parameterBuilder.AddCompositeParameter(
                "CompositeInvariant",
                builder => { });

            Assert.Equal(0, parameterBuilder.Parameters.Count);
        }