Ejemplo n.º 1
0
        public void ShouldPadInParameters(int parameterCount, int expectedPaddingTo)
        {
            var parameters = new CommandParameterValues();

            parameters.Add("ids", Enumerable.Range(0, parameterCount).Select(i => "A"));
            var command = new SqlCommand($"SELECT * FROM [Table] WHERE [Id] IN @ids");

            parameters.ContributeTo(command, new TypeHandlerRegistry());

            var parameterListString = string.Join(", ", Enumerable.Range(0, expectedPaddingTo).Select(i => "@ids_" + (i + 1)));

            command.CommandText.Should().Be($"SELECT * FROM [Table] WHERE [Id] IN ({parameterListString})");
        }
Ejemplo n.º 2
0
        public void ShouldReplaceParametersAcrossLineBreaks()
        {
            var parameters = new CommandParameterValues();

            parameters.Add("someId", new[] { "id1", "id2" });
            parameters.Add("someIdentifier", "value");
            var command = new SqlCommand($"SELECT * FROM [Table]{Environment.NewLine}WHERE [Id] IN @someId{Environment.NewLine}AND [OtherId] = @someIdentifier");

            parameters.ContributeTo(command, new TypeHandlerRegistry());

            command.CommandText.Should().Be($"SELECT * FROM [Table]{Environment.NewLine}WHERE [Id] IN (@someId_1, @someId_2){Environment.NewLine}AND [OtherId] = @someIdentifier");
            command.Parameters["someId_1"].Value.Should().Be("id1");
            command.Parameters["someId_2"].Value.Should().Be("id2");
            command.Parameters["someIdentifier"].Value.Should().Be("value");
        }
Ejemplo n.º 3
0
        public void ShouldReplaceParametersWithExactMatchSpecialCharacters(string paramName)
        {
            var parameters = new CommandParameterValues();

            parameters.Add("someId", new[] { "id1", "id2" });
            parameters.Add(paramName, "value");
            var command = new SqlCommand($"SELECT * FROM [Table] WHERE [Id] IN @someId AND [OtherId] = @{paramName}");

            parameters.ContributeTo(command, new TypeHandlerRegistry());

            command.CommandText.Should().Be($"SELECT * FROM [Table] WHERE [Id] IN (@someId_1, @someId_2) AND [OtherId] = @{paramName}");
            command.Parameters["someId_1"].Value.Should().Be("id1");
            command.Parameters["someId_2"].Value.Should().Be("id2");
            command.Parameters[paramName].Value.Should().Be("value");
        }
Ejemplo n.º 4
0
        public void ShouldReplaceParametersWithExactMatchEndOfQuery()
        {
            var parameters = new CommandParameterValues();

            parameters.Add("someId", "value");
            parameters.Add("someIdentifier", new[] { "id1", "id2" });
            var command = new SqlCommand("SELECT * FROM [Table] WHERE [Id] = @someId AND [OtherId] IN @someIdentifier");

            parameters.ContributeTo(command, new TypeHandlerRegistry());

            command.CommandText.Should().Be("SELECT * FROM [Table] WHERE [Id] = @someId AND [OtherId] IN (@someIdentifier_1, @someIdentifier_2)");
            command.Parameters["someId"].Value.Should().Be("value");
            command.Parameters["someIdentifier_1"].Value.Should().Be("id1");
            command.Parameters["someIdentifier_2"].Value.Should().Be("id2");
        }
Ejemplo n.º 5
0
        public void ShouldUseMaxLengthsWhenAvailable()
        {
            var mapping = new Map();

            var parameters = new CommandParameterValues();

            parameters["FirstName"] = "Fred";
            parameters["LastName"]  = "Fred";

            var command = new SqlCommand($"SELECT BLAH BLAH");

            parameters.ContributeTo(command, new TypeHandlerRegistry(), ((IDocumentMap)mapping).Build());

            command.Parameters["FirstName"].Size.Should().Be(128);
            command.Parameters["LastName"].Size.Should().Be(256);
        }