Skip to content

Commit 7d3c98c

Browse files
authored
Add more datatypes to ProductsColumnTypes tests (Azure#635)
* get started on adding datatypes * Fix TIME in Java * fix java test * GetProductsColumnTypesSerializationAsyncEnumerable * add product column types test * fix linting * remove productcolumntypes in samples-python * cleanup * cleanup * add unicode * skip java addproductcolumntypestest * add unicode to java and python test * fix space
1 parent 29623ac commit 7d3c98c

File tree

16 files changed

+500
-53
lines changed

16 files changed

+500
-53
lines changed

samples/samples-python/.pylintrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ file-header=# Copyright \(c\) Microsoft Corporation\. All rights reserved\.[\r\n
1313
# can either give multiple identifier separated by comma (,) or put this option
1414
# multiple time (only on the command line, not in the configuration file where
1515
# it should appear only once).
16-
disable= R0801, W0108, W0613, C0103, C0114, C0115, C0116, E0401, C0301
16+
disable= R0801, W0108, W0613, C0103, C0114, C0115, C0116, E0401, C0301, R0913, R0914

samples/samples-python/Common/productcolumntypes.py

-11
This file was deleted.

test-outofproc/AddProductColumnTypes.cs

+19-1
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,26 @@ public static ProductColumnTypes Run(
2727
var product = new ProductColumnTypes()
2828
{
2929
ProductId = int.Parse(queryStrings["productId"], null),
30+
BigInt = int.MaxValue,
31+
Bit = true,
32+
DecimalType = 1.2345M,
33+
Money = 1.23M,
34+
Numeric = 1.2345M,
35+
SmallInt = 0,
36+
SmallMoney = 1.23M,
37+
TinyInt = 1,
38+
FloatType = 1.2,
39+
Real = 1.2f,
40+
Date = DateTime.UtcNow,
3041
Datetime = new SqlDateTime(DateTime.UtcNow).Value,
31-
Datetime2 = DateTime.UtcNow
42+
Datetime2 = DateTime.UtcNow,
43+
DatetimeOffset = DateTime.UtcNow,
44+
SmallDatetime = new SqlDateTime(DateTime.UtcNow).Value,
45+
Time = DateTime.UtcNow.TimeOfDay,
46+
CharType = "test",
47+
Varchar = "test",
48+
Nchar = "\u2649",
49+
Nvarchar = "\u2649",
3250
};
3351
return product;
3452
}

test-outofproc/Product.cs

+45-1
Original file line numberDiff line numberDiff line change
@@ -93,24 +93,68 @@ public static List<Product> GetNewProductsRandomized(int num, int cost)
9393
return products;
9494
}
9595
}
96+
9697
public class ProductColumnTypes
9798
{
9899
public int ProductId { get; set; }
99100

101+
public long BigInt { get; set; }
102+
103+
public bool Bit { get; set; }
104+
105+
public decimal DecimalType { get; set; }
106+
107+
public decimal Money { get; set; }
108+
109+
public decimal Numeric { get; set; }
110+
111+
public short SmallInt { get; set; }
112+
113+
public decimal SmallMoney { get; set; }
114+
115+
public short TinyInt { get; set; }
116+
117+
public Double FloatType { get; set; }
118+
119+
public Single Real { get; set; }
120+
121+
public DateTime Date { get; set; }
122+
100123
public DateTime Datetime { get; set; }
101124

102125
public DateTime Datetime2 { get; set; }
103126

127+
public DateTimeOffset DatetimeOffset { get; set; }
128+
129+
public DateTime SmallDatetime { get; set; }
130+
131+
public TimeSpan Time { get; set; }
132+
133+
public string CharType { get; set; }
134+
135+
public string Varchar { get; set; }
136+
137+
public string Nchar { get; set; }
138+
139+
public string Nvarchar { get; set; }
140+
104141
public override bool Equals(object obj)
105142
{
106143
if (obj is ProductColumnTypes)
107144
{
108145
var that = obj as ProductColumnTypes;
109-
return this.ProductId == that.ProductId && this.Datetime == that.Datetime && this.Datetime2 == that.Datetime2;
146+
return this.ProductId == that.ProductId && this.BigInt == that.BigInt && this.Bit == that.Bit &&
147+
this.DecimalType == that.DecimalType && this.Money == that.Money && this.Numeric == that.Numeric &&
148+
this.SmallInt == that.SmallInt && this.SmallMoney == that.SmallMoney && this.TinyInt == that.TinyInt &&
149+
this.FloatType == that.FloatType && this.Real == that.Real && this.Date == that.Date &&
150+
this.Datetime == that.Datetime && this.Datetime2 == that.Datetime2 && this.DatetimeOffset == that.DatetimeOffset &&
151+
this.SmallDatetime == that.SmallDatetime && this.Time == that.Time && this.CharType == that.CharType &&
152+
this.Varchar == that.Varchar && this.Nchar == that.Nchar && this.Nvarchar == that.Nvarchar;
110153
}
111154
return false;
112155
}
113156
}
157+
114158
public class ProductExtraColumns
115159
{
116160
public int ProductId { get; set; }

test/Common/ProductColumnTypes.cs

+48-1
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,65 @@ public class ProductColumnTypes
99
{
1010
public int ProductId { get; set; }
1111

12+
public long BigInt { get; set; }
13+
14+
public bool Bit { get; set; }
15+
16+
public decimal DecimalType { get; set; }
17+
18+
public decimal Money { get; set; }
19+
20+
public decimal Numeric { get; set; }
21+
22+
public short SmallInt { get; set; }
23+
24+
public decimal SmallMoney { get; set; }
25+
26+
public short TinyInt { get; set; }
27+
28+
public Double FloatType { get; set; }
29+
30+
public Single Real { get; set; }
31+
32+
public DateTime Date { get; set; }
33+
1234
public DateTime Datetime { get; set; }
1335

1436
public DateTime Datetime2 { get; set; }
1537

38+
public DateTimeOffset DatetimeOffset { get; set; }
39+
40+
public DateTime SmallDatetime { get; set; }
41+
42+
public TimeSpan Time { get; set; }
43+
44+
public string CharType { get; set; }
45+
46+
public string Varchar { get; set; }
47+
48+
public string Nchar { get; set; }
49+
50+
public string Nvarchar { get; set; }
51+
1652
public override bool Equals(object obj)
1753
{
1854
if (obj is ProductColumnTypes)
1955
{
2056
var that = obj as ProductColumnTypes;
21-
return this.ProductId == that.ProductId && this.Datetime == that.Datetime && this.Datetime2 == that.Datetime2;
57+
return this.ProductId == that.ProductId && this.BigInt == that.BigInt && this.Bit == that.Bit &&
58+
this.DecimalType == that.DecimalType && this.Money == that.Money && this.Numeric == that.Numeric &&
59+
this.SmallInt == that.SmallInt && this.SmallMoney == that.SmallMoney && this.TinyInt == that.TinyInt &&
60+
this.FloatType == that.FloatType && this.Real == that.Real && this.Date == that.Date &&
61+
this.Datetime == that.Datetime && this.Datetime2 == that.Datetime2 && this.DatetimeOffset == that.DatetimeOffset &&
62+
this.SmallDatetime == that.SmallDatetime && this.Time == that.Time && this.CharType == that.CharType &&
63+
this.Varchar == that.Varchar && this.Nchar == that.Nchar && this.Nvarchar == that.Nvarchar;
2264
}
2365
return false;
2466
}
67+
68+
public override string ToString()
69+
{
70+
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}]";
71+
}
2572
}
2673
}
+22-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
CREATE TABLE [ProductsColumnTypes] (
2-
[ProductId] [int] NOT NULL PRIMARY KEY,
3-
[Datetime] [datetime],
4-
[Datetime2] [datetime2]
5-
)
2+
[ProductId] [int] NOT NULL PRIMARY KEY,
3+
[BigInt] [bigint],
4+
[Bit] [bit],
5+
[DecimalType] [decimal](18,4),
6+
[Money] [money],
7+
[Numeric] [numeric](18,4),
8+
[SmallInt] [smallint],
9+
[SmallMoney] [smallmoney],
10+
[TinyInt] [tinyint],
11+
[FloatType] [float],
12+
[Real] [real],
13+
[Date] [date],
14+
[Datetime] [datetime],
15+
[Datetime2] [datetime2],
16+
[DatetimeOffset] [datetimeoffset],
17+
[SmallDatetime] [smalldatetime],
18+
[Time] [time],
19+
[CharType] [char](4),
20+
[Varchar] [varchar](100),
21+
[Nchar] [nchar](4),
22+
[Nvarchar] [nvarchar](100),
23+
)

test/Integration/SqlInputBindingIntegrationTests.cs

+46-17
Original file line numberDiff line numberDiff line change
@@ -143,19 +143,30 @@ public async void GetProductsColumnTypesSerializationAsyncEnumerableTest(string
143143
this.StartFunctionHost(nameof(GetProductsColumnTypesSerializationAsyncEnumerable), lang, true);
144144

145145
string datetime = "2022-10-20 12:39:13.123";
146-
ProductColumnTypes[] expectedResponse = new[]
147-
{
148-
new ProductColumnTypes()
149-
{
150-
ProductId = 999,
151-
Datetime = DateTime.Parse(datetime),
152-
Datetime2 = DateTime.Parse(datetime)
153-
}
154-
};
146+
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\"}]");
147+
155148
this.ExecuteNonQuery("INSERT INTO [dbo].[ProductsColumnTypes] VALUES (" +
156-
"999, " + // ProductId
157-
$"CONVERT(DATETIME, '{datetime}'), " + // Datetime field
158-
$"CONVERT(DATETIME2, '{datetime}'))"); // Datetime2 field
149+
"999, " + // ProductId,
150+
"999, " + // BigInt
151+
"0, " + // Bit
152+
"1.2345, " + // DecimalType
153+
"1.2345, " + // Money
154+
"1.2345, " + // Numeric
155+
"1, " + // SmallInt
156+
"1.2345, " + // SmallMoney
157+
"1, " + // TinyInt
158+
".1, " + // FloatType
159+
".1, " + // Real
160+
$"CONVERT(DATE, '{datetime}'), " + // Date
161+
$"CONVERT(DATETIME, '{datetime}'), " + // Datetime
162+
$"CONVERT(DATETIME2, '{datetime}'), " + // Datetime2
163+
$"CONVERT(DATETIMEOFFSET, '{datetime}'), " + // DatetimeOffset
164+
$"CONVERT(SMALLDATETIME, '{datetime}'), " + // SmallDatetime
165+
$"CONVERT(TIME, '{datetime}'), " + // Time
166+
"'test', " + // CharType
167+
"'test', " + // Varchar
168+
"NCHAR(0xD84C), " + // Nchar
169+
"NCHAR(0xD84C))"); // Nvarchar
159170

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

176187
string datetime = "2022-10-20 12:39:13.123";
177188
this.ExecuteNonQuery("INSERT INTO [dbo].[ProductsColumnTypes] VALUES (" +
178-
"999, " + // ProductId
179-
$"CONVERT(DATETIME, '{datetime}'), " + // Datetime field
180-
$"CONVERT(DATETIME2, '{datetime}'))"); // Datetime2 field
189+
"999, " + // ProductId,
190+
"999, " + // BigInt
191+
"0, " + // Bit
192+
"1.2345, " + // DecimalType
193+
"1.2345, " + // Money
194+
"1.2345, " + // Numeric
195+
"1, " + // SmallInt
196+
"1.2345, " + // SmallMoney
197+
"1, " + // TinyInt
198+
".1, " + // FloatType
199+
".1, " + // Real
200+
$"CONVERT(DATE, '{datetime}'), " + // Date
201+
$"CONVERT(DATETIME, '{datetime}'), " + // Datetime
202+
$"CONVERT(DATETIME2, '{datetime}'), " + // Datetime2
203+
$"CONVERT(DATETIMEOFFSET, '{datetime}'), " + // DatetimeOffset
204+
$"CONVERT(SMALLDATETIME, '{datetime}'), " + // SmallDatetime
205+
$"CONVERT(TIME, '{datetime}'), " + // Time
206+
"'test', " + // CharType
207+
"'test', " + // Varchar
208+
"NCHAR(0xD84C), " + // Nchar
209+
"NCHAR(0xD84C))"); // Nvarchar
181210

182211
HttpResponseMessage response = await this.SendInputRequest("getproducts-columntypesserialization");
183-
// We expect the datetime and datetime2 fields to be returned in UTC format
184-
ProductColumnTypes[] expectedResponse = JsonConvert.DeserializeObject<ProductColumnTypes[]>("[{\"ProductId\":999,\"Datetime\":\"2022-10-20T12:39:13.123Z\",\"Datetime2\":\"2022-10-20T12:39:13.123Z\"}]");
212+
// We expect the date fields to be returned in UTC format
213+
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\"}]");
185214
string actualResponse = await response.Content.ReadAsStringAsync();
186215
ProductColumnTypes[] actualProductResponse = JsonConvert.DeserializeObject<ProductColumnTypes[]>(actualResponse);
187216

test/Integration/SqlOutputBindingIntegrationTests.cs

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ public void AddProductArrayTest(SupportedLanguages lang)
110110
/// <param name="lang">The language to run the test against</param>
111111
[Theory]
112112
[SqlInlineData()]
113+
// Tracking issue here: https://github.com/Azure/azure-functions-sql-extension/issues/521
113114
[UnsupportedLanguages(SupportedLanguages.Java)]
114115
public void AddProductColumnTypesTest(SupportedLanguages lang)
115116
{

test/Integration/test-csharp/AddProductColumnTypes.cs

+21-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static class AddProductColumnTypes
1313
{
1414
/// <summary>
1515
/// This function is used to test compatability with converting various data types to their respective
16-
/// SQL server types.
16+
/// SQL server types.
1717
/// </summary>
1818
[FunctionName(nameof(AddProductColumnTypes))]
1919
public static IActionResult Run(
@@ -23,8 +23,26 @@ public static IActionResult Run(
2323
product = new ProductColumnTypes()
2424
{
2525
ProductId = int.Parse(req.Query["productId"]),
26-
Datetime = DateTime.UtcNow,
27-
Datetime2 = DateTime.UtcNow
26+
BigInt = int.MaxValue,
27+
Bit = true,
28+
DecimalType = 1.2345M,
29+
Money = 1.23M,
30+
Numeric = 1.2345M,
31+
SmallInt = 0,
32+
SmallMoney = 1.23M,
33+
TinyInt = 1,
34+
FloatType = 1.2,
35+
Real = 1.2f,
36+
Date = DateTime.Now,
37+
Datetime = DateTime.Now,
38+
Datetime2 = DateTime.Now,
39+
DatetimeOffset = DateTime.Now,
40+
SmallDatetime = DateTime.Now,
41+
Time = DateTime.Now.TimeOfDay,
42+
CharType = "test",
43+
Varchar = "test",
44+
Nchar = "\u2649",
45+
Nvarchar = "\u2649",
2846
};
2947

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

test/Integration/test-java/src/main/java/com/function/AddProductColumnTypes.java

+21-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
import com.microsoft.azure.functions.sql.annotation.SQLOutput;
1818
import com.function.Common.ProductColumnTypes;
1919

20+
import java.math.BigDecimal;
2021
import java.sql.Timestamp;
22+
import java.sql.Time;
2123
import java.util.Optional;
2224

2325
public class AddProductColumnTypes {
@@ -37,8 +39,26 @@ public HttpResponseMessage run(
3739

3840
ProductColumnTypes p = new ProductColumnTypes(
3941
Integer.parseInt(request.getQueryParameters().get("productId")),
42+
(long)999,
43+
true,
44+
new BigDecimal("1.2345"),
45+
new BigDecimal("1.2345"),
46+
new BigDecimal("1.2345"),
47+
(short)1,
48+
new BigDecimal("1.2345"),
49+
(short)1,
50+
0.1,
51+
0.1,
4052
new Timestamp(System.currentTimeMillis()),
41-
new Timestamp(System.currentTimeMillis()));
53+
new Timestamp(System.currentTimeMillis()),
54+
new Timestamp(System.currentTimeMillis()),
55+
new Timestamp(System.currentTimeMillis()),
56+
new Timestamp(System.currentTimeMillis()),
57+
new Time(System.currentTimeMillis()).toString(),
58+
"test",
59+
"test",
60+
"\u2649",
61+
"\u2649");
4262
product.setValue(p);
4363

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

0 commit comments

Comments
 (0)