Completed
Last Updated: 02 Feb 2021 09:35 by ADMIN
Karina
Created on: 29 Jul 2020 13:51
Type: Bug Report
1
Mock a local function inside an async method

I have a class, which has a private async method, which has a local function, like the following example

 

internal class TestClass

{

 ......

        private async Task<bool> TestPrivateMethod()
        {
            var x = await TestLocalFunction();
            return x;

            async Task<bool> TestLocalFunction()
            {
                await Task.Delay(5);
                return true;
            }
 }

 

When I try to mock the local function, thows an error "System.MissingMemberException : C# 7 local function 'TestLocalFunction' with the given signature was not found inside method 'TestPrivateMethod'"

 

var testClassInstance = Mock.Create<TestClass>(Behavior.CallOriginal);

Mock.Local.Function.Arrange<Task<bool>>(testClassInstance, "TestPrivateMethod", "TestLocalFunction").Returns(Task.FromResult(true));

 

2 comments
ADMIN
Mihail
Posted on: 02 Feb 2021 09:34

Hello Karina,

The issue was fixed with the R3 SP2 2020 and it is also available with the latest official release R1 2021 version(2021.1.115.1). You could try it and get back to us if you encounter any issues.

Regards,
Mihail
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

ADMIN
Ivo
Posted on: 30 Jul 2020 09:21

Hello Karina,

I can confirm your observations - due to an issue in discovery procedure, JustMock is unable to mock local functions declared inside async methods. I am afraid there is no workaround for that failure, so it requires code changes in order to be fixed. I am unable to give you an exact timeframe for releasing the solution, usually, we prioritize our backlog based on the customers' demand. In appreciation for your involvement, I have updated your Telerik points.

I would like to apologize for the inconvenience and hope that we manage to fix the issue soon.

Regards,
Ivo
Progress Telerik