Skip to content

Commit

Permalink
Fix HasDefault syntax (#1039)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
MaddyDev authored Feb 6, 2024
1 parent 856c045 commit a9788b8
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion samples/samples-csharp/Common/Product.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Microsoft.Azure.WebJobs.Extensions.Sql.Samples.Common
{
public class Product
{
public int ProductId { get; set; }
public int? ProductId { get; set; }

public string Name { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion samples/samples-csx/Common/product.csx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

public class Product
{
public int ProductId { get; set; }
public int? ProductId { get; set; }

public string Name { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
package com.function.Common;

public class Product {
private int ProductId;
private Integer ProductId;
private String Name;
private int Cost;

Expand Down
2 changes: 1 addition & 1 deletion samples/samples-outofproc/Product.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Microsoft.Azure.WebJobs.Extensions.Sql.SamplesOutOfProc.Common
{
public class Product
{
public int ProductId { get; set; }
public int? ProductId { get; set; }

public string Name { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion src/SqlAsyncCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ public static string GetPrimaryKeysQuery(SqlObject table)
ccu.{ColumnName},
c.is_identity,
case
when isc.COLUMN_DEFAULT = NULL then 'false'
when isc.COLUMN_DEFAULT IS NULL then 'false'
else 'true'
end as {HasDefault}
FROM
Expand Down
2 changes: 1 addition & 1 deletion test-outofproc/Product.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace DotnetIsolatedTests.Common
{
public class Product
{
public int ProductId { get; set; }
public int? ProductId { get; set; }

public string Name { get; set; }

Expand Down
2 changes: 2 additions & 0 deletions test/Integration/SqlOutputBindingIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ public async Task AddProductWithDefaultPKTest(SupportedLanguages lang)
await this.SendOutputPostRequest("addproductwithdefaultpk", Utils.JsonSerializeObject(product), TestUtils.GetPort(lang));
await this.SendOutputPostRequest("addproductwithdefaultpk", Utils.JsonSerializeObject(product), TestUtils.GetPort(lang));
Assert.Equal(2, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithDefaultPK"));
// Should throw error when there is no default PK and the primary key is missing from the user object.
Assert.Throws<AggregateException>(() => this.SendOutputPostRequest("addproduct", Utils.JsonSerializeObject(product), TestUtils.GetPort(lang)).Wait());
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions test/Integration/SqlTriggerBindingIntegrationTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ void MonitorOutputData(object sender, DataReceivedEventArgs e)
Assert.Equal(operation, change.Operation); // Expected change operation
Product product = change.Item;
Assert.NotNull(product); // Product deserialized correctly
Assert.Contains(product.ProductId, expectedIds); // We haven't seen this product ID yet, and it's one we expected to see
expectedIds.Remove(product.ProductId);
Assert.Equal(getName(product.ProductId), product.Name); // The product has the expected name
Assert.Equal(getCost(product.ProductId), product.Cost); // The product has the expected cost
Assert.Contains(product.ProductId.Value, expectedIds); // We haven't seen this product ID yet, and it's one we expected to see
expectedIds.Remove(product.ProductId.Value);
Assert.Equal(getName(product.ProductId.Value), product.Name); // The product has the expected name
Assert.Equal(getCost(product.ProductId.Value), product.Cost); // The product has the expected cost
}
}
catch (Exception ex)
Expand Down
2 changes: 1 addition & 1 deletion test/Integration/test-csx/Common/Product.csx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License. See License.txt in the project root for license information.
public class Product
{
public int ProductId { get; set; }
public int? ProductId { get; set; }

public string Name { get; set; }

Expand Down

0 comments on commit a9788b8

Please sign in to comment.