Skip to content

Commit dda1947

Browse files
Add more tests for OOP (#555)
* intial commit with tests for samples * changes for out of proc tests * remove commented code * remove tests from worker proj * initial commit * exclude outofproc for now * add local.settings.json * exclude outofproc for UnsupportedDatabaseThrows * remove queue trigger sample * remove OutOfProc from Unsuppported list * missed a test * test ColumnType with Date * Update test-outofproc/host.json Co-authored-by: Charles Gagnon <chgagnon@microsoft.com> * fix build error * exclude AddProductColumnTypesTest for OOP * add local settings file * add test-outofproc to sln * dont overwrite negative tests * supress warning * clean up * enable GetProductsColumnTypesSerializationTest Co-authored-by: Charles Gagnon <chgagnon@microsoft.com>
1 parent 99a5c30 commit dda1947

27 files changed

+1434
-5
lines changed

Directory.Packages.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
<PackageVersion Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.7.0" />
2323
<PackageVersion Include="System.Net.NameResolution" Version="4.3.0" />
2424
<PackageVersion Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
25+
<PackageVersion Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.1.0" />
26+
<PackageVersion Include="Microsoft.Azure.Functions.Worker.Extensions.Storage.Queues" Version="5.0.0" />
2527
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
2628
</ItemGroup>
2729
</Project>

WebJobs.Extensions.Sql.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Azure.Functions.W
3030
EndProject
3131
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Azure.WebJobs.Extensions.Sql.SamplesOutOfProc", "samples\samples-outofproc\Microsoft.Azure.WebJobs.Extensions.Sql.SamplesOutOfProc.csproj", "{BD0CE086-1778-4B08-905F-6766399C1D44}"
3232
EndProject
33+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "test-outofproc", "test-outofproc\test-outofproc.csproj", "{4E09227F-3F7C-4FAC-997A-24EB799CEC61}"
34+
EndProject
3335
Global
3436
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3537
Debug|Any CPU = Debug|Any CPU
@@ -60,6 +62,10 @@ Global
6062
{BD0CE086-1778-4B08-905F-6766399C1D44}.Debug|Any CPU.Build.0 = Debug|Any CPU
6163
{BD0CE086-1778-4B08-905F-6766399C1D44}.Release|Any CPU.ActiveCfg = Release|Any CPU
6264
{BD0CE086-1778-4B08-905F-6766399C1D44}.Release|Any CPU.Build.0 = Release|Any CPU
65+
{4E09227F-3F7C-4FAC-997A-24EB799CEC61}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
66+
{4E09227F-3F7C-4FAC-997A-24EB799CEC61}.Debug|Any CPU.Build.0 = Debug|Any CPU
67+
{4E09227F-3F7C-4FAC-997A-24EB799CEC61}.Release|Any CPU.ActiveCfg = Release|Any CPU
68+
{4E09227F-3F7C-4FAC-997A-24EB799CEC61}.Release|Any CPU.Build.0 = Release|Any CPU
6369
EndGlobalSection
6470
GlobalSection(SolutionProperties) = preSolution
6571
HideSolutionNode = FALSE

samples/samples-outofproc/GlobalSuppressions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@
1818
[assembly: SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Unused parameter is required by functions binding", Scope = "member", Target = "~M:Microsoft.Azure.WebJobs.Extensions.Sql.SamplesOutOfProc.InputBindingSamples.GetProductsStoredProcedureFromAppSetting.Run(Microsoft.AspNetCore.Http.HttpRequest,System.Collections.Generic.IEnumerable{Microsoft.Azure.WebJobs.Extensions.Sql.SamplesOutOfProc.Common.Product})~System.Collections.Generic.IEnumerable{Microsoft.Azure.WebJobs.Extensions.Sql.SamplesOutOfProc.Common.Product}")]
1919
[assembly: SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Unused parameter is required by functions binding", Scope = "member", Target = "~M:Microsoft.Azure.WebJobs.Extensions.Sql.SamplesOutOfProc.InputBindingSamples.GetProductsString.Run(Microsoft.AspNetCore.Http.HttpRequest,System.String)~System.String")]
2020
[assembly: SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Unused parameter is required by functions binding", Scope = "member", Target = "~M:Microsoft.Azure.WebJobs.Extensions.Sql.SamplesOutOfProc.InputBindingSamples.GetProductsTopN.Run(Microsoft.AspNetCore.Http.HttpRequest,System.Collections.Generic.IEnumerable{Microsoft.Azure.WebJobs.Extensions.Sql.SamplesOutOfProc.Common.Product})~System.Collections.Generic.IEnumerable{Microsoft.Azure.WebJobs.Extensions.Sql.SamplesOutOfProc.Common.Product}")]
21-
[assembly: SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Unused parameter is required by functions binding", Scope = "member", Target = "~M:Microsoft.Azure.WebJobs.Extensions.Sql.SamplesOutOfProc.OutputBindingSamples.AddProductsWithIdentityColumnArray.Run(Microsoft.AspNetCore.Http.HttpRequest)~Microsoft.Azure.WebJobs.Extensions.Sql.SamplesOutOfProc.Common.ProductWithoutId[]")]
21+
[assembly: SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Unused parameter is required by functions binding", Scope = "member", Target = "~M:Microsoft.Azure.WebJobs.Extensions.Sql.SamplesOutOfProc.OutputBindingSamples.AddProductsWithIdentityColumnArray.Run(Microsoft.AspNetCore.Http.HttpRequest)~Microsoft.Azure.WebJobs.Extensions.Sql.SamplesOutOfProc.Common.ProductWithoutId[]")]
22+
[assembly: SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Unused parameter is required by functions binding", Scope = "member", Target = "~M:Microsoft.Azure.WebJobs.Extensions.Sql.SamplesOutOfProc.OutputBindingSamples.TimerTriggerProducts.Run(Microsoft.Azure.Functions.Worker.TimerInfo,Microsoft.Azure.Functions.Worker.FunctionContext})~System.Collections.Generic.IEnumerable{Microsoft.Azure.WebJobs.Extensions.Sql.SamplesOutOfProc.Common.Product}")]
23+

samples/samples-outofproc/Microsoft.Azure.WebJobs.Extensions.Sql.SamplesOutOfProc.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
<PackageReference Include="Microsoft.Azure.Functions.Worker" />
99
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" />
1010
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" />
11+
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" />
12+
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage.Queues" />
1113
<PackageReference Include="Microsoft.AspNetCore.Http" />
1214
</ItemGroup>
1315
<ItemGroup>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using System.Collections.Generic;
5+
using Microsoft.Azure.WebJobs.Extensions.Sql.SamplesOutOfProc.Common;
6+
using Microsoft.Azure.Functions.Worker;
7+
using Microsoft.Azure.Functions.Worker.Extension.Sql;
8+
9+
namespace Microsoft.Azure.WebJobs.Extensions.Sql.SamplesOutOfProc.OutputBindingSamples
10+
{
11+
public static class TimerTriggerProducts
12+
{
13+
/// <summary>
14+
/// This timer function runs evyery 5 seconds, each time it upserts 1000 rows of data.
15+
/// </summary>
16+
[Function("TimerTriggerProducts")]
17+
[SqlOutput("Products", ConnectionStringSetting = "SqlConnectionString")]
18+
public static List<Product> Run(
19+
[TimerTrigger("*/5 * * * * *")] TimerInfo req, FunctionContext context)
20+
{
21+
int totalUpserts = 1000;
22+
23+
List<Product> newProducts = ProductUtilities.GetNewProducts(totalUpserts);
24+
25+
return newProducts;
26+
}
27+
}
28+
}

samples/samples-outofproc/packages.lock.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,24 @@
3737
"Microsoft.Azure.Functions.Worker.Extensions.Abstractions": "1.0.0"
3838
}
3939
},
40+
"Microsoft.Azure.Functions.Worker.Extensions.Storage.Queues": {
41+
"type": "Direct",
42+
"requested": "[5.0.0, )",
43+
"resolved": "5.0.0",
44+
"contentHash": "cF95kiiU6PD9sptrV3GKQKzRv2DYATYNTpOtvUtbAYQ4xPFKgF4ke3fDBcu+cu2O1/C8FQ7MhzkEQv00bx552A==",
45+
"dependencies": {
46+
"Microsoft.Azure.Functions.Worker.Extensions.Abstractions": "1.1.0"
47+
}
48+
},
49+
"Microsoft.Azure.Functions.Worker.Extensions.Timer": {
50+
"type": "Direct",
51+
"requested": "[4.1.0, )",
52+
"resolved": "4.1.0",
53+
"contentHash": "8HvZaChaw40EKBfBew0XG132YhO6bEw0nznvey7gkhm9thUe6wkA2LXTXHXxcYefbx0rlh57WedSiJgKTG7MvQ==",
54+
"dependencies": {
55+
"Microsoft.Azure.Functions.Worker.Extensions.Abstractions": "1.0.0"
56+
}
57+
},
4058
"Microsoft.Azure.Functions.Worker.Sdk": {
4159
"type": "Direct",
4260
"requested": "[1.7.0, )",

test-outofproc/.editorconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# See https://github.com/dotnet/roslyn-analyzers/blob/main/.editorconfig for an example on different settings and how they're used
2+
3+
[*.cs]
4+
5+
dotnet_diagnostic.CS0659.severity = silent # overrides Object.Equals but does not override Object.GetHashCode() - not necessary for our samples
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"recommendations": [
3+
"ms-azuretools.vscode-azurefunctions"
4+
]
5+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using Microsoft.Azure.Functions.Worker;
5+
using Microsoft.Azure.Functions.Worker.Http;
6+
using System.Web;
7+
using System.Collections.Specialized;
8+
using Microsoft.Azure.Functions.Worker.Extension.Sql;
9+
using DotnetIsolatedTests.Common;
10+
using System;
11+
12+
namespace DotnetIsolatedTests
13+
{
14+
public static class AddProductColumnTypes
15+
{
16+
/// <summary>
17+
/// This function is used to test compatability with converting various data types to their respective
18+
/// SQL server types.
19+
/// </summary>
20+
[Function(nameof(AddProductColumnTypes))]
21+
[SqlOutput("dbo.ProductsColumnTypes", ConnectionStringSetting = "SqlConnectionString")]
22+
public static ProductColumnTypes Run(
23+
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "addproduct-columntypes")] HttpRequestData req)
24+
{
25+
NameValueCollection queryStrings = HttpUtility.ParseQueryString(req.Url.Query);
26+
var product = new ProductColumnTypes()
27+
{
28+
ProductID = int.Parse(queryStrings["productId"], null),
29+
Datetime = DateTime.UtcNow.Date,
30+
Datetime2 = DateTime.UtcNow
31+
};
32+
33+
// Items were inserted successfully so return success, an exception would be thrown if there
34+
// was any issues
35+
return product;
36+
}
37+
}
38+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using DotnetIsolatedTests.Common;
5+
using Microsoft.Azure.Functions.Worker;
6+
using Microsoft.AspNetCore.Http;
7+
using Microsoft.Azure.Functions.Worker.Extension.Sql;
8+
9+
namespace DotnetIsolatedTests
10+
{
11+
public static class AddProductExtraColumns
12+
{
13+
// This output binding should throw an Exception because the ProductExtraColumns object has
14+
// two properties that do not exist as columns in the SQL table (ExtraInt and ExtraString).
15+
[Function("AddProductExtraColumns")]
16+
[SqlOutput("dbo.Products", ConnectionStringSetting = "SqlConnectionString")]
17+
public static ProductExtraColumns Run(
18+
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "addproduct-extracolumns")]
19+
HttpRequest req)
20+
{
21+
var product = new ProductExtraColumns
22+
{
23+
Name = "test",
24+
ProductID = 1,
25+
Cost = 100,
26+
ExtraInt = 1,
27+
ExtraString = "test"
28+
};
29+
return product;
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)