TestCases with Proxy Values

Welcome Forums Pester TestCases with Proxy Values

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
1 year, 7 months ago.

  • Author
    Posts
  • #75866

    Participant
    Points: 58
    Rank: Member

    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

    Participant
    Points: 22
    Rank: Member

    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

    Participant
    Points: 58
    Rank: Member

    Perfect.. thank you for the Tip much appreciated Adam

The topic ‘TestCases with Proxy Values’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort