microsoft-fakes

Running a test using Shims on a Visual Studio 2013 Test Agent

最后都变了- 提交于 2020-03-21 16:10:17
问题 I have found various iterations of this question across a number of websites, however so far I have not found anything that provides a full answer that worked. I have just set up a number of Visual Studio Test Agents that all appear to be behaving and running most of the unit tests we are planning on initially running on them. However when I came to checking one of the unit tests it is failing on the line: using (ShimsContext.Create()) , With the stack trace: Result Message: Microsoft

ShimNotImplementedException after upgrading Visual Studio 2013 and Microsoft Fakes v12

五迷三道 提交于 2020-01-25 10:59:06
问题 We are utilizing Microsoft Fakes with Visual Studio 2013. After updating to Visual Studio 2013 Update-4 or Update-5, we are getting ShimNotImplementedException 's in our tests. We have followed instructions found in other SOF questions and turned off the SpecificVersion of our Microsoft.QualityTools.Testing.Fakes references. This allows a compile but the tests still fail when run. 回答1: The hint we needed to solve this was found in MSDN forums. The underlying issue is that the legacy tests did

ShimNotImplementedException after upgrading Visual Studio 2013 and Microsoft Fakes v12

假如想象 提交于 2020-01-25 10:59:05
问题 We are utilizing Microsoft Fakes with Visual Studio 2013. After updating to Visual Studio 2013 Update-4 or Update-5, we are getting ShimNotImplementedException 's in our tests. We have followed instructions found in other SOF questions and turned off the SpecificVersion of our Microsoft.QualityTools.Testing.Fakes references. This allows a compile but the tests still fail when run. 回答1: The hint we needed to solve this was found in MSDN forums. The underlying issue is that the legacy tests did

How to create a fake FtpWebResponse

南笙酒味 提交于 2020-01-05 08:34:46
问题 I am trying to fake an FtpWebRequest.GetResponse() for an integration test, but without using a server. What I have been trying to do is the simple return a fake FtpWebResponse but, you are not allowed to access the constructor for the FtpWebResponse because it is internal. Here is my code: Production code: using (FtpWebResponse response = (FtpWebResponse) ftpWebRequest.GetResponse()) { ftpResponse = new FtpResponse(response.StatusDescription, false); } Test fake I am trying to use to return

How to use Microsoft Fakes Assemblies on Process.Start

99封情书 提交于 2020-01-03 16:16:10
问题 I would like to mock the System.Diagnostics.Process.Start call, so i added a Fakes Assembly for the System Assembly. The problem is that Start is a static method on System.Diagnostics.Process so i'm not getting a shim to be able to hock on a delegate for the Start method. What is the correct way of doing this? 回答1: So first of all you need to generate the Shim for the Process class. After you create the Fakes for System you should see a folder called 'Fakes'. Inside that folder you need to

Error “The extern alias 'snh' was not specified in a /reference option ” in a C# test project using Microsoft Fakes

♀尐吖头ヾ 提交于 2020-01-02 01:36:27
问题 I have a C# test project that uses Microsoft fakes. An external library ( abc.dll ) that the project is referencing was recently updated to .net standard 2.0 . After updating the abc.dll library reference to the latest version, the test project doesn't build any more and also doesn't generate the fake assembly for that library ( dll ). I see the following error in the generated .csproj file. The external alias 'snh' was not specified in a /reference option I looked at the generated . csproj

How to mock/isolate internal classes in VS 2012 with Fakes Framework shims?

情到浓时终转凉″ 提交于 2020-01-01 08:51:53
问题 So, the issue is that I have a bunch of internal classes in my assembly that are used by the class I want to test. Since accessors have been removed from VS2012, I'm fine with using [InternalsVisibleTo] and that works great... except when I try to shimify my internal classes, they are not visible to the Fakes framework. I should also note that the particular class I am dealing with is a static class with static methods, and I don't really want to refactor everything to use interfaces (and

How to mock/isolate internal classes in VS 2012 with Fakes Framework shims?

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-01 08:51:15
问题 So, the issue is that I have a bunch of internal classes in my assembly that are used by the class I want to test. Since accessors have been removed from VS2012, I'm fine with using [InternalsVisibleTo] and that works great... except when I try to shimify my internal classes, they are not visible to the Fakes framework. I should also note that the particular class I am dealing with is a static class with static methods, and I don't really want to refactor everything to use interfaces (and

How to mock/fake SmtpClient in a UnitTest?

大兔子大兔子 提交于 2020-01-01 04:16:27
问题 I want to use it to fake System.Net.Mail.SmtpClient in a MS-Test UnitTest. Therefor I added a Fakes Assembmly of System.dll. Then I create a ShimsContext and a StubSmtpClient . using (ShimsContext.Create()) { StubSmtpClient client = new StubSmtpClient(); } But what do I do with it? The ultimate goal would be to write a Test which expects that the send Method is called with a object of MailMessage . 回答1: You can create an interface which will expose functions that will be used from SmtpClient