• Is it possible to pass incoming params to a codeblock using reflection?

    From Jafar@21:1/5 to All on Wed Jan 6 04:48:25 2021
    I am trying to create some fakes inside Visual Objects in order to rule out some dependencies while unit testing. Here is some example method that uses CodeBlocks to achieve that:

    METHOD ValidateTimeString(stringToValidate AS STRING) AS ValidationResultModel CLASS FakeTimeValidator
    IF !Empty(FakeValidateTimeStringFunction)
    RETURN Eval(FakeValidateTimeStringFunction, stringToValidate)
    ENDIF
    RETURN SUPER:ValidateTimeString(stringToValidate)

    I would like to make this more generic however, so that incoming arguments are passed automatically to subsequent CodeBlocks. Is there some method or code sample I can use to pass incoming params to a codeblock. I woud like to have something like a
    GetFakeOutput function, but just don't know how to do this:

    METHOD ValidateTimeString(stringToValidate AS STRING) AS ValidationResultModel CLASS FakeTimeValidator
    RETURN GetFakeOutput(SELF, GetCurrentMethodName(), GetCurrentMethodValues())

    FUNCTION GetFakeOutput(instance AS OBJECT, methodToFake AS SYMBOL, inputParams AS ARRAY) AS CODEBLOCK
    // I have no clue what to put here:
    LOCAL fakeCodeBlock := ??? AS CODEBLOCK
    RETURN fakedCodeBlock

    Thanks in advance.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jafar@21:1/5 to All on Wed Jan 6 04:53:44 2021
    I am trying to create some fakes inside Visual Objects in order to rule out some dependencies while unit testing. Here is some example method that uses CodeBlocks to achieve that:

    METHOD ValidateTimeString(stringToValidate AS STRING) AS ValidationResultModel CLASS FakeTimeValidator
    IF !Empty(FakeValidateTimeStringFunction)
    RETURN Eval(FakeValidateTimeStringFunction, stringToValidate)
    ENDIF
    RETURN SUPER:ValidateTimeString(stringToValidate)

    I would like to make this more generic however, so that incoming arguments are passed automatically to subsequent CodeBlocks. Is there some method or code sample I can use to pass incoming params to a codeblock. I woud like to have something like a
    GetFakeOutput function, but just don't know how to do this:

    METHOD ValidateTimeString(stringToValidate AS STRING) AS ValidationResultModel CLASS FakeTimeValidator
    RETURN GetFakeOutput(SELF, GetCurrentMethodName(), GetCurrentMethodValues())

    FUNCTION GetCurrentMethodName() AS SYMBOL STRICT
    // I already know how to do this!
    RETURN AsSymbol(SplitString(ProcName(1), ":", FALSE)[2])

    FUNCTION GetCurrentMethodValues() AS ARRAY
    // I have no clue what to put here:
    LOCAL values := ??? AS ARRAY
    RETURN values

    FUNCTION GetFakeOutput(instance AS OBJECT, methodToFake AS SYMBOL, inputParams AS ARRAY) AS CODEBLOCK
    // I have no clue what to put here:
    LOCAL fakeCodeBlock := ??? AS CODEBLOCK
    RETURN fakedCodeBlock

    Thanks in advance.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)