Skip to content

Commit 8fe0d26

Browse files
authored
tests for out of proc samples (#516)
* intial commit with tests for samples * changes for out of proc tests * remove commented code * remove tests from worker proj * add local.settings.json * exclude outofproc for UnsupportedDatabaseThrows
1 parent bd46fcf commit 8fe0d26

File tree

6 files changed

+34
-12
lines changed

6 files changed

+34
-12
lines changed

samples/samples-outofproc/OutputBindingSamples/AddProductParams.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static class AddProductParams
1515
[Function("AddProductParams")]
1616
[SqlOutput("dbo.Products", ConnectionStringSetting = "SqlConnectionString")]
1717
public static Product Run(
18-
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "addproduct-params")]
18+
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "addproduct-params")]
1919
HttpRequestData req)
2020
{
2121
if (req != null)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"IsEncrypted": false,
3+
"Values": {
4+
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
5+
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
6+
"SqlConnectionString": "",
7+
"Sp_SelectCost": "SelectProductsCost",
8+
"ProductCost": 100
9+
}
10+
}

test/Common/SupportedLanguagesTestAttribute.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public enum SupportedLanguages
7373
CSharp,
7474
JavaScript,
7575
PowerShell,
76-
Java
76+
Java,
77+
OutOfProc
7778
};
7879
}

test/Integration/SqlInputBindingIntegrationTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public async void GetProductNamesViewTest(SupportedLanguages lang)
137137
[Theory]
138138
[SqlInlineData("en-US")]
139139
[SqlInlineData("it-IT")]
140-
[UnsupportedLanguages(SupportedLanguages.JavaScript, SupportedLanguages.PowerShell, SupportedLanguages.Java)] // IAsyncEnumerable is only available in C#
140+
[UnsupportedLanguages(SupportedLanguages.JavaScript, SupportedLanguages.PowerShell, SupportedLanguages.Java, SupportedLanguages.OutOfProc)] // IAsyncEnumerable is only available in C#
141141
public async void GetProductsColumnTypesSerializationAsyncEnumerableTest(string culture, SupportedLanguages lang)
142142
{
143143
this.StartFunctionHost(nameof(GetProductsColumnTypesSerializationAsyncEnumerable), lang, true);
@@ -163,7 +163,7 @@ public async void GetProductsColumnTypesSerializationAsyncEnumerableTest(string
163163
[SqlInlineData()]
164164
// Java worker returns timestamps in local time zone
165165
// https://github.com/Azure/azure-functions-sql-extension/issues/515
166-
[UnsupportedLanguages(SupportedLanguages.Java)]
166+
[UnsupportedLanguages(SupportedLanguages.Java, SupportedLanguages.OutOfProc)]
167167
public async void GetProductsColumnTypesSerializationTest(SupportedLanguages lang)
168168
{
169169
this.StartFunctionHost(nameof(GetProductsColumnTypesSerialization), lang, true);

test/Integration/SqlOutputBindingIntegrationTests.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ public void AddProductTest(int id, string name, int cost, SupportedLanguages lan
2929
{
3030
this.StartFunctionHost(nameof(AddProduct), lang);
3131

32-
var query = new Dictionary<string, string>()
32+
var query = new Dictionary<string, object>()
3333
{
34-
{ "productId", id.ToString() },
34+
{ "productId", id },
3535
{ "name", name },
36-
{ "cost", cost.ToString() }
36+
{ "cost", cost }
3737
};
3838

3939
this.SendOutputPostRequest("addproduct", JsonConvert.SerializeObject(query)).Wait();
@@ -116,7 +116,7 @@ public void AddProductArrayTest(SupportedLanguages lang)
116116
[SqlInlineData()]
117117
// This test is currrently failing in the Linux pipeline for Java
118118
// https://github.com/Azure/azure-functions-sql-extension/issues/521
119-
[UnsupportedLanguages(SupportedLanguages.Java, SupportedLanguages.PowerShell)]
119+
[UnsupportedLanguages(SupportedLanguages.Java, SupportedLanguages.PowerShell, SupportedLanguages.OutOfProc)]
120120
public void AddProductColumnTypesTest(SupportedLanguages lang)
121121
{
122122
this.StartFunctionHost(nameof(AddProductColumnTypes), lang, true);
@@ -133,7 +133,7 @@ public void AddProductColumnTypesTest(SupportedLanguages lang)
133133

134134
[Theory]
135135
[SqlInlineData()]
136-
[UnsupportedLanguages(SupportedLanguages.JavaScript, SupportedLanguages.PowerShell, SupportedLanguages.Java)] // Collectors are only available in C#
136+
[UnsupportedLanguages(SupportedLanguages.JavaScript, SupportedLanguages.PowerShell, SupportedLanguages.Java, SupportedLanguages.OutOfProc)] // Collectors are only available in C#
137137
public void AddProductsCollectorTest(SupportedLanguages lang)
138138
{
139139
this.StartFunctionHost(nameof(AddProductsCollector), lang);
@@ -146,6 +146,7 @@ public void AddProductsCollectorTest(SupportedLanguages lang)
146146

147147
[Theory]
148148
[SqlInlineData()]
149+
[UnsupportedLanguages(SupportedLanguages.OutOfProc)]
149150
public void QueueTriggerProductsTest(SupportedLanguages lang)
150151
{
151152
this.StartFunctionHost(nameof(QueueTriggerProducts), lang);
@@ -163,6 +164,7 @@ public void QueueTriggerProductsTest(SupportedLanguages lang)
163164

164165
[Theory]
165166
[SqlInlineData()]
167+
[UnsupportedLanguages(SupportedLanguages.OutOfProc)]
166168
public void TimerTriggerProductsTest(SupportedLanguages lang)
167169
{
168170
this.StartFunctionHost(nameof(TimerTriggerProducts), lang);
@@ -189,6 +191,7 @@ public void AddProductExtraColumnsTest(SupportedLanguages lang)
189191

190192
[Theory]
191193
[SqlInlineData()]
194+
[UnsupportedLanguages(SupportedLanguages.OutOfProc)]
192195
public void AddProductMissingColumnsTest(SupportedLanguages lang)
193196
{
194197
this.StartFunctionHost(nameof(AddProductMissingColumns), lang, true);
@@ -201,6 +204,7 @@ public void AddProductMissingColumnsTest(SupportedLanguages lang)
201204

202205
[Theory]
203206
[SqlInlineData()]
207+
[UnsupportedLanguages(SupportedLanguages.OutOfProc)]
204208
public void AddProductMissingColumnsNotNullTest(SupportedLanguages lang)
205209
{
206210
this.StartFunctionHost(nameof(AddProductMissingColumnsExceptionFunction), lang, true);
@@ -212,6 +216,7 @@ public void AddProductMissingColumnsNotNullTest(SupportedLanguages lang)
212216

213217
[Theory]
214218
[SqlInlineData()]
219+
[UnsupportedLanguages(SupportedLanguages.OutOfProc)]
215220
public void AddProductNoPartialUpsertTest(SupportedLanguages lang)
216221
{
217222
this.StartFunctionHost(nameof(AddProductsNoPartialUpsert), lang, true);
@@ -421,10 +426,10 @@ public void AddProductCaseSensitiveTest(SupportedLanguages lang)
421426
public void AddProductWithDefaultPKTest(SupportedLanguages lang)
422427
{
423428
this.StartFunctionHost(nameof(AddProductWithDefaultPK), lang);
424-
var product = new Dictionary<string, string>()
429+
var product = new Dictionary<string, object>()
425430
{
426431
{ "name", "MyProduct" },
427-
{ "cost", "1" }
432+
{ "cost", 1 }
428433
};
429434
Assert.Equal(0, this.ExecuteScalar("SELECT COUNT(*) FROM dbo.ProductsWithDefaultPK"));
430435
this.SendOutputPostRequest("addproductwithdefaultpk", JsonConvert.SerializeObject(product)).Wait();
@@ -437,10 +442,11 @@ public void AddProductWithDefaultPKTest(SupportedLanguages lang)
437442
/// </summary>
438443
[Theory]
439444
[SqlInlineData()]
445+
[UnsupportedLanguages(SupportedLanguages.OutOfProc)]
440446
public async Task UnsupportedDatabaseThrows(SupportedLanguages lang)
441447
{
442448
// Change database compat level to unsupported version
443-
this.ExecuteNonQuery($"ALTER DATABASE {this.DatabaseName} SET COMPATIBILITY_LEVEL = 120");
449+
this.ExecuteNonQuery($"ALTER DATABASE {this.DatabaseName} SET COMPATIBILITY_LEVEL = 120;");
444450

445451
var foundExpectedMessageSource = new TaskCompletionSource<bool>();
446452
this.StartFunctionHost(nameof(AddProductParams), lang, false, (object sender, DataReceivedEventArgs e) =>

test/Microsoft.Azure.WebJobs.Extensions.Sql.Tests.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,10 @@
4343
</ItemGroup>
4444
<Copy SourceFiles="@(_PSCopyItems)" DestinationFolder="$(OutDir)\SqlExtensionSamples\PowerShell\%(RecursiveDir)" />
4545
<Message Text="Copied PS Samples output to $(OutDir)\SqlExtensionSamples\PowerShell" Importance="high" />
46+
<ItemGroup>
47+
<_OOPCopyItems Include="..\samples\samples-outofproc\bin\$(Configuration)\$(TargetFramework)\**\*.*" />
48+
</ItemGroup>
49+
<Copy SourceFiles="@(_OOPCopyItems)" DestinationFolder="$(OutDir)\SqlExtensionSamples\OutOfProc\%(RecursiveDir)" />
50+
<Message Text="Copied C# out of proc Samples output to $(OutDir)\SqlExtensionSamples\OutOfProc" Importance="high" />
4651
</Target>
4752
</Project>

0 commit comments

Comments
 (0)