Moq Internal Methods
我是moq的新手并试图为下面的类实现moq测试,但是遇到了错误。
1 2 3 4 | public class ClassToTest { internal Func<string> GetConfigString = () => ConfigurationManager.AppSettings["somekey"].ToString() } |
测试方法
1 2 | var mock = new Mock<ClassToTest>(); mock.Setup(m => m.GetConfigString).Returns(It.IsAny<Func<string>>()); |
安装失败并显示一条消息:
expression is not a method invocation
我在
1 | [assembly:InternalsVisibleTo("DynamicProxyGenAssembly2,Publi??cKey=002400000480000??09400000006020000002??40000525341310004000??001000100c547cac37ab??d99c8db225ef2f6c8a36??02f3b3606cc9891605d0??2baa56104f4cfc0734aa??39b93bf7852f7d926665??4753cc297e7d2edfe0ba??c1cdcf9f717241550e0a??7b191195b7667bb4f64b??cb8e2121380fd1d9d46a??d2d92d2d15605093924c??ceaf74c4861eff62abf6??9b9291ed0a340e113be1??1e6a7d3113e92484cf70??45cc7")] |
将
1 2 3 4 5 6 7 | internal virtual Func<string> GetConfigString { get { return () => ConfigurationManager.AppSettings["somekey"]; } } |