using System.Reflection; namespace Notesnook.API.Tests; // a fake for interfaces: methods without a handler throw NotImplementedException public class Stub : DispatchProxy where T : class { private Dictionary> handlers = []; public static T Create(params (string Method, Func Handler)[] handlers) { var proxy = Create>(); ((Stub)(object)proxy).handlers = handlers.ToDictionary((h) => h.Method, (h) => h.Handler); return proxy; } protected override object? Invoke(MethodInfo? method, object?[]? args) => handlers.TryGetValue(method!.Name, out var handler) ? handler(args ?? []) : throw new NotImplementedException(method.Name); }