In Development
Last Updated: 20 Oct 2020 10:17 by ADMIN
Created on: 29 Jul 2020 13:51
Type: Bug Report
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));


1 comment
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.

Progress Telerik