Skip to content

Commit a9788b8

Browse files
authored
Fix HasDefault syntax (#1039)
* fix syntax and add test * update test to catch errors * undo copy paste error * undo changes to AddProductWithIdentity_MissingPrimaryColumn * ad comment and update product defnition for other langs * use Integer for nullable int in Java * missed nullable int * csx miss
1 parent 856c045 commit a9788b8

File tree

9 files changed

+13
-11
lines changed

9 files changed

+13
-11
lines changed

samples/samples-csharp/Common/Product.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Microsoft.Azure.WebJobs.Extensions.Sql.Samples.Common
55
{
66
public class Product
77
{
8-
public int ProductId { get; set; }
8+
public int? ProductId { get; set; }
99

1010
public string Name { get; set; }
1111

samples/samples-csx/Common/product.csx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
public class Product
55
{
6-
public int ProductId { get; set; }
6+
public int? ProductId { get; set; }
77

88
public string Name { get; set; }
99

samples/samples-java/src/main/java/com/function/Common/Product.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
package com.function.Common;
88

99
public class Product {
10-
private int ProductId;
10+
private Integer ProductId;
1111
private String Name;
1212
private int Cost;
1313

samples/samples-outofproc/Product.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Microsoft.Azure.WebJobs.Extensions.Sql.SamplesOutOfProc.Common
66
{
77
public class Product
88
{
9-
public int ProductId { get; set; }
9+
public int? ProductId { get; set; }
1010

1111
public string Name { get; set; }
1212

src/SqlAsyncCollector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ public static string GetPrimaryKeysQuery(SqlObject table)
474474
ccu.{ColumnName},
475475
c.is_identity,
476476
case
477-
when isc.COLUMN_DEFAULT = NULL then 'false'
477+
when isc.COLUMN_DEFAULT IS NULL then 'false'
478478
else 'true'
479479
end as {HasDefault}
480480
FROM

test-outofproc/Product.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace DotnetIsolatedTests.Common
88
{
99
public class Product
1010
{
11-
public int ProductId { get; set; }
11+
public int? ProductId { get; set; }
1212

1313
public string Name { get; set; }
1414

test/Integration/SqlOutputBindingIntegrationTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,8 @@ public async Task AddProductWithDefaultPKTest(SupportedLanguages lang)
352352
await this.SendOutputPostRequest("addproductwithdefaultpk", Utils.JsonSerializeObject(product), TestUtils.GetPort(lang));
353353
await this.SendOutputPostRequest("addproductwithdefaultpk", Utils.JsonSerializeObject(product), TestUtils.GetPort(lang));
354354
Assert.Equal(2, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithDefaultPK"));
355+
// Should throw error when there is no default PK and the primary key is missing from the user object.
356+
Assert.Throws<AggregateException>(() => this.SendOutputPostRequest("addproduct", Utils.JsonSerializeObject(product), TestUtils.GetPort(lang)).Wait());
355357
}
356358

357359
/// <summary>

test/Integration/SqlTriggerBindingIntegrationTestBase.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ void MonitorOutputData(object sender, DataReceivedEventArgs e)
100100
Assert.Equal(operation, change.Operation); // Expected change operation
101101
Product product = change.Item;
102102
Assert.NotNull(product); // Product deserialized correctly
103-
Assert.Contains(product.ProductId, expectedIds); // We haven't seen this product ID yet, and it's one we expected to see
104-
expectedIds.Remove(product.ProductId);
105-
Assert.Equal(getName(product.ProductId), product.Name); // The product has the expected name
106-
Assert.Equal(getCost(product.ProductId), product.Cost); // The product has the expected cost
103+
Assert.Contains(product.ProductId.Value, expectedIds); // We haven't seen this product ID yet, and it's one we expected to see
104+
expectedIds.Remove(product.ProductId.Value);
105+
Assert.Equal(getName(product.ProductId.Value), product.Name); // The product has the expected name
106+
Assert.Equal(getCost(product.ProductId.Value), product.Cost); // The product has the expected cost
107107
}
108108
}
109109
catch (Exception ex)

test/Integration/test-csx/Common/Product.csx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33
public class Product
44
{
5-
public int ProductId { get; set; }
5+
public int? ProductId { get; set; }
66

77
public string Name { get; set; }
88

0 commit comments

Comments
 (0)