From 2c9d2069b7c4b9fbc8256a11f49f35fc3aa0a47f Mon Sep 17 00:00:00 2001 From: Rob Sewell Date: Fri, 27 Apr 2018 08:43:19 +0100 Subject: [PATCH 1/6] Added data table snippet --- docs/community_snippets.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/docs/community_snippets.md b/docs/community_snippets.md index dcd7338061..e419fe1b3e 100644 --- a/docs/community_snippets.md +++ b/docs/community_snippets.md @@ -20,6 +20,7 @@ _To contribute, check out our [guide here](#contributing)._ | [DateTimeWriteVerbose](#datetimewriteverbose): _Write-Verbose with the time and date pre-pended to your message by @ThmsRynr_ | | [Parameter-Credential](#parameter-credential): _Add a standard credential parameter to your function by @omniomi_ | | [PSCustomObject](#pscustomobject): _A simple PSCustomObject by @brettmillerb_ | +| [DataTable](#datatable): _Creates a DataTable_ | ## Snippets @@ -39,6 +40,41 @@ Create calculated property for use in Select Statements } ``` +### DataTable + +Quickly create a Data Table object by @SQLDBAWithABeard. + +#### Snippet + +```json +"DataTable": { + "prefix": "DataTable", + "body": [ + "# Create DataTable Object", + "$$table = New-Object system.Data.DataTable $$TableName", + + "\r# Create Columns", + "$$col1 = New-Object system.Data.DataColumn NAME1,([string])", + "$$col2 = New-Object system.Data.DataColumn NAME2,([decimal])", + + "\r#Add the Columns to the table", + "$$table.columns.add($$col1)", + "$$table.columns.add($$col2)", + + "\r# Create a new Row", + "$$row = $$table.NewRow() ", + + "\r# Add values to new row", + "$$row.Name1 = 'VALUE'", + "$$row.NAME2 = 'VALUE'", + + "\r#Add new row to table", + "$$table.Rows.Add($$row)" + ], + "description": "Creates a Data Table Object" + } +``` + ### DateTimeWriteVerbose Quickly add a `Write-Verbose` with the current date and time inserted before the message you're going to write to the verbose stream, by @ThmsRynr. From 9e52a26ff4f84cbdbbdf69ebd5859819a10e341a Mon Sep 17 00:00:00 2001 From: Rob Sewell Date: Fri, 27 Apr 2018 08:48:33 +0100 Subject: [PATCH 2/6] added max length of datatable --- docs/community_snippets.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/docs/community_snippets.md b/docs/community_snippets.md index e419fe1b3e..179b850102 100644 --- a/docs/community_snippets.md +++ b/docs/community_snippets.md @@ -21,6 +21,7 @@ _To contribute, check out our [guide here](#contributing)._ | [Parameter-Credential](#parameter-credential): _Add a standard credential parameter to your function by @omniomi_ | | [PSCustomObject](#pscustomobject): _A simple PSCustomObject by @brettmillerb_ | | [DataTable](#datatable): _Creates a DataTable_ | +| [MaxColumnLengthinDataTable](#maxcolumnlengthindatatable): _Gets teh max length of string columns in datatables_ | ## Snippets @@ -91,6 +92,31 @@ Quickly add a `Write-Verbose` with the current date and time inserted before the } ``` +### MaxColumnLengthinDataTable + +Takes a datatable object and iterates through it to get the max length of the string columns - useful for data loads into a SQL Server table with fixed column widths by @SQLDBAWithABeard + +#### Snippet + +```json + "Max Length of Datatable": { + "prefix": "Max Length of Datatable", + "body": [ + "$$columns = ($$datatable | Get-Member -MemberType Property).Name", + "foreach($$column in $$Columns) {", + " $$max = 0", + " foreach ($$a in $$datatable){", + " if($$max -lt $$a.$$column.length){", + " $$max = $$a.$$column.length", + " }", + " }", + " Write-Output \"$$column max length is $$max\"", + "}" + ], + "description": "Takes a datatable object and iterates through it to get the max length of the string columns - useful for data loads" + } +``` + ### Parameter-Credential Add a `-Credential` parameter that supports a PSCredential object in a variable, `-Credential (Get-Credential)`, or `-Credential Username` (will prompt). Includes an empty PSCredential object as the default value but this is the first tabstop so pressing backspace after inserting the snippet removes it. by @omniomi From 778e42d1692d5806bf36245699485f1d7bcd54b7 Mon Sep 17 00:00:00 2001 From: Rob Sewell Date: Fri, 27 Apr 2018 08:48:48 +0100 Subject: [PATCH 3/6] spelling --- docs/community_snippets.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/community_snippets.md b/docs/community_snippets.md index 179b850102..dbed541bcd 100644 --- a/docs/community_snippets.md +++ b/docs/community_snippets.md @@ -21,7 +21,7 @@ _To contribute, check out our [guide here](#contributing)._ | [Parameter-Credential](#parameter-credential): _Add a standard credential parameter to your function by @omniomi_ | | [PSCustomObject](#pscustomobject): _A simple PSCustomObject by @brettmillerb_ | | [DataTable](#datatable): _Creates a DataTable_ | -| [MaxColumnLengthinDataTable](#maxcolumnlengthindatatable): _Gets teh max length of string columns in datatables_ | +| [MaxColumnLengthinDataTable](#maxcolumnlengthindatatable): _Gets the max length of string columns in datatables_ | ## Snippets From 00606c0a9c1c7cf6d08bab434698c20c1f82f06c Mon Sep 17 00:00:00 2001 From: Rob Sewell Date: Fri, 27 Apr 2018 09:02:01 +0100 Subject: [PATCH 4/6] Added Assertt Mock snippet --- docs/community_snippets.md | 46 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/docs/community_snippets.md b/docs/community_snippets.md index dbed541bcd..a840c89bc4 100644 --- a/docs/community_snippets.md +++ b/docs/community_snippets.md @@ -16,15 +16,39 @@ _To contribute, check out our [guide here](#contributing)._ | Table of Contents | |:------------------| +| [AssertMock](#assertmock): _Creates assert mock Pester test_ | | [CalculatedProperty](#calculatedproperty): _Create a calculated property for use in a select-object call by @corbob_ | +| [DataTable](#datatable): _Creates a DataTable_ | | [DateTimeWriteVerbose](#datetimewriteverbose): _Write-Verbose with the time and date pre-pended to your message by @ThmsRynr_ | +| [IfShouldProcess](#ifshouldprocess): _Added If Should Process_ | +| [MaxColumnLengthinDataTable](#maxcolumnlengthindatatable): _Gets the max length of string columns in datatables_ | | [Parameter-Credential](#parameter-credential): _Add a standard credential parameter to your function by @omniomi_ | | [PSCustomObject](#pscustomobject): _A simple PSCustomObject by @brettmillerb_ | -| [DataTable](#datatable): _Creates a DataTable_ | -| [MaxColumnLengthinDataTable](#maxcolumnlengthindatatable): _Gets the max length of string columns in datatables_ | + ## Snippets +### Assert Mock + +Creates Assert Mock for Pester Tests y @SQLDBAWithABeard + +#### Snippet + +```json + "AssertMock": { + "prefix": "AssertMock", + "body": [ + "$$assertMockParams = @{", + "'CommandName' = '${1:Command}'", + "'Times' = ${2:1}", + "'Exactly' = $$true", + "}", + "Assert-MockCalled @assertMockParams" + ], + "description": "AssertMock snippet for Pestering" + } +``` + ### CalculatedProperty Create calculated property for use in Select Statements @@ -92,6 +116,24 @@ Quickly add a `Write-Verbose` with the current date and time inserted before the } ``` +### IfShouldProcess + +Add If Should Process with easy tab inputs + +#### Snippet + +```json +"IfShouldProcess": { + "prefix": "IfShouldProcess", + "body": [ + "if ($$PSCmdlet.ShouldProcess(\"${1:The Item}\" , \"${2:The Change}\")) {", + " # Place Code here", + "}" + ], + "description": "Creates an if should process" + } +``` + ### MaxColumnLengthinDataTable Takes a datatable object and iterates through it to get the max length of the string columns - useful for data loads into a SQL Server table with fixed column widths by @SQLDBAWithABeard From c24871e893a47964905a010756fc0ea68edf32ee Mon Sep 17 00:00:00 2001 From: Rob Sewell Date: Fri, 27 Apr 2018 09:07:29 +0100 Subject: [PATCH 5/6] Added Pester Parameter test --- docs/community_snippets.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/community_snippets.md b/docs/community_snippets.md index a840c89bc4..d16e393196 100644 --- a/docs/community_snippets.md +++ b/docs/community_snippets.md @@ -23,6 +23,7 @@ _To contribute, check out our [guide here](#contributing)._ | [IfShouldProcess](#ifshouldprocess): _Added If Should Process_ | | [MaxColumnLengthinDataTable](#maxcolumnlengthindatatable): _Gets the max length of string columns in datatables_ | | [Parameter-Credential](#parameter-credential): _Add a standard credential parameter to your function by @omniomi_ | +| [PesterTestForParameter](#PesterTestForParameter): _Create Pester Test for Parameter_ | | [PSCustomObject](#pscustomobject): _A simple PSCustomObject by @brettmillerb_ | @@ -180,6 +181,23 @@ Add a `-Credential` parameter that supports a PSCredential object in a variable, } ``` +### PesterTestForParameter + +Quickly create a Pester Test for existence of a parameter by @SQLDBAWithABeard + +#### Snippet + +```json + "Pester for Parameter": { + "prefix": "Param Pester", + "body": [ + "It \"${1:FunctionName} Should have a parameter ${2:ParameterName}\" {", + " (Get-Command ${1:FunctionName}).Parameters['${2:ParameterName}'].Count | Should -Be 1", + "}" + ], + "description": "Pester Test for Parameter" + } +``` ### PSCustomObject A simple PSCustomObject by @brettmillerb. It has 4 properties that you can tab through to quickly fill in. From 2cf75952ff43b291d610549787fb8b59430f63dc Mon Sep 17 00:00:00 2001 From: Rob Sewell Date: Fri, 27 Apr 2018 09:10:08 +0100 Subject: [PATCH 6/6] added pester test for mandatory parameter --- docs/community_snippets.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/docs/community_snippets.md b/docs/community_snippets.md index d16e393196..2f8370b374 100644 --- a/docs/community_snippets.md +++ b/docs/community_snippets.md @@ -23,7 +23,8 @@ _To contribute, check out our [guide here](#contributing)._ | [IfShouldProcess](#ifshouldprocess): _Added If Should Process_ | | [MaxColumnLengthinDataTable](#maxcolumnlengthindatatable): _Gets the max length of string columns in datatables_ | | [Parameter-Credential](#parameter-credential): _Add a standard credential parameter to your function by @omniomi_ | -| [PesterTestForParameter](#PesterTestForParameter): _Create Pester Test for Parameter_ | +| [PesterTestForMandatoryParameter](#pestertestformandatoryparameter): _Create Pester test for a mandatory parameter_ | +| [PesterTestForParameter](#pestertestforparameter): _Create Pester test for parameter_ | | [PSCustomObject](#pscustomobject): _A simple PSCustomObject by @brettmillerb_ | @@ -181,6 +182,24 @@ Add a `-Credential` parameter that supports a PSCredential object in a variable, } ``` +### PesterTestForMandatoryParameter + +Quickly create a Pester Test for existence of a mandatory parameter by @SQLDBAWithABeard + +#### Snippet + +```json + "Pester for Mandatory Pester": { + "prefix": "mandatoryParamPester", + "body": [ + "It \"${1:FunctionName} Should have a mandatory parameter ${2:ParameterName}\" {", + " (Get-Command ${1:FunctionName}).Parameters['${2:ParameterName}'].Attributes.Mandatory | Should -BeTrue", + "}" + ], + "description": "Pester Test for Parameter" + } +``` + ### PesterTestForParameter Quickly create a Pester Test for existence of a parameter by @SQLDBAWithABeard