Skip to content

Generated test for VOID method still tests for a return type #122

Open
@Stephanevg

Description

@Stephanevg

Regarding this class below.

The SetVersionType (and for that matter all the void methods) still have a test to test their return type.

When a method has no return type the test to test for the type should not be generated.

See use case below.

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

    PCCPAckage(){

    }

    PccPAckage([String]$Path){
        $P = [System.Io.DirectoryInfo]::New($Path)
        If($P.Exists){
            if(!($P.Name.ToString().ToUpper().StartsWith("PCC.CHK"))){
                Throw "the module folder doesn't start with the required prefexi 'PCC.CHK'!"
            }
            $this.Path = $P
            $this.Name = $p.Name.ToUpper()
            $this.SetValues()
        }else{
            Throw "$($Path) not present"
        }
    }

    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.FullName -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
    }
}

See the _SEtVersion() test

#Public Method
It '[PCCPackage] --> _SetVersion() :  - should return type []' {

# -- Arrange

# -- Act

$Instance = [PCCPackage]::New()
# -- Assert

($Instance._SetVersion()).GetType().Name | should be 

} #End It Block

Metadata

Metadata

Assignees

No one assigned

    Labels

    Begginer friendlybugSomething isn't workinghacktoberfestGood first use to gain a PR for Hacktoberfest

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions