nunit

Why is Controller.Url null when I unit test my action?

眉间皱痕 提交于 2020-01-03 15:32:10
问题 I've followed this answer to mock HttpContext, Request, Response and User and set Controller.ControllerContext and Controller.Url . Controller.Url is most definitely not null before calling controller.Index() . However, inside controller.Index() , it is null. It seems very strange. What am I missing? Here's my test fixture: [TestFixture] public class ControllerFixtureBase { private Mock<HttpContextBase> _httpContextMock; private RouteCollection _routes; [SetUp] public void SetUp() { var

C# NUnit parameterized TestCaseSource value identification

喜夏-厌秋 提交于 2020-01-03 13:08:37
问题 I am using TestCaseSource on NUnit 2.6.1 to test the same Asserts with different object class constructor parameters. I mean, [Test, TestCaseSource("myConstructorsForMale")} public void CheckMale(Person p) { Assert.That(p.IsMale); } static Person[] myConstructorsForMale = { new Person("John"), new Person(isMale=true), new Person("Doe") }; Ok, all is runing fine, but this is the result I received on the NUnit Console: CheckMale CheckMale(Person) CheckMale(Person) CheckMale(Person) So I don't

ASP.NET + NUnit : Good unit testing strategy for HttpModule using .NET 4

我只是一个虾纸丫 提交于 2020-01-03 11:37:43
问题 I have the following HttpModule that I wanted to unit test. Problem is I am not allowed to change the access modifiers/static as they need to be as it is. I was wondering what would be the best method to test the following module. I am still pretty new in testing stuff and mainly looking for tips on testing strategy and in general testing HttpModules. Just for clarification, I am just trying to grab each requested URL(only .aspx pages) and checking if the requested url has permission (for

How to run an NUnit test in VisualStudio with OpenCover code coverage?

泪湿孤枕 提交于 2020-01-03 11:34:12
问题 I am new to NUnit testing. I was able to write test cases for my functions, now what I want is to know the code coverage for my test cases. For that I use OpenCover. But I don't know how to install and get OpenCover to work with Visual Studio 2015, can anyone guide me to install OpenCover for Visual Studio and provide help to see the code coverage in Visual Studio? 回答1: The best solution I found for code coverage in Visual Studio is as follows: Open Visual Studio 2017 Go to Tools->Extensions

How to run an NUnit test in VisualStudio with OpenCover code coverage?

 ̄綄美尐妖づ 提交于 2020-01-03 11:34:07
问题 I am new to NUnit testing. I was able to write test cases for my functions, now what I want is to know the code coverage for my test cases. For that I use OpenCover. But I don't know how to install and get OpenCover to work with Visual Studio 2015, can anyone guide me to install OpenCover for Visual Studio and provide help to see the code coverage in Visual Studio? 回答1: The best solution I found for code coverage in Visual Studio is as follows: Open Visual Studio 2017 Go to Tools->Extensions

NullReferenceException thrown when testing custom AuthorizationAttribute

☆樱花仙子☆ 提交于 2020-01-03 11:12:27
问题 I have taken a look at: How do I make a unit test to test a method that checks request headers? How to mock Controller.User using moq How do I unit test a controller method that has the [Authorize] attribute applied? I am trying to test a custom AuthorizeAttribute that I wrote. I have tried many different things to get it to work. This is my current attempt. [AttributeUsage(AttributeTargets.All, AllowMultiple = false, Inherited = true)] public class ConfigurableAuthorizeAttribute :

How to run NUnit v2.4.8 tests with NAnt 0.86 beta?

这一生的挚爱 提交于 2020-01-03 10:45:30
问题 I tried recently to use NAnt (beta 0.86.2962.0) to run some unit tests compiled with the last stable version of NUnit (v2.4.8) without any success. The error I get is the following : [nunit2] Assembly "C:\Dev\MySample\bin\tests\My.Sample.Tests.dll" contains no tests. Of course, the assembly contains tests that I can run from any runner, like NUnit one, TestDriven or Resharper. I would like to use <nunit2> task, and not directly the <exec> one, but I'm wondering if it is still possible, even

Run all tests in a test class using TestDriven.NET and NUnit

天涯浪子 提交于 2020-01-03 08:26:14
问题 Note: I am using TestDriven.NET 3.0.2749 and NUnit 2.6.0.12051 for this project. I have installed both TestDriven.NET and NUnit and am trying to get TestDriven.NET to run all tests in a test class via the right-click context menu. From the TestDriven.NET documentation: If the code editor window is selected, the test(s) to execute will be determined by the position of the caret; individual tests are executed by right-clicking anywhere inside a test method and selecting 'Run Test(s)' as shown

NUnit Rollback attribute seems to fail on SQL Server 2005

怎甘沉沦 提交于 2020-01-03 05:27:06
问题 I'm using a nice little [Rollback] attribute on my NUnit database-level tests: public class RollbackAttribute : Attribute, ITestAction { private TransactionScope _transaction; public ActionTargets Targets { get { return ActionTargets.Test; } } public void BeforeTest(TestDetails testDetails) { _transaction = new TransactionScope(); } public void AfterTest(TestDetails testDetails) { _transaction.Dispose(); } } So I can then decorate my db-based tests like this: [Test] [Rollback] public void

xUnit.net Test Stripper [to remove test code embedded in binaries prior to deployment/shipping]

强颜欢笑 提交于 2020-01-03 05:19:12
问题 Is there a Test Stripper (as defined in xUnit Test Patterns) available that supports removing classes containing methods tagged as [Fact]s etc. plus the dependency on xunit.dll from binaries [as part of a build process] ? Further details of the full requirements and context are at this xUnit CodePlex post. Failing that (something that removes the tests and the reference to the DLL), does anyone have a utility/proven clean approach to removing the xunit.dll dependecy without too much monkeying