Last active
July 21, 2020 16:00
-
-
Save ramonjoaquim/fae014f546dd7c00e0dd06c979a3dc7a to your computer and use it in GitHub Desktop.
invoke private method to mock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.Linq; | |
using System.Reflection; | |
using Microsoft.EntityFrameworkCore; | |
using Moq; | |
namespace TestExamples01.Setup | |
{ | |
public class Setup | |
{ | |
public static object InvokePrivateMethod<T>(object classInstance, string nameMethod, object[] parameters) where T : class | |
{ | |
var methodInfo = typeof(T).GetMethod(nameMethod, BindingFlags.NonPublic | BindingFlags.Instance); | |
return methodInfo?.Invoke(classInstance, parameters); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment