Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated Tests assumes that the a parameterless constructor is avaiable. #121

Open
Stephanevg opened this issue Sep 18, 2019 · 0 comments

Comments

@Stephanevg
Copy link
Owner

This is not always the case. See example below.

Class PCCPackage {
    [String]$Name
    [version]$Version
    [system.io.DirectoryInfo]$Path
    [String]$OS
    [String]$Type
    [String]$Platform

    PCCPackage([String]$Name,[String]$Path){
        $this.Name = $Name
        $this.Path = $Path
        $This.SetValues()
        
    }

    SetValues(){
        $this._SetVersion()
        $this._SetPlatform()
        $this._SetOS()
        $this._SetType()
    }

    Hidden _SetVersion(){
        try{

            $ver = (Get-Module $this.Path -ListAvailable -ErrorAction Stop).Version.ToString() 
        }Catch{
            $ver = $null
        }
        $this.Version = $ver
    }

    hidden _SetPlatform(){
        $p =  $this.Name.Split(".")[2]
        $This.Platform =$p
    }

    hidden _SetOS(){
        
        $this.OS = $this.Name.Split(".")[3]
    }

    Hidden _SetType(){
        $t = $this.Name.Split(".")[4]
        $This.Type = $t
    }

    Hidden [String] GetOS(){
        return $this.Os
         
    }

    [String] GetPath(){
        REturn $this.Path.Full
    }
    [version] GetVersion(){
        return $this.version
    }
}

generates

Describing [PCCPackage]-[Constructors]
    [-] [PCCPackage]-[Constructor]([String]Name,[String]Path) should Not Throw 98ms
      Expected no exception to be thrown, but an exception "Exception setting "Path": "Cannot convert value "" to type "System.IO.DirectoryInfo". Error: "The path is not of a legal form.""" was thrown from C:\Users\taavast3\OneDrive\Repo\Projects\Clients\ee\ESC\PCCComplianceChecks\Code\Classes\Class.PCCPackage.ps1:11 char:9
          +         $this.Path = $Path
          +         ~~~~~~~~~~~~~~~~~~.
      18: {[PCCPackage]::New($Name,$Path)} | Should Not Throw
      at <ScriptBlock>, C:\Users\taavast3\OneDrive\Repo\Projects\Clients\hh\ESC\PCCComplianceChecks\Code\Classes\Class.PCCPackage.Tests.Ps1: line 18

  Describing [PCCPackage]-[Methods]
    [-] [PCCPackage] --> SetValues() :  - should Not Throw 28ms
      MethodException: Cannot find an overload for "new" and the argument count: "0".
      at <ScriptBlock>, C:\Users\taavast3\OneDrive\Repo\Projects\Clients\hh\ESC\PCCComplianceChecks\Code\Classes\Class.PCCPackage.Tests.Ps1: line 33
    [-] [PCCPackage] --> SetValues() :  - should return type [] 30ms
      MethodException: Cannot find an overload for "new" and the argument count: "0".
      at <ScriptBlock>, C:\Users\taavast3\OneDrive\Repo\Projects\Clients\hh\ESC\PCCComplianceChecks\Code\Classes\Class.PCCPackage.Tests.Ps1: line 48
    [-] [PCCPackage] --> _SetVersion() :  - should Not Throw 32ms

Here there is no parameterless constructor (I'll add in my production code) but Write-CUPesterTEsts should assume that a parameterless constructor is present.

If no parameterless constructor is present, is should use the first one of the list available (see Get-CUConstructor)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant