dsccommunity/DnsServerDsc

xDnsRecordMx: Unit test missing Mock

Sudman1 opened this issue · 2 comments

Details of the scenario you tried and the problem that is occurring

Cannot throw Get-DnsServerResourceRecord Stub call, as it seems one of the MSFT_xDnsRecordMx\Set-TargetResource tests may not have mocked it.

Verbose logs showing the problem

...
  Describing MSFT_xDnsRecordMx\Set-TargetResource

    Context When managing MX type DNS record
      [-] Calls Add-DnsServerResourceRecord in the set method when Ensure is Present 98ms
        RuntimeException: Get-DnsServerResourceRecord: StubNotImplemented
        at Get-DnsServerResourceRecord, C:\Users\james\Documents\code\xDnsServer\tests\Unit\Stubs\DnsServer.psm1: line 5662
        at Set-TargetResource, C:\Users\james\Documents\code\xDnsServer\output\xDnsServer\0.0.1\DSCResources\MSFT_xDnsRecordMx\MSFT_xDnsRecordMx.psm1: line 163
        at <ScriptBlock>, C:\Users\james\Documents\code\xDnsServer\tests\Unit\MSFT_xDnsRecordMx.Tests.ps1: line 156
VERBOSE: Updating DNS record 'MX' for target 'mail.contoso.com.' in zone 'contoso.com' on 'localhost'.
...

Suggested solution to the issue

Verify that a mock for Get-DnsServerResourceRecord exists within the scope of the test (prior to being called) at line 156

The content of the stub should be changed from (which shows the missing mock as above)

Write-Verbose ('{0}: StubNotImplemented' -f $MyInvocation.MyCommand)

to

throw ('{0}: StubNotImplemented' -f $MyInvocation.MyCommand)

The resource have been deprecated and the unit test has been remove so we can add the throw back in the stub.