TestCases with Proxy Values

This topic contains 2 replies, has 2 voices, and was last updated by  Thom Schumacher 3 months ago.

  • Author
    Posts
  • #75866

    Thom Schumacher
    Participant

    I have a need to have a test case call a web service proxy and the results used in my pester script here is what I'm trying to do.

    the function requires a proxy so that you can call methods. I want to verify that the method I call through the proxy is returning something or better yet returns a type of: SSRSProxy.ScheduleDefinition

    My problem is every time I run the test I can't seem to figure out the right means to formulate my Test case. so that it goes to the It block properly. What am I missing?

    #---------function to be tested ---------------
    function Get-CacheOptions
    {
      param(
           [Parameter(Mandatory=$true)]
           [object]$ssrsproxy,
           [Parameter(Mandatory=$true)]
           [string]$path
      )
        $cacheOptions = $null
        $ssrsproxy.GetCacheOptions($path,[ref]$cacheOptions) | Out-Null
        if($cacheOptions.Item -is [SSRSProxy.ScheduleDefinition])
        {$cacheOptions}
        else {
            $cacheOptions = $null
        }
        
    }
    
    #----------------- test case and pester code below ------------------------
    #$ssrsproxy = New-WebServiceProxy -Uri 'http://ssrsdev/reportserver/reportservice2010.asmx' -UseDefaultCredential   -namespace 'SSRSProxy' -class 'ReportService2010' -ErrorAction 0 
    Describe 'Get-CacheOptions' {
    $testCases = @(
      @{
        ssrsproxy = (New-WebServiceProxy -Uri 'http://ssrs/reportserver/reportservice2010.asmx' -UseDefaultCredential   -namespace 'SSRSProxy' -class 'ReportService2010' -ErrorAction 0);
        path = '/Reports/DataSets/DocumentChanges'
    
      }
      @{
        ssrsproxy = (New-WebServiceProxy -Uri 'http://ssrs/reportserver/reportservice2010.asmx' -UseDefaultCredential   -namespace 'SSRSProxy' -class 'ReportService2010' -ErrorAction 0);
        path = '/Reports/DataSets/ColorChanges'
      }
        )
      Context 'running with arguments' {
        It 'does something' -TestCases $testCases {
          foreach($testcase in $testcases)
          {
           (get-CacheOptions -ssrsproxy $testcase.ssrsproxy -path $testcase.path).item | should exist
           #(get-CacheOptions -ssrsproxy $testcase.ssrsproxy -path $testcase.path).item | should beoftype SSRSProxy.ScheduleDefinition
          }
        }
      }
        
    }
    
  • #75868

    Adam Bertram
    Moderator

    Try below: When using test cases, there's a "built-in" foreach loop that will iterate through your $testCases array. You need to create a param block inside of the scriptblock to pass the test case parameters into.

    Describe 'Get-CacheOptions' {
    	$testCases = @(
    		@{
    			ssrsproxy = (New-WebServiceProxy -Uri 'http://ssrs/reportserver/reportservice2010.asmx' -UseDefaultCredential   -namespace 'SSRSProxy' -class 'ReportService2010' -ErrorAction 0);
    			path = '/Reports/DataSets/DocumentChanges'
    
    		}
    		@{
    			ssrsproxy = (New-WebServiceProxy -Uri 'http://ssrs/reportserver/reportservice2010.asmx' -UseDefaultCredential   -namespace 'SSRSProxy' -class 'ReportService2010' -ErrorAction 0);
    			path = '/Reports/DataSets/ColorChanges'
    		}
    	)
    	Context 'running with arguments' {
    		It 'does something' -TestCases $testCases {
    			param($ssrsproxy,$path)
    
    			(get-CacheOptions -ssrsproxy $ssrsproxy -path $path).item | should beoftype SSRSProxy.ScheduleDefinition
    		}
    	}
    }
    
  • #75869

    Thom Schumacher
    Participant

    Perfect.. thank you for the Tip much appreciated Adam

You must be logged in to reply to this topic.