Skip to content

Commit

Permalink
DatabasePermission/ServerPermission: Fix ToString() method (#1997)
Browse files Browse the repository at this point in the history
  • Loading branch information
johlju authored Jan 19, 2024
1 parent a11aee3 commit c26c06f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix unit test FailedRemoveAvailabilityGroupReplica
- SqlAgentOperator
- Integration test for changing e-mail address on an existing operator.
- `DatabasePermission`
- New method ToString() for making verbose output better.
- `ServerPermission`
- New method ToString() for making verbose output better.

### Changed

Expand Down
27 changes: 27 additions & 0 deletions source/Classes/002.DatabasePermission.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
evaluate during runtime so that no two states are enforcing the same
permission.
This class cannot inherit a parent class. If it would have, then the
DSC resource (e.g. SqlDatabasePermission) that uses the complex type fail
with the error:
"The 'Permission' property with type 'DatabasePermission' of DSC resource
class 'SqlDatabasePermission' is not supported."
The method Equals() returns $false if type is not the same on both sides
of the comparison. There was a thought to throw an exception if the object
being compared was of another type, but since there was issues with using
Expand All @@ -32,6 +39,19 @@
the for example [ServerPermission] to the right side, then the left side
array is filtered with the matching values on the right side. This is the
normal behavior for other types.
.EXAMPLE
[DatabasePermission] @{}
Initializes a new instance of the DatabasePermission class without any
property values.
.EXAMPLE
[DatabasePermission] @{ State = 'Grant'; Permission = @('Connect', 'Select') }
Initializes a new instance of the DatabasePermission class with property
values.
#>
class DatabasePermission : IComparable, System.IEquatable[Object]
{
Expand Down Expand Up @@ -245,4 +265,11 @@ class DatabasePermission : IComparable, System.IEquatable[Object]

return $returnValue
}

[System.String] ToString()
{
$concatenatedPermission = ($this.Permission | Sort-Object) -join ', '

return ('{0}: {1}' -f $this.State, $concatenatedPermission)
}
}
27 changes: 26 additions & 1 deletion source/Classes/002.ServerPermission.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
evaluate during runtime so that no two states are enforcing the same
permission.
This class cannot inherit a parent class. If it would have, then the
DSC resource (e.g. SqlServerPermission) that uses the complex type fail
with the error:
"The 'Permission' property with type 'ServerPermission' of DSC resource
class 'SqlServerPermission' is not supported."
The method Equals() returns $false if type is not the same on both sides
of the comparison. There was a thought to throw an exception if the object
being compared was of another type, but since there was issues with using
Expand All @@ -32,6 +39,18 @@
the for example [ServerPermission] to the right side, then the left side
array is filtered with the matching values on the right side. This is the
normal behavior for other types.
.EXAMPLE
[ServerPermission] @{}
Initializes a new instance of the ServerPermission class without any
property values.
.EXAMPLE
[ServerPermission] @{ State = 'Grant'; Permission = @('ConnectSql', 'ViewServerState') }
Initializes a new instance of the ServerPermission class with property
values.
#>
class ServerPermission : IComparable, System.IEquatable[Object]
{
Expand Down Expand Up @@ -81,7 +100,6 @@ class ServerPermission : IComparable, System.IEquatable[Object]
[System.String[]]
$Permission


ServerPermission ()
{
}
Expand Down Expand Up @@ -184,4 +202,11 @@ class ServerPermission : IComparable, System.IEquatable[Object]

return $returnValue
}

[System.String] ToString()
{
$concatenatedPermission = ($this.Permission | Sort-Object) -join ', '

return ('{0}: {1}' -f $this.State, $concatenatedPermission)
}
}

0 comments on commit c26c06f

Please sign in to comment.