Closed beaudryj closed 8 years ago
For the IIS functions you can present the Property function in the public function. That allows you to make them more flexible.
example
function WebSiteBinding {
[CmdletBinding()]
param(
[Parameter(Mandatory, Position=1)]
[Alias('Name')]
[string]$Target,
[Parameter(Mandatory, Position=2)]
[string]$Property,
[Parameter(Mandatory, Position=3)]
[scriptblock]$Should
)
$expression = {Get-WebBinding -Name '$Target' -ErrorAction SilentlyContinue }
$params = Get-PoshspecParam -TestName WebSiteBinding -TestExpression $expression @PSBoundParameters
Invoke-PoshspecExpression @params
}
This way, a user could test any property of the WebSitebinding object they choose with this one function.
If the Property is going to be static like in AppPoolState
then just include it in the expression. It's perfectly functional to send it to Get-PoshspecParam
like you did, it just adds the value of $Property
to the test name and that doesn't have a lot of value in this case since you always test the same property.
$expression = {Get-WebAppPoolState -Name '$Target' -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Value}
So I see what you mean now, but where is your black voodoo magic that knows where to use Property I get how its used and why its used but where in the hell do you pass it over to Invoke-PoshSpec and Get-Poshspec that is lost on me
@beaudryj The Property parameter passed to the public function is used to build the Expression property of the output object of the Get-PoshspecParam function. It is splatted (i think that's how you say that) to the Get-PoshspecParam function and then the output object is passed to Invoke-PoshspecExpression for parsing. Ultimately, the Property parameter of the public function makes it to the Invoke-PoshspecExpression as part of the string in the Expression property of the object coming from Get-PoshspecParam. @cdhunt Did I explain that correctly?
Yes, it's through spatting the PSBoundParams. Basically, we just pass the public function parameters through to the private function. The public functions really only serve as a way to tweak parameter enforcement and expose help. That's why every public function has to use the same parameter names.
if ($PSBoundParameters.ContainsKey("Property"))
{
$expressionString += " | Select-Object -ExpandProperty '$Property'"
You could let Get-PoshspecParams add the select-object
for you, but, like I said that really makes more sense if you are exposing Properties to the user to set.
Ahhhhh! I was over thinking that
So I attempted to add the qualifier as we had talked about
webbinding sitename http bindinginfo | {should be *:80:}
however it did not seem to work well when I had the mixed types that weren't using the qualifier.
My guess is you need to reorder you parameters so Qualifier is Position=2
and Property is Position=3
. I think you would want to specify http/https so that you could specifically test either.
I don't have a strong opinion either way for creating two separate functions or just one. I guess it depends on how much complexity it adds to have one function that tries to cover all website configuration options.
You can also add more parameters to your function if that helps you determine which scriptblock to pass to Get-PoshspecParam
.
Just remember that the goal of Poshspec was to make writing tests easier.
@beaudryj If you can add tests, this PR looks good to merge.
sounds good, I got distracted last night
Added Features Requested in https://github.com/Ticketmaster/poshspec/issues/5