nunit

Mocking HttpContext.GetGlobalResourceObject in NUnit with Moq

◇◆丶佛笑我妖孽 提交于 2019-12-22 09:29:04
问题 I am trying to write a unit test which tests a method that uses HttpContext.GetGlobalResourceObject() and I would like to mock it using Moq. Let's say we're testing this method: public List<DctmGridColumn> GetDctmColumnsMandatory() { List<DctmGridColumn> metadataFields = new List<DctmGridColumn> { new DctmGridColumn(HttpContext.GetGlobalResourceObject("SharePoint.Service", "DctmGridColumn_DispName_r_object_id").ToString()), new DctmGridColumn(HttpContext.GetGlobalResourceObject("SharePoint

what will NUnit do internally when a test timeout is violated?

风格不统一 提交于 2019-12-22 09:09:16
问题 exactly what does NUnit do when it encounters a timeout? I used to think it would abort the test by throwing a TimeoutException, but this test proves otherwise: [Test, Timeout(100), ExpectedException(typeof(TimeoutException))] public static void RaisingExpectedTimeoutException() { Thread.Sleep(500); } unfortunately the nunit console only reports a violation of the timeout, but not how the test was aborted by it. is there anyone out there who knows more about how this would work? and why the

How to use AOP from DI Frameworks With C# TestFrameworks? (NOT for the item under test)

流过昼夜 提交于 2019-12-22 08:53:25
问题 My apologies in advance for a terrible title- suggestions welcome! I've been reading about DI and AOP, and I think I grasp the basics; at least for the canonical example of adding logging. I would like to apply this to the test cases we've been creating in NUnit e.g. be able to automatically add entry/exit logging for all test case methods and any 'helper methods' that they call. (And I'm not tied to NUnit- if it's easier in another framework, please let me know.) NOTE- this is not about the

Test a public method which calls a private method using NUnit

元气小坏坏 提交于 2019-12-22 08:39:03
问题 I have a public method in a class that internally calls a particular private method within that class. It looks something like this : public class MyClass : IMyClassInterface { public List<int> MyMethod(int a, int b) { MyPrivateMethod(a, b, ref varList, ref someVal); } private void MyPrivateMethod(int a, int b, ref List<int> varList, ref double someval) { } } Now, I basically want to test this public method using NUnit. I am using NMock 2.0 for mocking. How do I do it? Since, it internally

Two dimensional object array return type - NSubstitute

痴心易碎 提交于 2019-12-22 08:37:12
问题 I get a cast exception System.InvalidCastException : Unable to cast object of type 'System.Object[]' to type 'System.Object[,]'. at Castle.Proxies.ITestProxy.Get2DArray() at Scratch.TestFixture.Get2DArray() in TestTest.cs: line 17 from from the below: [TestFixture] public class TestFixture { [Test] public void Get2DArray() { Substitute.For<ITest>().Get2DArray().Returns(new object[1,1]); } } public interface ITest { object[,] Get2DArray(); } can anyone throw any light on this? I'm thinking it

NUnit asserts in separate thread

假如想象 提交于 2019-12-22 08:35:16
问题 Is nunit applicable in multithreading context. I do not want nunit to test my multithreading application of course, but want to use nunit assertions Simple example - this test is "green". What do I wrong? [Test] public void Test() { Action action = Async; action.BeginInvoke(action.EndInvoke, null).AsyncWaitHandle.WaitOne(); } private void Async() { Assert.IsTrue(false); Assert.DoesNotThrow( () => { Console.WriteLine("Async"); throw new InvalidOperationException(); }); } 回答1: The NUnit test

Testing With A Fake DbContext and Autofixture and Moq

徘徊边缘 提交于 2019-12-22 08:29:26
问题 SO follow this example example and how make a fake DBContex For test my test using just this work fine [Test] public void CiudadIndex() { var ciudades = new FakeDbSet<Ciudad> { new Ciudad {CiudadId = 1, EmpresaId =1, Descripcion ="Santa Cruz", FechaProceso = DateTime.Now, MarcaBaja = null, UsuarioId = 1}, new Ciudad {CiudadId = 2, EmpresaId =1, Descripcion ="La Paz", FechaProceso = DateTime.Now, MarcaBaja = null, UsuarioId = 1}, new Ciudad {CiudadId = 3, EmpresaId =1, Descripcion ="Cochabamba

PartCover 4.0 Only Reports NUnit Libraries

我是研究僧i 提交于 2019-12-22 07:59:13
问题 I'm using PartCover 4.0 (from the sourceforge page, latest dev build) with NUnit 2.5.8 on Windows 7 (x64). PartCover runs ok (using the -x86.exe), but it only shows me coverage for various NUnit packages -- not my own source-code. I originally didn't use CorFlags.exe since I didn't get the COM error; I tried it anyways, and it didn't make any difference. I've looked at all the other questions on Stack Overflow, and none seem to apply; I'm using PartCover 4.0, there are no spaces in any of my

Execute a command-line command from CruiseControl.NET

孤街醉人 提交于 2019-12-22 07:01:33
问题 I have this block of code in the CruiseControl.NET configuration: <exec> <executable>C:\Windows\System32\cmd.exe</executable> <buildArgs>/C SETX SELENIUM_BROWSER googlechrome /M</buildArgs> </exec> It is followed by an NUnit execution command that will run some Selenium tests on my website. The idea is that this command changes the testing browser (system environment variable) before the tests are run. The problem is that the command does not seem to be working. The tests are still using the

Tests dependent on commonly used functionality with NUnit

喜你入骨 提交于 2019-12-22 06:48:03
问题 I have some initialization code to use my API. The initialization may fail and I´d like to test it in an NUnit test. After the initialization the API may be used. I´m testing the API too, but all my test methods will use the same, common, initialization code. What I would ideally like is if this behavior: The Initialization test is run. The other tests are run if [1] succeeded. In all cases where [1] will fail, so will all other tests. But the valuable information is that [1] fails. That's