我在 Visual Studio 2010 中设置了一个简单的测试项目。对于单元测试,我使用 nunit 2.6.1 并模拟通过 NuGet 安装的 FakeItEasy 1.7.4582.63。
\n\n我尝试使用以下代码伪造 DbDataAdapter:
\n\nusing System.Data.Common;\nusing FakeItEasy;\nusing NUnit.Framework;\n\nnamespace huhu\n{\n [TestFixture]\n public class Class1\n {\n [Test]\n public void test1()\n {\n A.Fake<DbDataAdapter>();\n }\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n当我使用 .NET Framework 3.5 运行测试时,一切正常并且 test1 将通过。但是,当我将框架版本设置为 .NET 4.0 时,出现以下异常:
\n\nFakeItEasy.Core.FakeCreationException : \n Failed to create fake of type "System.Data.Common.DbDataAdapter".\n\n Below is a list of reasons for failure per attempted constructor:\n No constructor arguments failed:\n No default constructor was found on the type System.Data.Common.DbDataAdapter.\n …Run Code Online (Sandbox Code Playgroud)