Skip to content

Commit 6383b77

Browse files
Add default CommandType (#264)
* Add default CommandType * Tests
1 parent 65e80af commit 6383b77

File tree

5 files changed

+20
-13
lines changed

5 files changed

+20
-13
lines changed

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22
<ItemGroup>
33
<PackageVersion Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="5.0.0" />
4-
<PackageVersion Include="Microsoft.NET.Sdk.Functions" Version="3.0.13" />
4+
<PackageVersion Include="Microsoft.NET.Sdk.Functions" Version="3.1.1" />
55
<PackageVersion Include="Microsoft.ApplicationInsights" Version="2.17.0" />
66
<PackageVersion Include="Microsoft.Azure.WebJobs" Version="3.0.31" />
77
<PackageVersion Include="Microsoft.Data.SqlClient" Version="3.0.1" />

samples/samples-csharp/packages.lock.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
},
1515
"Microsoft.NET.Sdk.Functions": {
1616
"type": "Direct",
17-
"requested": "[3.0.13, )",
18-
"resolved": "3.0.13",
19-
"contentHash": "8BEt6I6OLm7fo9bh8VGI7Mkc7xs/vI/KDira8MQcfZIA+K+lmDRb2PAL/+728eYfXI4SVrGs4MLhUZvKtpWfvQ==",
17+
"requested": "[3.1.1, )",
18+
"resolved": "3.1.1",
19+
"contentHash": "sPPLAjDYroeuIDKwff5B1XrwvGzJm9K9GabXurmfpaXa3M4POy7ngLcG5mm+2pwjTA7e870pIjt1N2DqVQS4yA==",
2020
"dependencies": {
2121
"Microsoft.Azure.Functions.Analyzers": "[1.0.0, 2.0.0)",
2222
"Microsoft.Azure.WebJobs": "[3.0.23, 3.1.0)",

src/SqlAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public SqlAttribute(string commandText)
4747
/// Specifies whether <see cref="CommandText"/> refers to a stored procedure or SQL query string.
4848
/// Use <see cref="CommandType.StoredProcedure"/> for the former, <see cref="CommandType.Text"/> for the latter
4949
/// </summary>
50-
public CommandType CommandType { get; set; }
50+
public CommandType CommandType { get; set; } = CommandType.Text;
5151

5252
/// <summary>
5353
/// Specifies the parameters that will be used to execute the SQL query or stored procedure specified in <see cref="CommandText"/>.

test/Unit/SqlInputBindingTests.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,18 @@ public void TestInvalidCommandType()
9595
CommandType = System.Data.CommandType.TableDirect
9696
};
9797
Assert.Throws<ArgumentException>(() => SqlBindingUtilities.BuildCommand(attribute, null));
98+
}
9899

100+
[Fact]
101+
public void TestDefaultCommandType()
102+
{
103+
string query = "select * from Products";
104+
var attribute = new SqlAttribute(query);
105+
SqlCommand command = SqlBindingUtilities.BuildCommand(attribute, null);
106+
// CommandType should default to Text
107+
Assert.Equal(System.Data.CommandType.Text, command.CommandType);
108+
Assert.Equal(query, command.CommandText);
99109

100-
// Don't specify a type at all
101-
attribute = new SqlAttribute("");
102-
Assert.Throws<ArgumentException>(() => SqlBindingUtilities.BuildCommand(attribute, null));
103110
}
104111

105112
[Fact]

test/packages.lock.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
".NETCoreApp,Version=v3.1": {
55
"Microsoft.NET.Sdk.Functions": {
66
"type": "Direct",
7-
"requested": "[3.0.13, )",
8-
"resolved": "3.0.13",
9-
"contentHash": "8BEt6I6OLm7fo9bh8VGI7Mkc7xs/vI/KDira8MQcfZIA+K+lmDRb2PAL/+728eYfXI4SVrGs4MLhUZvKtpWfvQ==",
7+
"requested": "[3.1.1, )",
8+
"resolved": "3.1.1",
9+
"contentHash": "sPPLAjDYroeuIDKwff5B1XrwvGzJm9K9GabXurmfpaXa3M4POy7ngLcG5mm+2pwjTA7e870pIjt1N2DqVQS4yA==",
1010
"dependencies": {
1111
"Microsoft.Azure.Functions.Analyzers": "[1.0.0, 2.0.0)",
1212
"Microsoft.Azure.WebJobs": "[3.0.23, 3.1.0)",
@@ -1938,9 +1938,9 @@
19381938
"microsoft.azure.webjobs.extensions.sql.samples": {
19391939
"type": "Project",
19401940
"dependencies": {
1941-
"Microsoft.Azure.WebJobs.Extensions.Sql": "1.0.0",
1941+
"Microsoft.Azure.WebJobs.Extensions.Sql": "99.99.99",
19421942
"Microsoft.Azure.WebJobs.Extensions.Storage": "5.0.0",
1943-
"Microsoft.NET.Sdk.Functions": "3.0.13"
1943+
"Microsoft.NET.Sdk.Functions": "3.1.1"
19441944
}
19451945
},
19461946
"Microsoft.ApplicationInsights": {

0 commit comments

Comments
 (0)