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

[Write-CUPesterTest] Erro when you use [System.XXXX] as return type in method #114

Open
LaurentLienhard opened this issue Aug 2, 2019 · 4 comments

Comments

@LaurentLienhard
Copy link
Contributor

When you have a method in your class and in return value you put [System.String] or [System.Int32] (probably the others too) if you generate the tests pester it puts errors when you play them

Describing [Date]-[Methods]
    [-] [Date] --> MethodTest($Message) : [System.String] - should return type [System.String]

      Expected strings to be the same, but they were different.

      Expected length: 13

      Actual length:   6

      Strings differ at index 1.

      Expected: 'System.String'

      But was:  'String'

      83: ($Instance.MethodTest($Message)).GetType().Name | should be System.String

in the pester file you have

 #Public Method
    It '[Date] --> MethodTest($Message) : [System.String] - should return type [System.String]' {

        # -- Arrange
        [System.String]$Message = "test"

        # -- Act

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

        ($Instance.MethodTest($Message)).GetType().Name | should be System.String

    } #End It Block`

and my method is

   [System.String] MethodTest ([System.String]$Message) {
        return "Mon message est : $($Message)"
    }

Actually, the return is a String type and not [System.String]

PS > ($date.MethodTest("test")).gettype()  

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     String                                   System.Object

I think that the solution would be to add in the Write-CUPesterTest a transformation so that if it finds [System.XXXX] it transforms it into [XXXX] in pester test

@LaurentLienhard
Copy link
Contributor Author

Idea !
You can change in pester test
$resultat.GetType().name by $resultat.GetType().fullname ;-)

@LaurentLienhard
Copy link
Contributor Author

With $resultat.GetType().fullname in pester test it seems good with [System.String] or [String] as return Type 👍

@Stephanevg
Copy link
Owner

Salut @LaurentLienhard c'est quoi le statut de celui la?
Je peux le merge?

@LaurentLienhard
Copy link
Contributor Author

je pense que Oui. Lors de mes derniers tests quand j'ai fait le PR cela corrigé bien le souci entre [system.XXX] et [XXX]

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

2 participants