// // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. // #nullable disable using System.Reflection; using Moq.Language; using Moq.Language.Flow; namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Utility { public static class MoqExtensions { public delegate void OutAction(out TOut outVal); public delegate void OutAction(T1 arg1, out TOut outVal); public static IReturnsThrows OutCallback( this ICallback mock, OutAction action) where TMock : class { return OutCallbackInternal(mock, action); } public static IReturnsThrows OutCallback( this ICallback mock, OutAction action) where TMock : class { return OutCallbackInternal(mock, action); } private static IReturnsThrows OutCallbackInternal( ICallback mock, object action) where TMock : class { typeof(ICallback).GetTypeInfo() .Assembly.GetType("Moq.MethodCall") .GetMethod("SetCallbackWithArguments", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Instance) .Invoke(mock, new[] { action }); return mock as IReturnsThrows; } } }