diff --git a/DSCResources/MSFT_xDNSServerAddress/MSFT_xDNSServerAddress.psm1 b/DSCResources/MSFT_xDNSServerAddress/MSFT_xDNSServerAddress.psm1 index a7bc13b6..294b5656 100644 --- a/DSCResources/MSFT_xDNSServerAddress/MSFT_xDNSServerAddress.psm1 +++ b/DSCResources/MSFT_xDNSServerAddress/MSFT_xDNSServerAddress.psm1 @@ -11,6 +11,7 @@ ###################################################################################### function Get-TargetResource { + [OutputType([System.Collections.Hashtable])] param ( [Parameter(Mandatory)] @@ -21,8 +22,9 @@ function Get-TargetResource [ValidateNotNullOrEmpty()] [String]$InterfaceAlias, + [Parameter(Mandatory)] [ValidateSet("IPv4", "IPv6")] - [String]$AddressFamily = "IPv4" + [String]$AddressFamily ) @@ -52,8 +54,9 @@ function Set-TargetResource [ValidateNotNullOrEmpty()] [String]$InterfaceAlias, + [Parameter(Mandatory)] [ValidateSet("IPv4", "IPv6")] - [String]$AddressFamily = "IPv4" + [String]$AddressFamily ) ValidateProperties @PSBoundParameters -Apply @@ -65,6 +68,7 @@ function Set-TargetResource ###################################################################################### function Test-TargetResource { + [OutputType([System.Boolean])] param ( [Parameter(Mandatory)] @@ -75,8 +79,9 @@ function Test-TargetResource [ValidateNotNullOrEmpty()] [String]$InterfaceAlias, + [Parameter(Mandatory)] [ValidateSet("IPv4", "IPv6")] - [String]$AddressFamily = "IPv4" + [String]$AddressFamily ) ValidateProperties @PSBoundParameters @@ -99,6 +104,7 @@ function ValidateProperties [ValidateNotNullOrEmpty()] [String]$InterfaceAlias, + [Parameter(Mandatory)] [ValidateSet("IPv4", "IPv6")] [String]$AddressFamily, diff --git a/DSCResources/MSFT_xDNSServerAddress/MSFT_xDNSServerAddress.schema.mof b/DSCResources/MSFT_xDNSServerAddress/MSFT_xDNSServerAddress.schema.mof index 5431748b..53b31d67 100644 --- a/DSCResources/MSFT_xDNSServerAddress/MSFT_xDNSServerAddress.schema.mof +++ b/DSCResources/MSFT_xDNSServerAddress/MSFT_xDNSServerAddress.schema.mof @@ -1,7 +1,7 @@ -[ClassVersion("1.0.0"), FriendlyName("xDNSServerAddress")] -class MSFT_xDNSServerAddress : OMI_BaseResource -{ - [Required] string Address[]; - [Key] string InterfaceAlias; - [Write,ValueMap{"IPv4", "IPv6"},Values{"IPv4", "IPv6"}] string AddressFamily; -}; +[ClassVersion("1.0.0"), FriendlyName("xDNSServerAddress")] +class MSFT_xDNSServerAddress : OMI_BaseResource +{ + [Required] string Address[]; + [Key] string InterfaceAlias; + [Key,Write,ValueMap{"IPv4", "IPv6"},Values{"IPv4", "IPv6"}] string AddressFamily; +}; diff --git a/README.md b/README.md index 7bfdb208..b0f6cb39 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,10 @@ Please check out common DSC Resources [contributing guidelines](https://github.c ## Versions +### Unreleased +* Update to xDNSServerAddress to allow both IPv4 and IPv6 DNS addresses to be assigned to an + interface. xDNSServerAddress AddressFamily parameter has been changed to mandatory. + ### 2.2.0.0 * Changes in xFirewall resources to meet Test-xDscResource criteria diff --git a/Tests/MSFT_xDNSServerAddress.Tests.ps1 b/Tests/MSFT_xDNSServerAddress.Tests.ps1 new file mode 100644 index 00000000..cd041370 --- /dev/null +++ b/Tests/MSFT_xDNSServerAddress.Tests.ps1 @@ -0,0 +1,100 @@ +$here = Split-Path -Parent $MyInvocation.MyCommand.Path + +if (Get-Module MSFT_xDNSServerAddress -All) +{ + Get-Module MSFT_xDNSServerAddress -All | Remove-Module +} + +Import-Module -Name $PSScriptRoot\..\DSCResources\MSFT_xDNSServerAddress -Force -DisableNameChecking + +InModuleScope MSFT_xDNSServerAddress { + + Describe 'Get-TargetResource' { + + #region Mocks + Mock Get-DnsClientServerAddress -MockWith { + + [PSCustomObject]@{ + ServerAddresses = '192.168.0.1' + InterfaceAlias = 'Ethernet' + AddressFamily = 'IPv4' + } + } + #endregion + + Context 'comparing IPAddress' { + It 'should return true' { + + $Splat = @{ + Address = '192.168.0.1' + InterfaceAlias = 'Ethernet' + AddressFamily = 'IPv4' + } + $Result = Get-TargetResource @Splat + $Result.IPAddress | Should Be $Splat.IPAddress + } + } + } + + + Describe 'ValidateProperties' { + + #region Mocks + Mock Get-DnsClientServerAddress -MockWith { + + [PSCustomObject]@{ + ServerAddresses = '192.168.0.1' + InterfaceAlias = 'Ethernet' + AddressFamily = 'IPv4' + } + } + + Mock Set-DnsClientServerAddress -MockWith {} + #endregion + + Context 'invoking without -Apply switch' { + + It 'should be $false' { + $Splat = @{ + Address = '10.0.0.2' + InterfaceAlias = 'Ethernet' + AddressFamily = 'IPv4' + } + $Result = ValidateProperties @Splat + $Result | Should Be $false + } + + It 'should be $true' { + $Splat = @{ + Address = '192.168.0.1' + InterfaceAlias = 'Ethernet' + AddressFamily = 'IPv4' + } + $Result = ValidateProperties @Splat + $Result | Should Be $true + } + + It 'should call Get-DnsClientServerAddress once' { + Assert-MockCalled -commandName Get-DnsClientServerAddress + } + } + + Context 'invoking with -Apply switch' { + + It 'should be $null' { + $Splat = @{ + Address = '10.0.0.2' + InterfaceAlias = 'Ethernet' + AddressFamily = 'IPv4' + } + $Result = ValidateProperties @Splat -Apply + $Result | Should BeNullOrEmpty + } + + It 'should call all the mocks' { + Assert-MockCalled -commandName Get-DnsClientServerAddress + Assert-MockCalled -commandName Set-DnsClientServerAddress + } + } + } +}