Skip to content

Commit 124d11e

Browse files
authored
Add test for input binding with views (#193)
* add input bindinng with views test * xml format comments
1 parent 47c2f2d commit 124d11e

File tree

5 files changed

+58
-1
lines changed

5 files changed

+58
-1
lines changed

samples/Common/Product.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@ public class ProductWithOptionalId
2020

2121
public int Cost { get; set; }
2222
}
23+
24+
public class ProductName
25+
{
26+
public string Name { get; set; }
27+
}
2328
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CREATE VIEW ProductNames
2+
AS
3+
SELECT p.Name FROM Products p;

samples/GlobalSuppressions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@
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.Samples.OutputBindingSamples.AddProductsAsyncCollector.Run(Microsoft.AspNetCore.Http.HttpRequest,Microsoft.Azure.WebJobs.IAsyncCollector{Microsoft.Azure.WebJobs.Extensions.Sql.Samples.Common.Product})~System.Threading.Tasks.Task{Microsoft.AspNetCore.Mvc.IActionResult}")]
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.Samples.OutputBindingSamples.AddProductsCollector.Run(Microsoft.AspNetCore.Http.HttpRequest,Microsoft.Azure.WebJobs.ICollector{Microsoft.Azure.WebJobs.Extensions.Sql.Samples.Common.Product})~Microsoft.AspNetCore.Mvc.IActionResult")]
2121
[assembly: SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Unused parameter is required by functions binding", Scope = "member", Target = "~M:Microsoft.Azure.WebJobs.Extensions.Sql.Samples.OutputBindingSamples.TimerTriggerProducts.Run(Microsoft.Azure.WebJobs.TimerInfo,Microsoft.Extensions.Logging.ILogger,Microsoft.Azure.WebJobs.ICollector{Microsoft.Azure.WebJobs.Extensions.Sql.Samples.Common.Product})")]
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.Samples.InputBindingSamples.GetProducts.Run(Microsoft.AspNetCore.Http.HttpRequest,System.Collections.Generic.IEnumerable{Microsoft.Azure.WebJobs.Extensions.Sql.Samples.Common.Product})~Microsoft.AspNetCore.Mvc.IActionResult")]
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.Samples.InputBindingSamples.GetProducts.Run(Microsoft.AspNetCore.Http.HttpRequest,System.Collections.Generic.IEnumerable{Microsoft.Azure.WebJobs.Extensions.Sql.Samples.Common.Product})~Microsoft.AspNetCore.Mvc.IActionResult")]
23+
[assembly: SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Unused parameter is required by functions binding", Scope = "member", Target = "~M:Microsoft.Azure.WebJobs.Extensions.Sql.Samples.InputBindingSamples.GetProductNamesView.Run(Microsoft.AspNetCore.Http.HttpRequest,System.Collections.Generic.IEnumerable{Microsoft.Azure.WebJobs.Extensions.Sql.Samples.Common.ProductName})~Microsoft.AspNetCore.Mvc.IActionResult")]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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.AspNetCore.Http;
6+
using Microsoft.AspNetCore.Mvc;
7+
using Microsoft.Azure.WebJobs.Extensions.Http;
8+
using Microsoft.Azure.WebJobs.Extensions.Sql.Samples.Common;
9+
10+
namespace Microsoft.Azure.WebJobs.Extensions.Sql.Samples.InputBindingSamples
11+
{
12+
/// <summary>
13+
/// This shows an example of a SQL Input binding that queries from a SQL View named ProductNames.
14+
/// </summary>
15+
public static class GetProductNamesView
16+
{
17+
[FunctionName("GetProductNamesView")]
18+
public static IActionResult Run(
19+
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "getproduct-namesview/")]
20+
HttpRequest req,
21+
[Sql("SELECT * FROM ProductNames",
22+
CommandType = System.Data.CommandType.Text,
23+
ConnectionStringSetting = "SqlConnectionString")]
24+
IEnumerable<ProductName> products)
25+
{
26+
return new OkObjectResult(products);
27+
}
28+
}
29+
}

test/Integration/SqlInputBindingIntegrationTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,25 @@ public async void GetProductsNameEmptyTest(int n, int cost)
9898
Assert.Equal(expectedResponse, actualResponse, StringComparer.OrdinalIgnoreCase);
9999
}
100100

101+
[Fact]
102+
public async void GetProductNamesViewTest()
103+
{
104+
this.StartFunctionHost(nameof(GetProductNamesView));
105+
106+
// Insert one row of data into Product table
107+
Product[] products = GetProductsWithSameCost(1, 100);
108+
this.InsertProducts(products);
109+
110+
// Run the function that queries from the ProductName view
111+
HttpResponseMessage response = await this.SendInputRequest("getproduct-namesview");
112+
113+
// Verify result
114+
string expectedResponse = "[{\"name\":\"test\"}]";
115+
string actualResponse = await response.Content.ReadAsStringAsync();
116+
117+
Assert.Equal(expectedResponse, actualResponse, StringComparer.OrdinalIgnoreCase);
118+
}
119+
101120
private static Product[] GetProductsWithSameCost(int n, int cost)
102121
{
103122
var result = new Product[n];

0 commit comments

Comments
 (0)