microsoft-fakes

how to stub HttpControllerContext

我的梦境 提交于 2019-11-30 05:18:54
I am trying to unit-test a piece of code that gets called from a WebAPI (OData) controller and takes in an HttpControllerContext: public string MethodToTest(HttpControllerContext context) { string pub = string.Empty; if (context != null) { pub = context.Request.RequestUri.Segments[2].TrimEnd('/'); } return pub; } To Unit-test this i need an HttpControllerContext object. How should i go about it? I was initially trying to stub it with Microsoft Fakes, but HttpControllerContext doesnt seem to have an interface (why??), so thats doesnt seem to be an option. Should i just new up a new

MSB3270: Mismatch between the processor architecture - Fakes Framework

醉酒当歌 提交于 2019-11-30 04:39:28
Since I use Fakes Framework in my UnitTest, I get the following MSBuild warning. warning MSB3270: There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "DocumentServiceModel", "x86". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor

How can I verify that a Microsoft Fakes (beta) stub/shim was called (like AssertWasCalled in Rhino Mocks)?

六月ゝ 毕业季﹏ 提交于 2019-11-29 13:47:21
I'm using the beta of Microsoft Fakes in Visual Studio 11. How can I verify that a dependency's method was called by my system under test? As verify functionality is not included in the Microsoft Fakes Beta, the code below is a basic test for whether or not a method on a dependency was called. You could enhance the true test to test parameter values or other conditions of a proper call. Test: [TestMethod] public void TestMethod1() { var secondDoItCalled = false; var secondStub = new Fakes.ShimSecond(); secondStub.DoIt = () => { secondDoItCalled = true; }; var first = new First(secondStub);

SonarQube.Integration.targets process conflicts when building a project

安稳与你 提交于 2019-11-29 12:23:01
I am having an issue with building a project, with SonarQube integrated, on TFS 2015. When I build this project without SonarQube, it builds fine. However, when SonarQube runs alongside this build, one of the project files fails to compile (specifically, it's a unit test project). I get the following error: D:\Builds\....\Project\.sonarqube\bin\targets\SonarQube.Integration.targets (235, 0) Could not write lines to file "D:\Builds\.....\.sonarqube\out\\f_AnyCPU_Release_0213\FilesToAnalyze.txt". The process cannot access the file 'D:\Builds\.....\Project\.sonarqube\out\f_AnyCPU_Release_0213

ShimNotSupportedException in MS VisualStudio 2012

陌路散爱 提交于 2019-11-29 11:02:38
I'm just trying to get familiar with the new Fakes Isolation Framework in Visual Studio 2012 RC but I'm consequently facing issues with ShimNotSupportedException s. At the first tries, each single shim method I tried to hook up a delegate to, had thrown a ShimNotSupportedException when trying to run/debug the test. [TestMethod] public void GetFoo_ValidBar_ReturnsBaz() { using(ShimsContext.Create()) { ShimDateTime.NowGet = () => new DateTime(2012,08,11,10,20,59); const string expected = "20120811_102059"; string actual = GetFoo(); Assert.AreEqual(expected,actual); } } This is the corresponding

Suppressing Microsoft Fakes warnings

五迷三道 提交于 2019-11-29 06:01:40
I'm using Microsoft Fakes to shim a couple WindowsAzure components for testing. Following the advice in vs 2012: Shims compile , I updated my .fakes file to just generate the shims I actually need: <Fakes xmlns="http://schemas.microsoft.com/fakes/2011/" Diagnostic="false"> <Assembly Name="Microsoft.WindowsAzure.Storage" Version="2.1.0.0"/> <StubGeneration> <Clear/> </StubGeneration> <ShimGeneration> <Clear/> <Add FullName="Microsoft.WindowsAzure.Storage.CloudStorageAccount"/> <Add FullName="Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient"/> <Add FullName="Microsoft.WindowsAzure.Storage

how to stub HttpControllerContext

耗尽温柔 提交于 2019-11-29 02:54:28
问题 I am trying to unit-test a piece of code that gets called from a WebAPI (OData) controller and takes in an HttpControllerContext: public string MethodToTest(HttpControllerContext context) { string pub = string.Empty; if (context != null) { pub = context.Request.RequestUri.Segments[2].TrimEnd('/'); } return pub; } To Unit-test this i need an HttpControllerContext object. How should i go about it? I was initially trying to stub it with Microsoft Fakes, but HttpControllerContext doesnt seem to

How can I verify that a Microsoft Fakes (beta) stub/shim was called (like AssertWasCalled in Rhino Mocks)?

岁酱吖の 提交于 2019-11-28 07:22:04
问题 I'm using the beta of Microsoft Fakes in Visual Studio 11. How can I verify that a dependency's method was called by my system under test? 回答1: As verify functionality is not included in the Microsoft Fakes Beta, the code below is a basic test for whether or not a method on a dependency was called. You could enhance the true test to test parameter values or other conditions of a proper call. Test: [TestMethod] public void TestMethod1() { var secondDoItCalled = false; var secondStub = new

SonarQube.Integration.targets process conflicts when building a project

佐手、 提交于 2019-11-28 05:56:58
问题 I am having an issue with building a project, with SonarQube integrated, on TFS 2015. When I build this project without SonarQube, it builds fine. However, when SonarQube runs alongside this build, one of the project files fails to compile (specifically, it's a unit test project). I get the following error: D:\Builds\....\Project\.sonarqube\bin\targets\SonarQube.Integration.targets (235, 0) Could not write lines to file "D:\Builds\.....\.sonarqube\out\\f_AnyCPU_Release_0213\FilesToAnalyze.txt

How to pass in a mocked HttpClient in a .NET test?

六眼飞鱼酱① 提交于 2019-11-28 03:47:08
I have a service which uses Microsoft.Net.Http to retrieve some Json data. Great! Of course, I don't want my unit test hitting the actual server (otherwise, that's an integration test). Here's my service ctor (which uses dependency injection...) public Foo(string name, HttpClient httpClient = null) { ... } I'm not sure how I can mock this with ... say .. Moq or FakeItEasy . I want to make sure that when my service calls GetAsync or PostAsync .. then i can fake those calls. Any suggestions how I can do that? I'm -hoping- i don't need to make my own Wrapper .. cause that's crap :( Microsoft can