microsoft-fakes

How to stub out a generic method definition in an interface using Microsoft Fakes in c#

北城余情 提交于 2019-12-14 02:36:27
问题 I have a unit test which stubs out the following interface using Microsoft Fakes: public interface ITable { Task<TableResult> Retrieve(string tableReference, string partitionKey, string rowKey); } The stub looks like this: ITable table = new MessagesAPI.Azure.Fakes.StubITable() { RetrieveStringStringString = delegate { TableResult tableResult = new TableResult(); return Task.FromResult(tableResult); } }; This works fine. However I'd like to change the interface to be more generic like so:

Build and test with TeamCity and Fakes Framework

痞子三分冷 提交于 2019-12-13 13:12:28
问题 We are running a TeamCity 8.1.4 buildserver with VS2013 installed on the machine. I've recently introduced tests which rely on the Microsoft Fakes Framework. Because of this I had to add some references to the new Fake assemblies and the Microsoft.VisualStudio.TestTools.UnitTesting assembly. This all runs fine on my local development machine. Now, when I try to build the solution on the TeamCity server, the following errors are thrown: SomeDirectory\Processors\ProcessorTests.cs(3, 27): error

Fakes stopped working after installing Visual Studio 2015

旧巷老猫 提交于 2019-12-13 12:01:21
问题 I've installed Visual Studio 2015 as a try-out and since then my unit tests that use fakes won't compile anymore, not even on VS 2013. The unit test project targets .net 4.5. Msdn suggest changing the target framework version. The error is gone if I change the targeted framework to 4.6 but I cannot update my project to .net 4.6 as every developer must update at once. Error that I get: The primary reference "mscorlib.4.0.0.0.Fakes" could not be resolved because it was built against the "

How can I stub IDBconnection

人走茶凉 提交于 2019-12-13 05:01:08
问题 I am writting Unit Test for my database connection. I have following class Public class A { public IDbConnection _dbConnection; public A() { _dbConnection = new SqlConnection(connectionStringName); } public int ExecuteNoneQuery(CommandDefination command) { return _dbConnection.Execute(command); } } I want to test this class, how I can test with Microsoft Stub/Shim I have written following code, but it is not working. [TestMethod] public void TestMethod1() { StubIDbConnection stubIDbConnection

How to set the return value of MS Fakes object?

烂漫一生 提交于 2019-12-13 02:25:51
问题 I have generated an OData Client code with the OData V4 Client Code Generator . The generated code cannot be unit tested without MS Fakes so I generated a fake assembly from it. Now I have a problem of how to actually set the return value of the methods. The "core" class in the generated code is called System : [global::Microsoft.OData.Client.OriginalNameAttribute("System")] public partial class System : global::Microsoft.OData.Client.DataServiceContext { /// <summary> /// Initialize a new

Is it OK to use MS Fakes shims with NSubstitute mocks?

送分小仙女□ 提交于 2019-12-12 21:15:13
问题 We are using NSubstitute to mock external objects for our unit tests. However many legacy classes are not called via interfaces and can't be easily replaced with mocks. I've considered to use Microsoft Fakes, but according to the answer for the question "Mock framework vs MS Fakes frameworks" " if you're already using a more full-featured mocking framework, you might feel like there are some important pieces missing from Fakes stubs." Would it be possible to use MS Fakes shims with

Unable to generate Fakes for an assembly referencing a portable class library

谁说我不能喝 提交于 2019-12-12 21:14:36
问题 I am unable to generate the Microsoft Fakes assembly for a class library (.NET 4.5) when said class library references a PCL (Portable Class Library) targetting .Net 4.5 and Silverlight 5 under Visual Studio 2013. This only occurs if the class library (.NET 4.5): Declares a type deriving from a type which can both be found in System.dll v4.0.0.0 and v2.0.5.0 Declares another type deriving from one declared in the PCL library, which in turn derives from a type declared in System.dll v.2.0.5.0

Visual Studio 2013 Update 4 Changes MSFakes Shim Object Default Behaviour

风流意气都作罢 提交于 2019-12-12 10:59:49
问题 We have a suite of unit tests some of which use MS Fakes. Prior to Update 4 they ran successfully. After applying Update 4 the tests that instantiate a shimmed type fail with a ShimNotImplemented exception. This has been confirmed by executing the same codebase on two different machines, one with Update 4 the other without. I understand that it's possible to change the behaviour of a shimmed type between DefaultValue and NotImplemented but from what I can determine prior to Update 4 the

Shimming a class instantiated by a static class

别来无恙 提交于 2019-12-12 04:15:03
问题 I have a static class which creates a database class instance. I am looking for a way to shim/stub that database class in my tests. public partial class Y : Form { static Models.DBModel db = new Models.DBModel(); .... Unfortunately I cannot change the code. Is there any way I can mock this database class in my tests? 回答1: This worked for me: I. Update yourdll.fakes to include: ... <ShimGeneration> <Clear/> ... <Add FullName="Models.DBModel"/> ... </ShimGeneration> ... II. In your TestClass

VerificationException when instantiating MVC controller during unit testing

对着背影说爱祢 提交于 2019-12-12 02:36:39
问题 I am doing some unit testing with Microsoft Fakes Framework , and everything works fine until I add System.Web.Mvc fake assembly. From that moment any time I try to initialize a controller in a unit test, a VerificationException is thrown. When I remove the Fake assembly reference everything works fine. However, I need this fake in order to shim an Action method of a UrlHelper object. I've seen some link's here on SO, but they are mostly about FluentValidation which is of no help to me. Also,