microsoft-fakes

Microsoft.Fakes won't run in normal unit test contexts

╄→гoц情女王★ 提交于 2019-12-30 02:42:26
问题 I'm using a simple proof-of-concept Fakes nUnit test: [Test] public void TestFakes() { using (var ctx = ShimsContext.Create()) { System.Fakes.ShimDateTime.NowGet = () => { return new DateTime(2000, 1, 1); }; Assert.That(DateTime.Now.Year, Is.EqualTo(2000)); } } This test runs in the Visual Studio Test Explorer, but doesn't run in: nUnit GUI nUnit console The JetBrains test runner (dotCover OR Resharper) TestDriven.net test runner In each of these, I receive the following error: Microsoft

MS Fakes Static Method that Returns Class with Private Constructor

岁酱吖の 提交于 2019-12-25 04:22:52
问题 I'm trying to fake/stub out System.DirectoryServices.ActiveDirectory.Domain.GetComputerDomain().Name I'd like to know how to assign GetComputerDomain to return a Domain with a Name of "TestDomain". I can return a null domain as follows: System.DirectoryServices.ActiveDirectory.Fakes.ShimDomain .GetComputerDomain = () => { return null; }; But I think the main issue is that the Domain class does not have a public constructor so I can't do the following: System.DirectoryServices.ActiveDirectory

How to Unit Test without testing private methods calling database

青春壹個敷衍的年華 提交于 2019-12-25 01:21:49
问题 I am facing difficulties understanding how to well unit-test my application. Let's say I have a public method publicMethod() calling several private methods holding the business logic. I learned that private methods shouldn't be unit-tested, so I need to unit-test publicMethod() . The problem is that my private methods at some point access the database. As I am not unit-testing the private methods, I cannot fake the database call. What I can do is fake the private method call, but then if I

MSFakes Naming Convention to match Generic class?

别等时光非礼了梦想. 提交于 2019-12-24 00:55:36
问题 I have a class called MyClass , and a generic version called MyClass<C> . Using fakes, I want to generate a shim of JUST MyClass<C> , and not MyClass . I originally tried: <Fakes xmlns="http://schemas.microsoft.com/fakes/2011/"> <Assembly Name="XXXX" Version="#.##.###"/> <ShimGeneration> <Clear/> <Add FullName="MyClass!"/> </ShimGeneration> </Fakes> This generated shims for MyClass , but not MyClass<C> . If I change the ! to a *, it does match MyClass<C> . This leads me to believe there is

Microsoft Fakes (Shims and / or Stubs) on a c# method with SQL code

╄→гoц情女王★ 提交于 2019-12-23 17:15:20
问题 I am trying to learn a bit more about Unit Testing, using out-of-the-box functionality (i believe it is MSTest.exe), and Microsoft Fakes (stubs and Shims). I am using Visual Studio 2012 Ultimate and .Net 4.5 Framework. Given the following code that calls a stored procedure (SQL Server) which returns a single output value (for simplicity): public string GetSomeDatabaseValue() { string someValue = String.Empty; SqlParameter paramater = new SqlParameter(); paramater.ParameterName = "

Visual Studio 2015, Microsoft Fakes and System.Security.Claims.Claim

北城余情 提交于 2019-12-20 01:38:11
问题 I have an interface in a .NET 4.5 (not 4.6) class library, public interface IBrokenFakeInterface { Claim WhyWontItGenerateFakeOfThisInterface(); } In my unit test project (MSTest) when I have added the Fakes for the appropriate assembly containing this interface, I get compiler warning that says it cannot generate the stub. Warning: Cannot generate stub for ClassLibrary1.IBrokenFakeInterface: method System.Security.Claims.Claim ClassLibrary1.IBrokenFakeInterface

MSBuild 15 - The type or namespace 'Fakes' does not exist in the namespace

[亡魂溺海] 提交于 2019-12-19 06:20:04
问题 I'm trying to set up automated builds and unit testing for a project which uses the Fakes library for it's unit tests. The project builds and tests fine on my Windows 10 PC (VS 2017 Enterprise installed), however using the same command to compile the project on the build server (also windows 10 with VS 2017 Enterprise) gives several errors about the Fakes not existing. The exact errors look like this: XControllerTests.cs(10,20): error CS0234: The type or namespace 'Fakes' does not exist in

UnitTestIsolationException: Throws Exception while running Shims test in Release/Debug mode

假装没事ソ 提交于 2019-12-18 18:16:11
问题 I am trying to run this unit test using Microsoft Shims, but it throws me exception in Shims.Context.Create(); method. Environment: VS 2012, Win2K8 R2 namespace MyShimsUnitTest { [TestClass] public class MyUnitTest { [TestMethod] public void GetCurrentYear() { using (Microsoft.QualityTools.Testing.Fakes.ShimsContext.Create()) { // Some Logic... } } } } Detailed Exception: Result Message: Test method MyShimsUnitTest.MyUnitTest.GetCurrentYear threw exception: Microsoft.QualityTools.Testing

MS Fakes unit tests failing after Visual Studio 2013 Update 4

夙愿已清 提交于 2019-12-18 02:17:52
问题 I have recently upgrade from Microsoft Visual Studio 2013 Update 3 (Premium edition) to Microsoft Visual Studio 2013 Update 4 (Premium edition) and now my existing unit test projects have stopped compiling. It fails with the error: The type 'Microsoft.QualityTools.Testing.Fakes.Stubs.StubBase`1' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.QualityTools.Testing.Fakes, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' We,

MS Fakes unit tests failing after Visual Studio 2013 Update 4

血红的双手。 提交于 2019-12-18 02:17:12
问题 I have recently upgrade from Microsoft Visual Studio 2013 Update 3 (Premium edition) to Microsoft Visual Studio 2013 Update 4 (Premium edition) and now my existing unit test projects have stopped compiling. It fails with the error: The type 'Microsoft.QualityTools.Testing.Fakes.Stubs.StubBase`1' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.QualityTools.Testing.Fakes, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' We,