Skip to content

Add more datatypes to ProductsColumnTypes tests #635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jan 23, 2023
2 changes: 1 addition & 1 deletion samples/samples-python/.pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ file-header=# Copyright \(c\) Microsoft Corporation\. All rights reserved\.[\r\n
# can either give multiple identifier separated by comma (,) or put this option
# multiple time (only on the command line, not in the configuration file where
# it should appear only once).
disable= R0801, W0108, W0613, C0103, C0114, C0115, C0116, E0401, C0301
disable= R0801, W0108, W0613, C0103, C0114, C0115, C0116, E0401, C0301, R0913, R0914
11 changes: 0 additions & 11 deletions samples/samples-python/Common/productcolumntypes.py

This file was deleted.

20 changes: 19 additions & 1 deletion test-outofproc/AddProductColumnTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,26 @@ public static ProductColumnTypes Run(
var product = new ProductColumnTypes()
{
ProductId = int.Parse(queryStrings["productId"], null),
BigInt = int.MaxValue,
Bit = true,
DecimalType = 1.2345M,
Money = 1.23M,
Numeric = 1.2345M,
SmallInt = 0,
SmallMoney = 1.23M,
TinyInt = 1,
FloatType = 1.2,
Real = 1.2f,
Date = DateTime.UtcNow,
Datetime = new SqlDateTime(DateTime.UtcNow).Value,
Datetime2 = DateTime.UtcNow
Datetime2 = DateTime.UtcNow,
DatetimeOffset = DateTime.UtcNow,
SmallDatetime = new SqlDateTime(DateTime.UtcNow).Value,
Time = DateTime.UtcNow.TimeOfDay,
CharType = "test",
Varchar = "test",
Nchar = "\u2649",
Nvarchar = "\u2649",
};
return product;
}
Expand Down
46 changes: 45 additions & 1 deletion test-outofproc/Product.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,24 +93,68 @@ public static List<Product> GetNewProductsRandomized(int num, int cost)
return products;
}
}

public class ProductColumnTypes
{
public int ProductId { get; set; }

public long BigInt { get; set; }

public bool Bit { get; set; }

public decimal DecimalType { get; set; }

public decimal Money { get; set; }

public decimal Numeric { get; set; }

public short SmallInt { get; set; }

public decimal SmallMoney { get; set; }

public short TinyInt { get; set; }

public Double FloatType { get; set; }

public Single Real { get; set; }

public DateTime Date { get; set; }

public DateTime Datetime { get; set; }

public DateTime Datetime2 { get; set; }

public DateTimeOffset DatetimeOffset { get; set; }

public DateTime SmallDatetime { get; set; }

public TimeSpan Time { get; set; }

public string CharType { get; set; }

public string Varchar { get; set; }

public string Nchar { get; set; }

public string Nvarchar { get; set; }

public override bool Equals(object obj)
{
if (obj is ProductColumnTypes)
{
var that = obj as ProductColumnTypes;
return this.ProductId == that.ProductId && this.Datetime == that.Datetime && this.Datetime2 == that.Datetime2;
return this.ProductId == that.ProductId && this.BigInt == that.BigInt && this.Bit == that.Bit &&
this.DecimalType == that.DecimalType && this.Money == that.Money && this.Numeric == that.Numeric &&
this.SmallInt == that.SmallInt && this.SmallMoney == that.SmallMoney && this.TinyInt == that.TinyInt &&
this.FloatType == that.FloatType && this.Real == that.Real && this.Date == that.Date &&
this.Datetime == that.Datetime && this.Datetime2 == that.Datetime2 && this.DatetimeOffset == that.DatetimeOffset &&
this.SmallDatetime == that.SmallDatetime && this.Time == that.Time && this.CharType == that.CharType &&
this.Varchar == that.Varchar && this.Nchar == that.Nchar && this.Nvarchar == that.Nvarchar;
}
return false;
}
}

public class ProductExtraColumns
{
public int ProductId { get; set; }
Expand Down
49 changes: 48 additions & 1 deletion test/Common/ProductColumnTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,65 @@ public class ProductColumnTypes
{
public int ProductId { get; set; }

public long BigInt { get; set; }

public bool Bit { get; set; }

public decimal DecimalType { get; set; }

public decimal Money { get; set; }

public decimal Numeric { get; set; }

public short SmallInt { get; set; }

public decimal SmallMoney { get; set; }

public short TinyInt { get; set; }

public Double FloatType { get; set; }

public Single Real { get; set; }

public DateTime Date { get; set; }

public DateTime Datetime { get; set; }

public DateTime Datetime2 { get; set; }

public DateTimeOffset DatetimeOffset { get; set; }

public DateTime SmallDatetime { get; set; }

public TimeSpan Time { get; set; }

public string CharType { get; set; }

public string Varchar { get; set; }

public string Nchar { get; set; }

public string Nvarchar { get; set; }

public override bool Equals(object obj)
{
if (obj is ProductColumnTypes)
{
var that = obj as ProductColumnTypes;
return this.ProductId == that.ProductId && this.Datetime == that.Datetime && this.Datetime2 == that.Datetime2;
return this.ProductId == that.ProductId && this.BigInt == that.BigInt && this.Bit == that.Bit &&
this.DecimalType == that.DecimalType && this.Money == that.Money && this.Numeric == that.Numeric &&
this.SmallInt == that.SmallInt && this.SmallMoney == that.SmallMoney && this.TinyInt == that.TinyInt &&
this.FloatType == that.FloatType && this.Real == that.Real && this.Date == that.Date &&
this.Datetime == that.Datetime && this.Datetime2 == that.Datetime2 && this.DatetimeOffset == that.DatetimeOffset &&
this.SmallDatetime == that.SmallDatetime && this.Time == that.Time && this.CharType == that.CharType &&
this.Varchar == that.Varchar && this.Nchar == that.Nchar && this.Nvarchar == that.Nvarchar;
}
return false;
}

public override string ToString()
{
return $"[{this.ProductId}, {this.BigInt}, {this.Bit}, {this.DecimalType}, {this.Money}, {this.Numeric}, {this.SmallInt}, {this.SmallMoney}, {this.TinyInt}, {this.FloatType}, {this.Real}, {this.Date}, {this.Datetime}, {this.Datetime2}, {this.DatetimeOffset}, {this.SmallDatetime}, {this.Time}, {this.CharType}, {this.Varchar}, {this.Nchar}, {this.Nvarchar}]";
}
}
}
26 changes: 22 additions & 4 deletions test/Database/Tables/ProductsColumnTypes.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
CREATE TABLE [ProductsColumnTypes] (
[ProductId] [int] NOT NULL PRIMARY KEY,
[Datetime] [datetime],
[Datetime2] [datetime2]
)
[ProductId] [int] NOT NULL PRIMARY KEY,
[BigInt] [bigint],
[Bit] [bit],
[DecimalType] [decimal](18,4),
[Money] [money],
[Numeric] [numeric](18,4),
[SmallInt] [smallint],
[SmallMoney] [smallmoney],
[TinyInt] [tinyint],
[FloatType] [float],
[Real] [real],
[Date] [date],
[Datetime] [datetime],
[Datetime2] [datetime2],
[DatetimeOffset] [datetimeoffset],
[SmallDatetime] [smalldatetime],
[Time] [time],
[CharType] [char](4),
[Varchar] [varchar](100),
[Nchar] [nchar](4),
[Nvarchar] [nvarchar](100),
)
63 changes: 46 additions & 17 deletions test/Integration/SqlInputBindingIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,30 @@ public async void GetProductsColumnTypesSerializationAsyncEnumerableTest(string
this.StartFunctionHost(nameof(GetProductsColumnTypesSerializationAsyncEnumerable), lang, true);

string datetime = "2022-10-20 12:39:13.123";
ProductColumnTypes[] expectedResponse = new[]
{
new ProductColumnTypes()
{
ProductId = 999,
Datetime = DateTime.Parse(datetime),
Datetime2 = DateTime.Parse(datetime)
}
};
ProductColumnTypes[] expectedResponse = JsonConvert.DeserializeObject<ProductColumnTypes[]>("[{\"ProductId\":999,\"BigInt\":999,\"Bit\":false,\"DecimalType\":1.2345,\"Money\":1.2345,\"Numeric\":1.2345,\"SmallInt\":1,\"SmallMoney\":1.2345,\"TinyInt\":1,\"FloatType\":0.1,\"Real\":0.1,\"Date\":\"2022-10-20T00:00:00.000Z\",\"Datetime\":\"2022-10-20T12:39:13.123Z\",\"Datetime2\":\"2022-10-20T12:39:13.123Z\",\"DatetimeOffset\":\"2022-10-20T12:39:13.123Z\",\"SmallDatetime\":\"2022-10-20T12:39:00.000Z\",\"Time\":\"12:39:13.1230000\",\"CharType\":\"test\",\"Varchar\":\"test\",\"Nchar\":\"\uFFFD\u0020\u0020\u0020\",\"Nvarchar\":\"\uFFFD\"}]");

this.ExecuteNonQuery("INSERT INTO [dbo].[ProductsColumnTypes] VALUES (" +
"999, " + // ProductId
$"CONVERT(DATETIME, '{datetime}'), " + // Datetime field
$"CONVERT(DATETIME2, '{datetime}'))"); // Datetime2 field
"999, " + // ProductId,
"999, " + // BigInt
"0, " + // Bit
"1.2345, " + // DecimalType
"1.2345, " + // Money
"1.2345, " + // Numeric
"1, " + // SmallInt
"1.2345, " + // SmallMoney
"1, " + // TinyInt
".1, " + // FloatType
".1, " + // Real
$"CONVERT(DATE, '{datetime}'), " + // Date
$"CONVERT(DATETIME, '{datetime}'), " + // Datetime
$"CONVERT(DATETIME2, '{datetime}'), " + // Datetime2
$"CONVERT(DATETIMEOFFSET, '{datetime}'), " + // DatetimeOffset
$"CONVERT(SMALLDATETIME, '{datetime}'), " + // SmallDatetime
$"CONVERT(TIME, '{datetime}'), " + // Time
"'test', " + // CharType
"'test', " + // Varchar
"NCHAR(0xD84C), " + // Nchar
"NCHAR(0xD84C))"); // Nvarchar

HttpResponseMessage response = await this.SendInputRequest("getproducts-columntypesserializationasyncenumerable", $"?culture={culture}");
// We expect the datetime and datetime2 fields to be returned in UTC format
Expand All @@ -175,13 +186,31 @@ public async void GetProductsColumnTypesSerializationTest(SupportedLanguages lan

string datetime = "2022-10-20 12:39:13.123";
this.ExecuteNonQuery("INSERT INTO [dbo].[ProductsColumnTypes] VALUES (" +
"999, " + // ProductId
$"CONVERT(DATETIME, '{datetime}'), " + // Datetime field
$"CONVERT(DATETIME2, '{datetime}'))"); // Datetime2 field
"999, " + // ProductId,
"999, " + // BigInt
"0, " + // Bit
"1.2345, " + // DecimalType
"1.2345, " + // Money
"1.2345, " + // Numeric
"1, " + // SmallInt
"1.2345, " + // SmallMoney
"1, " + // TinyInt
".1, " + // FloatType
".1, " + // Real
$"CONVERT(DATE, '{datetime}'), " + // Date
$"CONVERT(DATETIME, '{datetime}'), " + // Datetime
$"CONVERT(DATETIME2, '{datetime}'), " + // Datetime2
$"CONVERT(DATETIMEOFFSET, '{datetime}'), " + // DatetimeOffset
$"CONVERT(SMALLDATETIME, '{datetime}'), " + // SmallDatetime
$"CONVERT(TIME, '{datetime}'), " + // Time
"'test', " + // CharType
"'test', " + // Varchar
"NCHAR(0xD84C), " + // Nchar
"NCHAR(0xD84C))"); // Nvarchar

HttpResponseMessage response = await this.SendInputRequest("getproducts-columntypesserialization");
// We expect the datetime and datetime2 fields to be returned in UTC format
ProductColumnTypes[] expectedResponse = JsonConvert.DeserializeObject<ProductColumnTypes[]>("[{\"ProductId\":999,\"Datetime\":\"2022-10-20T12:39:13.123Z\",\"Datetime2\":\"2022-10-20T12:39:13.123Z\"}]");
// We expect the date fields to be returned in UTC format
ProductColumnTypes[] expectedResponse = JsonConvert.DeserializeObject<ProductColumnTypes[]>("[{\"ProductId\":999,\"BigInt\":999,\"Bit\":false,\"DecimalType\":1.2345,\"Money\":1.2345,\"Numeric\":1.2345,\"SmallInt\":1,\"SmallMoney\":1.2345,\"TinyInt\":1,\"FloatType\":0.1,\"Real\":0.1,\"Date\":\"2022-10-20T00:00:00.000Z\",\"Datetime\":\"2022-10-20T12:39:13.123Z\",\"Datetime2\":\"2022-10-20T12:39:13.123Z\",\"DatetimeOffset\":\"2022-10-20T12:39:13.123Z\",\"SmallDatetime\":\"2022-10-20T12:39:00.000Z\",\"Time\":\"12:39:13.1230000\",\"CharType\":\"test\",\"Varchar\":\"test\",\"Nchar\":\"\uFFFD\u0020\u0020\u0020\",\"Nvarchar\":\"\uFFFD\"}]");
string actualResponse = await response.Content.ReadAsStringAsync();
ProductColumnTypes[] actualProductResponse = JsonConvert.DeserializeObject<ProductColumnTypes[]>(actualResponse);

Expand Down
1 change: 1 addition & 0 deletions test/Integration/SqlOutputBindingIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public void AddProductArrayTest(SupportedLanguages lang)
/// <param name="lang">The language to run the test against</param>
[Theory]
[SqlInlineData()]
// Tracking issue here: https://github.com/Azure/azure-functions-sql-extension/issues/521
[UnsupportedLanguages(SupportedLanguages.Java)]
public void AddProductColumnTypesTest(SupportedLanguages lang)
{
Expand Down
24 changes: 21 additions & 3 deletions test/Integration/test-csharp/AddProductColumnTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static class AddProductColumnTypes
{
/// <summary>
/// This function is used to test compatability with converting various data types to their respective
/// SQL server types.
/// SQL server types.
/// </summary>
[FunctionName(nameof(AddProductColumnTypes))]
public static IActionResult Run(
Expand All @@ -23,8 +23,26 @@ public static IActionResult Run(
product = new ProductColumnTypes()
{
ProductId = int.Parse(req.Query["productId"]),
Datetime = DateTime.UtcNow,
Datetime2 = DateTime.UtcNow
BigInt = int.MaxValue,
Bit = true,
DecimalType = 1.2345M,
Money = 1.23M,
Numeric = 1.2345M,
SmallInt = 0,
SmallMoney = 1.23M,
TinyInt = 1,
FloatType = 1.2,
Real = 1.2f,
Date = DateTime.Now,
Datetime = DateTime.Now,
Datetime2 = DateTime.Now,
DatetimeOffset = DateTime.Now,
SmallDatetime = DateTime.Now,
Time = DateTime.Now.TimeOfDay,
CharType = "test",
Varchar = "test",
Nchar = "\u2649",
Nvarchar = "\u2649",
};

// Items were inserted successfully so return success, an exception would be thrown if there
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import com.microsoft.azure.functions.sql.annotation.SQLOutput;
import com.function.Common.ProductColumnTypes;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.sql.Time;
import java.util.Optional;

public class AddProductColumnTypes {
Expand All @@ -37,8 +39,26 @@ public HttpResponseMessage run(

ProductColumnTypes p = new ProductColumnTypes(
Integer.parseInt(request.getQueryParameters().get("productId")),
(long)999,
true,
new BigDecimal("1.2345"),
new BigDecimal("1.2345"),
new BigDecimal("1.2345"),
(short)1,
new BigDecimal("1.2345"),
(short)1,
0.1,
0.1,
new Timestamp(System.currentTimeMillis()),
new Timestamp(System.currentTimeMillis()));
new Timestamp(System.currentTimeMillis()),
new Timestamp(System.currentTimeMillis()),
new Timestamp(System.currentTimeMillis()),
new Timestamp(System.currentTimeMillis()),
new Time(System.currentTimeMillis()).toString(),
"test",
"test",
"\u2649",
"\u2649");
product.setValue(p);

// Items were inserted successfully so return success, an exception would be thrown if there
Expand Down
Loading