nunit

Moq testing void method

一笑奈何 提交于 2020-01-01 08:43:21
问题 Hi I am new to Moq testing and having hard time to do a simple assertion. I am using an interface public interface IAdd { void add(int a, int b); } Moq for the IAdd interface is: Mock<IAdd> mockadd = new Mock<IAdd>(); mockadd.Setup(x => x.add(It.IsAny<int>(), It.IsAny<int>()).callback((int a, int b) => { a+b;}); IAdd testing = mockadd.Object; Since the add method is void, it doesn't return any value to Assert with. How can I assert this setup? 回答1: Why mocking is used? It used for verifying

Moq testing void method

时间秒杀一切 提交于 2020-01-01 08:43:08
问题 Hi I am new to Moq testing and having hard time to do a simple assertion. I am using an interface public interface IAdd { void add(int a, int b); } Moq for the IAdd interface is: Mock<IAdd> mockadd = new Mock<IAdd>(); mockadd.Setup(x => x.add(It.IsAny<int>(), It.IsAny<int>()).callback((int a, int b) => { a+b;}); IAdd testing = mockadd.Object; Since the add method is void, it doesn't return any value to Assert with. How can I assert this setup? 回答1: Why mocking is used? It used for verifying

Instantiate new System.Web.Http.OData.Query.ODataQueryOptions in nunit test of ASP.NET Web API controller

风流意气都作罢 提交于 2020-01-01 08:14:34
问题 I have an ASP.NET MVC4 Web API project with an ApiController-inheriting controller that accepts an ODataQueryOptions parameter as one of its inputs. I am using NUnit and Moq to test the project, which allow me to setup canned responses from the relevant repository methods used by the ApiController. This works, as in: [TestFixture] public class ProjectControllerTests { [Test] public async Task GetById() { var repo = new Mock<IManagementQuery>(); repo.Setup(a => a.GetProjectById(2)).Returns

Running individual NUnit tests programmatically

别来无恙 提交于 2020-01-01 05:22:08
问题 I need to run individual C# NUnit tests programmatically. I found another post that was very helpful in showing me how to run an entire set of tests programmatically, but I need to be able to select individual tests. I thought that setting up a NameFilter would do the trick, but the RemoteTestRunner only seems to think that there's one test in my suite when there are over fifty. Is it really lumping all tests in a single DLL into one gargantuan test? Is there a way that I can separate them

FluentAssertions: equivalence of sorted lists

烂漫一生 提交于 2020-01-01 04:06:52
问题 I'm trying to establish equivalence of two lists using FluentAssertions in C#, where two things are of importance: the elements are compared by the values they hold, not by reference (i.e. they are equivalent, not equal) the order of the elements in the lists is important Is there no function in FluentAssertions (or even NUnit) that does this? Cheers! 回答1: By default, ShouldBeEquivalentTo() will ignore the order in the collections because in most cases two collections are equivalent if they

Is unit testing a bad idea during beta/prototyping?

删除回忆录丶 提交于 2019-12-31 18:51:11
问题 A new project we began introduced a lot of new technologies we weren't so familiar with, and an architecture that we don't have a lot of practice in. In other words, the interfaces and interactions between service classes etc of what we're building are fairly volatile, even more so due to internal and customer feedback. Though I've always been frustrated by the ever-moving specification, I see this to some degree a necessary part of building something we've never built before - if we just

How to run nunit with msbuild from VS2010

折月煮酒 提交于 2019-12-31 10:24:50
问题 please tell me how to run nunit with msbuild. I am using TFS for code integration and VS2010 . 回答1: You probably want to integrate NUnit with TFSBuild and not MSBuild since you are using Team Foundation Server. You will need MSBuild tasks to be able to run NUnit as explained in the three following tutorials: Using NUnit and NCover with TFS Build Integrate Nunit test into a Tfs build MSBuild with NUnit The easiest way is to use the MSBuild Community Tasks where you already have a NUnit task

How to run nunit with msbuild from VS2010

假装没事ソ 提交于 2019-12-31 10:22:45
问题 please tell me how to run nunit with msbuild. I am using TFS for code integration and VS2010 . 回答1: You probably want to integrate NUnit with TFSBuild and not MSBuild since you are using Team Foundation Server. You will need MSBuild tasks to be able to run NUnit as explained in the three following tutorials: Using NUnit and NCover with TFS Build Integrate Nunit test into a Tfs build MSBuild with NUnit The easiest way is to use the MSBuild Community Tasks where you already have a NUnit task

Can I add NUnit 3 tests to Visual Studio 2015 load tests?

こ雲淡風輕ζ 提交于 2019-12-31 03:36:11
问题 I have a testing automation framework written in C# with unit tests written in NUnit ( not MSTest ). I created a new Visual Studio Load Test configuration and I was expecting to be able to add these NUnit tests to the load test, however Visual Studio (2015) is not listing them. I have the NUnit 3 Test Adapter installed already. Can I add NUnit tests to VS load tests or do they have to be MSTest unit tests? 回答1: Until now there is no package or workaround, other then converting your NUnit

Redirecting Console.Out within test Setup and Teardown

十年热恋 提交于 2019-12-31 03:03:53
问题 This is a follow up from Grabbing the output sent to Console.Out from within a unit test? and the referenced article in the accepted answer by Mark Seemann. I would like to use Console.Out and Console.In to redirect the streams while testing. Every test in the class needs to use the redirects. In order to keep the tests clean I would like to do this in the test SetUp and TearDown. This is what I was thinking: private StringWriter _sw; private StringReader _sr; [SetUp] public void SetUp() {