nunit

ServiceLocator not initialized in Tests project

梦想与她 提交于 2019-12-24 10:03:04
问题 When attempting to write a test related to my new Tasks (MVC3, S#arp 2.0), I get this error when I try to run the test: MyProject.Tests.MyProject.Tasks.CategoryTasksTests.CanConfirmDeleteReadiness: SetUp : System.NullReferenceException : ServiceLocator has not been initialized; I was trying to retrieve SharpArch.NHibernate.ISessionFactoryKeyProvider ----> System.NullReferenceException : Object reference not set to an instance of an object. at SharpArch.Domain.SafeServiceLocator 1.GetService()

Unit testing with I/O dependencies

喜欢而已 提交于 2019-12-24 09:49:59
问题 I would like to test the following class but I/O and sealed class dependencies are making it quite hard. public class ImageDrawingCombiner { /// <summary> /// Save image to a specified location in path /// </summary> /// <param name="path">Location to save the image</param> /// <param name="surface">The image as canvas</param> public void CombineDrawingsIntoImage(Uri path, Canvas surface) { Size size = new Size(surface.ActualWidth, surface.ActualHeight); // Create a render bitmap and push the

How to use OneTimeSetup?

丶灬走出姿态 提交于 2019-12-24 09:21:48
问题 NUnit has a OneTimeSetup attribute: https://github.com/nunit/docs/wiki/OneTimeSetUp-Attribute. I am trying to think of some scenarios when I can use it. However, I cannot find any GitHub examples online (even my link does not have an example): Say I had some code like this: [TestFixture] public class MyFixture { IProduct Product; [OneTimeSetUp] public void OneTimeSetUp() { IFixture fixture = new Fixture().Customize(new AutoMoqCustomization()); Product = fixture.Create<Product>(); } [Test]

How to pass values across test cases in NUnit 2.6.2?

霸气de小男生 提交于 2019-12-24 09:09:11
问题 I am having two Methods in Unit Test case where First Insert Records into Database and Second retrieves back data. I want that input parameter for retrieve data should be the id generated into first method. private int savedrecordid =0; private object[] SavedRecordId{ get { return new object[] { new object[] { savedrecordid } }; } } [Test] public void InsertInfo() { Info oInfo = new Info(); oInfo.Desc ="Some Description here !!!"; savedrecordid = InsertInfoToDb(oInfo); } [Test]

System.OutOfMemoryException during NUnit tests with localdb

♀尐吖头ヾ 提交于 2019-12-24 07:46:33
问题 While debugging some NUnit tests we found a memory leak when inserting rows into a localdb via a script file. This has started leading to System.OutOfMemoryException which stops us from running unit tests during development. The code looks like this: public static void InsertFromScriptFile (string conString, string dbName, string filePath) { using (SqlConnection conn = new SqlConnection(string.Format(conString, dbName))) { string script = File.ReadAllText(filePath); using (SqlCommand cmd =

NullReference durning testing controller with NUnit and Moq

泄露秘密 提交于 2019-12-24 07:35:13
问题 I obtain a NullReference exception in my test. When I comment eventsRepository.AddEvent(eve, User.Identity.GetUserId()); in controller than it goes through. How Can I fix it ? Controller's Method [ValidateAntiForgeryToken] [HttpPost] [Authorize] public ActionResult CreateEvent(Event eve) { if (eve.DateOfBegining < DateTime.Now) { ModelState.AddModelError("DateOfBegining", ""); } if (eve.MaxQuantityOfPlayers < eve.MinCount) { ModelState.AddModelError("MinCount", ""); } if (eve.ConflictSides

C# NUnit Selenium - Passing Objects from SetUp to TestCase

浪尽此生 提交于 2019-12-24 06:49:59
问题 I am not understanding how the scoping works on a test case. [TestFixture] class MockTests { [Setup] private void StartTest() { IWebDriver driver = new ChromeDriver(); TestLogger logger = new TestLogger(); } [TestCase(TestName = "mock1")] { //Problem is here. Driver and logger "does not exist in the current context" driver.Navigate().GoToUrl("http://my.url.com"); logger.Out("Hello! I cannot be accessed!"); } [TestCase(TestName = "mock2")] { //I now have a new instance of driver and logger in

NDepend TypeInitializationExceptions when Testing with NUnit

给你一囗甜甜゛ 提交于 2019-12-24 06:38:42
问题 So I'm trying to set up a project using the NDepend API for some metrics on my code (Which works nicely), however, when I attempt to run a testing framework (NUnit) over it, I'm getting TypeInitializationExceptions thrown. Here is some code to reproduce the errors I'm getting: Create a class library project, and reference the NDepend API dll at $NDependInstallPath$\lib\NDependAPI , setting copy local to false . Create a class as follows: public class NDependProjectLoader { public void

Run TestFixtures in Order with NUnit

大兔子大兔子 提交于 2019-12-24 04:35:13
问题 I need to have ordered test fixtures in my NUnit c# Application. I have an example on how to run ordered test methods from this page, and I've tried to implement the same logic for test fixtures with the same methods provided in the example application. In our application a test fixture is separated for each class and each test fixture has one test method. Our latest attempt was to use a Parent Test Fixture which inherits from a class called: OrderedTestFixture (the same as in the example),

How to test HttpApplication events in IHttpModules

拥有回忆 提交于 2019-12-24 03:27:59
问题 I am writing HttpModule and need to test it, I am using C# , .NET4.5.2 , NUnit and Moq . Method I am trying to test is Context_BeginRequest : public class XForwardedForRewriter : IHttpModule { public void Init(HttpApplication context) { context.BeginRequest += Context_BeginRequest; } public void Context_BeginRequest(object sender, EventArgs e) { ... } } sender here is HttpApplication and this is where the problems start,... one can create instance of HttpApplication however there is no way to