From a9788b86ac5bffccf7077106e7810d13b08a279b Mon Sep 17 00:00:00 2001 From: Maddy <12754347+MaddyDev@users.noreply.github.com> Date: Tue, 6 Feb 2024 10:55:22 -0800 Subject: [PATCH] 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 --- samples/samples-csharp/Common/Product.cs | 2 +- samples/samples-csx/Common/product.csx | 2 +- .../src/main/java/com/function/Common/Product.java | 2 +- samples/samples-outofproc/Product.cs | 2 +- src/SqlAsyncCollector.cs | 2 +- test-outofproc/Product.cs | 2 +- test/Integration/SqlOutputBindingIntegrationTests.cs | 2 ++ test/Integration/SqlTriggerBindingIntegrationTestBase.cs | 8 ++++---- test/Integration/test-csx/Common/Product.csx | 2 +- 9 files changed, 13 insertions(+), 11 deletions(-) diff --git a/samples/samples-csharp/Common/Product.cs b/samples/samples-csharp/Common/Product.cs index cc56e53d5..1eefadc72 100644 --- a/samples/samples-csharp/Common/Product.cs +++ b/samples/samples-csharp/Common/Product.cs @@ -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; } diff --git a/samples/samples-csx/Common/product.csx b/samples/samples-csx/Common/product.csx index 0196a9fea..3aca0cad2 100644 --- a/samples/samples-csx/Common/product.csx +++ b/samples/samples-csx/Common/product.csx @@ -3,7 +3,7 @@ public class Product { - public int ProductId { get; set; } + public int? ProductId { get; set; } public string Name { get; set; } diff --git a/samples/samples-java/src/main/java/com/function/Common/Product.java b/samples/samples-java/src/main/java/com/function/Common/Product.java index 5990ebb49..1626e23ea 100644 --- a/samples/samples-java/src/main/java/com/function/Common/Product.java +++ b/samples/samples-java/src/main/java/com/function/Common/Product.java @@ -7,7 +7,7 @@ package com.function.Common; public class Product { - private int ProductId; + private Integer ProductId; private String Name; private int Cost; diff --git a/samples/samples-outofproc/Product.cs b/samples/samples-outofproc/Product.cs index ab5675f3d..5a14b16a8 100644 --- a/samples/samples-outofproc/Product.cs +++ b/samples/samples-outofproc/Product.cs @@ -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; } diff --git a/src/SqlAsyncCollector.cs b/src/SqlAsyncCollector.cs index 8232c86c0..145dee446 100644 --- a/src/SqlAsyncCollector.cs +++ b/src/SqlAsyncCollector.cs @@ -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 diff --git a/test-outofproc/Product.cs b/test-outofproc/Product.cs index 5901a5828..4395ce389 100644 --- a/test-outofproc/Product.cs +++ b/test-outofproc/Product.cs @@ -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; } diff --git a/test/Integration/SqlOutputBindingIntegrationTests.cs b/test/Integration/SqlOutputBindingIntegrationTests.cs index 27dbe35e1..9b1806ed0 100644 --- a/test/Integration/SqlOutputBindingIntegrationTests.cs +++ b/test/Integration/SqlOutputBindingIntegrationTests.cs @@ -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(() => this.SendOutputPostRequest("addproduct", Utils.JsonSerializeObject(product), TestUtils.GetPort(lang)).Wait()); } /// diff --git a/test/Integration/SqlTriggerBindingIntegrationTestBase.cs b/test/Integration/SqlTriggerBindingIntegrationTestBase.cs index 7db1b60ea..487a79a51 100644 --- a/test/Integration/SqlTriggerBindingIntegrationTestBase.cs +++ b/test/Integration/SqlTriggerBindingIntegrationTestBase.cs @@ -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) diff --git a/test/Integration/test-csx/Common/Product.csx b/test/Integration/test-csx/Common/Product.csx index c84985b96..71816bc1e 100644 --- a/test/Integration/test-csx/Common/Product.csx +++ b/test/Integration/test-csx/Common/Product.csx @@ -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; }