Skip to content

Creates PowerShell Samples / Tests #449

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 44 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
afc2b34
add powershell samples
VasuBhog Oct 20, 2022
d3b5a3f
add further tests
VasuBhog Oct 21, 2022
c92fa64
fix powershell test
VasuBhog Oct 21, 2022
738337a
include runtime
VasuBhog Oct 21, 2022
ab4d551
copyright header fix
VasuBhog Oct 21, 2022
eb3b33c
deseralize powershell test
VasuBhog Oct 25, 2022
fa22718
add local.settings.json
VasuBhog Oct 26, 2022
c133228
add local.settings.json
VasuBhog Oct 26, 2022
64c2c1b
add local.settings.json correct for samples/ps
VasuBhog Oct 26, 2022
3eb0fc9
add local.settings.json for each sampels
VasuBhog Oct 26, 2022
b55cb98
update test to deseralize JSON objects and compare
VasuBhog Oct 26, 2022
3957d8e
update input test to fix views test
VasuBhog Oct 27, 2022
7ad4e37
Merge branch 'main' into vabhog/addPSSamplesTests
VasuBhog Oct 27, 2022
92acf93
add product params test
VasuBhog Oct 27, 2022
d975b53
address merge conflicts
VasuBhog Oct 27, 2022
cbd8ee1
address merge fixes
VasuBhog Oct 27, 2022
716a4c1
fix build
VasuBhog Oct 27, 2022
a1834b7
add function.json fix
VasuBhog Oct 27, 2022
b184c13
test getProductNamesViewTes
VasuBhog Oct 28, 2022
b82bde4
fixes
VasuBhog Oct 28, 2022
0e66298
fixes serialization problems
VasuBhog Oct 28, 2022
dba174e
add debug test
VasuBhog Oct 28, 2022
e19258c
Merge branch 'main' into vabhog/addPSSamplesTests
VasuBhog Oct 31, 2022
351c8e2
add debug tests
VasuBhog Oct 31, 2022
96b73c6
add debug add product test
VasuBhog Oct 31, 2022
ddc1f82
fixes serialization problems
VasuBhog Oct 31, 2022
b8e57ab
fix output binding tests
VasuBhog Nov 2, 2022
0cd9e31
small fixes
VasuBhog Nov 2, 2022
2b6907e
product overide test
VasuBhog Nov 2, 2022
33821b4
fix product test
VasuBhog Nov 2, 2022
3ed6e29
fix tests
VasuBhog Nov 2, 2022
bd14a67
address fixes
VasuBhog Nov 2, 2022
ea3b366
mark tests that are not currently working
VasuBhog Nov 3, 2022
60a539e
undo local.settings.json
VasuBhog Nov 3, 2022
1513c55
AddProductWithMultiplePrimaryColumnsAndIdentity test
VasuBhog Nov 3, 2022
188f40c
identity tests are unstable
VasuBhog Nov 3, 2022
41aec73
other identity tests unstable
VasuBhog Nov 4, 2022
c3e98fe
address comments
VasuBhog Nov 7, 2022
17d3ac1
Merge branch 'main' into vabhog/addPSSamplesTests
VasuBhog Nov 7, 2022
4a9e9d7
address comments:
VasuBhog Nov 7, 2022
9d006a5
add generic default files
VasuBhog Nov 7, 2022
985540e
add pipeline task
VasuBhog Nov 7, 2022
5c9b31c
add/edit comments
VasuBhog Nov 7, 2022
67980c4
fix pipeline dotnet task
VasuBhog Nov 7, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -358,4 +358,7 @@ __queuestorage__
__azurite_db*__.json

# Python virtual environment
.venv
.venv

# Mac OS X
.DS_Store
7 changes: 7 additions & 0 deletions builds/azure-pipelines/template-steps-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ steps:
inputs:
useGlobalJson: true

# Install .Net Core 3.1.0 as PowerShell tests are unable to find 3.1.0 framework to run tests
- task: UseDotNet@2
displayName: 'Install .NET Core 3.1 sdk'
inputs:
packageType: sdk
version: '3.1.x'

# Run Policheck early to avoid scanning dependency folders
- task: securedevelopmentteam.vss-secure-development-tools.build-task-policheck.PoliCheck@2
displayName: 'Run PoliCheck'
Expand Down
10 changes: 10 additions & 0 deletions samples/samples-csharp/Common/Product.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ public class ProductWithOptionalId
public class ProductName
{
public string Name { get; set; }

public override bool Equals(object obj)
{
if (obj is Product)
{
var that = obj as Product;
return this.Name == that.Name;
}
return false;
}
}

public class ProductWithDefaultPK
Expand Down
3 changes: 3 additions & 0 deletions samples/samples-powershell/.funcignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.git*
.vscode
local.settings.json
10 changes: 10 additions & 0 deletions samples/samples-powershell/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Azure Functions artifacts
bin
obj
appsettings.json
local.settings.json

# Azurite artifacts
__blobstorage__
__queuestorage__
__azurite_db*__.json
6 changes: 6 additions & 0 deletions samples/samples-powershell/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"ms-azuretools.vscode-azurefunctions",
"ms-vscode.powershell"
]
}
13 changes: 13 additions & 0 deletions samples/samples-powershell/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to PowerShell Functions",
"type": "PowerShell",
"request": "attach",
"customPipeName": "AzureFunctionsPSWorker",
"runspaceId": 1,
"preLaunchTask": "func: host start"
}
]
}
7 changes: 7 additions & 0 deletions samples/samples-powershell/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"azureFunctions.templateFilter": "All",
"azureFunctions.deploySubpath": ".",
"azureFunctions.projectLanguage": "PowerShell",
"azureFunctions.projectRuntime": "~4",
"debug.internalConsoleOptions": "neverOpen"
}
11 changes: 11 additions & 0 deletions samples/samples-powershell/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "func",
"command": "host start",
"problemMatcher": "$func-powershell-watch",
"isBackground": true
}
]
}
27 changes: 27 additions & 0 deletions samples/samples-powershell/AddProduct/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"bindings": [
{
"authLevel": "function",
"name": "Request",
"direction": "in",
"type": "httpTrigger",
"methods": [
"post"
],
"route": "addproduct"
},
{
"name": "response",
"type": "http",
"direction": "out"
},
{
"name": "product",
"type": "sql",
"direction": "out",
"commandText": "[dbo].[Products]",
"connectionStringSetting": "SqlConnectionString"
}
],
"disabled": false
}
23 changes: 23 additions & 0 deletions samples/samples-powershell/AddProduct/run.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using namespace System.Net

# Trigger binding data passed in via param block
param($Request)

# Write to the Azure Functions log stream.
Write-Host "PowerShell function with SQL Output Binding processed a request."

# Update req_body with the body of the request
# Note that this expects the body to be a JSON object or array of objects
# which have a property matching each of the columns in the table to upsert to.
$req_body = $Request.Body

# Assign the value we want to pass to the SQL Output binding.
# The -Name value corresponds to the name property in the function.json for the binding
Push-OutputBinding -Name product -Value $req_body

# Assign the value to return as the HTTP response.
# The -Name value matches the name property in the function.json for the binding
Push-OutputBinding -Name response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = $req_body
})
28 changes: 28 additions & 0 deletions samples/samples-powershell/AddProductParams/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"bindings": [
{
"authLevel": "function",
"name": "Request",
"direction": "in",
"type": "httpTrigger",
"methods": [
"get",
"post"
],
"route": "addproduct-params"
},
{
"name": "response",
"type": "http",
"direction": "out"
},
{
"name": "product",
"type": "sql",
"direction": "out",
"commandText": "[dbo].[Products]",
"connectionStringSetting": "SqlConnectionString"
}
],
"disabled": false
}
25 changes: 25 additions & 0 deletions samples/samples-powershell/AddProductParams/run.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using namespace System.Net

# Trigger binding data passed in via param block
param($Request)

# Write to the Azure Functions log stream.
Write-Host "PowerShell function with SQL Output Binding processed a request."

# Update req_query with the query of the request
$req_query = @{
"productId"= $Request.QUERY.productId;
"name"= $Request.QUERY.name;
"cost"= $Request.QUERY.cost;
};

# Assign the value we want to pass to the SQL Output binding.
# The -Name value corresponds to the name property in the function.json for the binding
Push-OutputBinding -Name product -Value $req_query

# Assign the value to return as the HTTP response.
# The -Name value matches the name property in the function.json for the binding
Push-OutputBinding -Name response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = $req_query
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"bindings": [
{
"authLevel": "function",
"name": "Request",
"direction": "in",
"type": "httpTrigger",
"methods": [
"post"
],
"route": "addproductwithdefaultpk"
},
{
"name": "response",
"type": "http",
"direction": "out"
},
{
"name": "products",
"type": "sql",
"direction": "out",
"commandText": "[dbo].[ProductsWithDefaultPK]",
"connectionStringSetting": "SqlConnectionString"
}
],
"disabled": false
}
23 changes: 23 additions & 0 deletions samples/samples-powershell/AddProductWithDefaultPK/run.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using namespace System.Net

# Trigger binding data passed in via param block
param($Request)

# Write to the Azure Functions log stream.
Write-Host "PowerShell function with SQL Output Binding processed a request."

# Update req_body with the body of the request
# Note that this expects the body to be a JSON object or array of objects
# which have a property matching each of the columns in the table to upsert to.
$req_body = $Request.Body

# Assign the value we want to pass to the SQL Output binding.
# The -Name value corresponds to the name property in the function.json for the binding
Push-OutputBinding -Name products -Value $req_body

# Assign the value to return as the HTTP response.
# The -Name value matches the name property in the function.json for the binding
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = $req_body
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"bindings": [
{
"authLevel": "function",
"name": "Request",
"direction": "in",
"type": "httpTrigger",
"methods": [
"get",
"post"
],
"route": "addproductwithidentitycolumn"
},
{
"name": "response",
"type": "http",
"direction": "out"
},
{
"name": "product",
"type": "sql",
"direction": "out",
"commandText": "[dbo].[ProductsWithIdentity]",
"connectionStringSetting": "SqlConnectionString"
}
],
"disabled": false
}
24 changes: 24 additions & 0 deletions samples/samples-powershell/AddProductWithIdentityColumn/run.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using namespace System.Net

# Trigger binding data passed in via param block
param($Request)

# Write to the Azure Functions log stream.
Write-Host "PowerShell function with SQL Output Binding processed a request."

# Update req_query with the query of the request
$req_query = @{
name=$Request.QUERY.name;
cost=$Request.QUERY.cost;
};

# Assign the value we want to pass to the SQL Output binding.
# The -Name value corresponds to the name property in the function.json for the binding
Push-OutputBinding -Name product -Value $req_query

# Assign the value to return as the HTTP response.
# The -Name value matches the name property in the function.json for the binding
Push-OutputBinding -Name response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = $req_query
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"bindings": [
{
"authLevel": "function",
"name": "Request",
"direction": "in",
"type": "httpTrigger",
"methods": [
"get"
],
"route": "addproductwithidentitycolumnincluded"
},
{
"name": "response",
"type": "http",
"direction": "out"
},
{
"name": "product",
"type": "sql",
"direction": "out",
"commandText": "[dbo].[ProductsWithIdentity]",
"connectionStringSetting": "SqlConnectionString"
}
],
"disabled": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using namespace System.Net

# Trigger binding data passed in via param block
param($Request)

# Write to the Azure Functions log stream.
Write-Host "PowerShell function with SQL Output Binding processed a request."

# Update req_query with the body of the request
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update comment

$req_query = @{
productId= if($Request.QUERY.productId) { $Request.QUERY.productId } else { $null };
name=$Request.QUERY.name;
cost=$Request.QUERY.cost;
};

# Assign the value we want to pass to the SQL Output binding.
# The -Name value corresponds to the name property in the function.json for the binding
Push-OutputBinding -Name product -Value $req_query

# Assign the value to return as the HTTP response.
# The -Name value matches the name property in the function.json for the binding
Push-OutputBinding -Name response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = $req_query
})
Loading