nunit

Help designing a order manager class

牧云@^-^@ 提交于 2019-12-12 18:00:49
问题 So I have an order manager class that looks like: public class OrderManager { private IDBFactory _dbFactory; private Order _order; public OrderManager(IDBFactory dbFactory) { _dbFactory = dbFactory; } public void Calculate() { _order.SubTotal _order.ShippingTotal _order.TaxTotal _order.GrandTotal } } Now, the point here is to have a flexible/testible design. I am very concerned about being able to write solid unit tests around this Calculate method. Considerations: 1. Shipping has to be

How to make WebBrowser complete navigation when running in a headless unit test?

折月煮酒 提交于 2019-12-12 15:34:52
问题 We have a WPF application that loads some content in a <WebBrowser/> control and then makes some calls based on what was loaded. With the right mocks, we think we can test this inside a displayless unit test (NUnit in this case). But the WebBrowser control doesn't want to play nicely. The problem is that we never receive the LoadCompleted or Navigated events. Apparently this is because a web-page is never "Loaded" until it is actually rendered (see this MSDN thread). We do receive the

Inconsistent test results when using dotCover

白昼怎懂夜的黑 提交于 2019-12-12 15:17:40
问题 I have some code with unit tests that pass in a Debug build but fail in a Release build which is correct. However, the same tests pass in both Debug and Release mode when run using JetBrains dotCover. To give a bit of background, here is the offending test code, just to give you in idea of why it's failing for a Release build - it's basically because of reduced stack information due to code optimization. using System.Diagnostics; using NUnit.Framework; namespace DotCoverTest { [TestFixture]

How can I use NUnit's EqualTo().Within() constraint with a custom data type?

只谈情不闲聊 提交于 2019-12-12 14:17:42
问题 I love NUnit's constraint-based API. I often use floating point comparison like this: double d = foo.SomeComputedProperty; Assert.That(d, Is.EqualTo(42.0).Within(0.001)); Very readable! However, if I have a custom class whose equality depends on floating point comparison: class Coord { Coord(double radius, double radians) { this.Radius = radius; this.Radians = radians; } double Radius { get; } double Radians { get; } public override bool Equals(Object obj) { Coord c = obj as Coord; if (obj ==

How to Structure CRUD Tests using BDD

折月煮酒 提交于 2019-12-12 14:15:55
问题 I'm stuck at a bit of a quandary trying to figure out the best way of structuring my CRUD tests. Within my application users have the ability to create several types of 'tasks'. My currently implementation looks something like the following: Scenario: Create Task-Type A Given I am on a user's profile page And Have access to create tasks When I create a new task with a unique title and description Then The confirmation prompt should display Scenario: Read the Task-Type A Given A new task was

Cannot use MvcHtmlString/IHtmlString with RazorEngine

走远了吗. 提交于 2019-12-12 13:16:45
问题 I just started playing around with the RazorEngine and I'm stumbling when using a static helper method. It just produces an MvcHtmlString/IHtmlString for the template. When calling Razor.Parse(...) I get RazorEngine.Templating.TemplateCompilationException : Unable to compile template. Der Typ 'System.Web.IHtmlString' ist in einer nicht referenzierten Assembly definiert. (not referenced) Fügen Sie einen Verweis auf die Assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken

NAnt not running NUnit tests

流过昼夜 提交于 2019-12-12 12:21:26
问题 I'm using NUnit 2.5 and NAnt 0.85 to compile a .NET 3.5 library. Because NAnt 0.85 doesn't support .NET 3.5 out of the box, I've added an entry for the 3.5 framework to NAnt.exe.config. 'MyLibrary' builds, but when I hit the "test" target to execute the NUnit tests, none of them seem to run. [nunit2] Tests run: 0, Failures: 0, Not run: 0, Time: 0.012 seconds Here are the entries in my NAnt.build file for the building and running the tests: <target name="build_tests" depends="build_core">

NUnit TestContext.CurrentContext null reference exception

五迷三道 提交于 2019-12-12 11:38:26
问题 I've been playing around this morning with watiN / Nunit to capture a screenshot on failed UI tests. However, I'm running into NRE's when accessing Nunits TestContext.CurrentContext... Any ideas as to what I'm doing wrong? [TestFixture] class SomePageTest { [Test] [STAThread] public void Page_IsAvailable() { var browser = new SomePage(); Assert.IsTrue(browser.ContainsText("Something")); if (TestContext.CurrentContext.Result.Status == TestStatus.Failed) { browser.CaptureWebPageToFile(@"X:

NUnit tests in a separate project, same solution

半腔热情 提交于 2019-12-12 11:33:14
问题 I have a solution containing my main project and a test project using NUnit. Everything compiles but when I run NUnit I get the exception below after the tests load, and the tests fail. I've added the main project as a reference, and I have $(ProjectDir)bin/Debug/$(TargetName)$(TargetExt) in the arguments for NUnit in the external tools setup, with a blank initial directory. MyMainProjectTests.Database.TestAddDelete: System.BadImageFormatException : Could not load file or assembly

Do the SetUp and TearDown methods need [RequiresSTA] if tests have it?

不想你离开。 提交于 2019-12-12 10:49:30
问题 I can run my WatiN tests with ReSharper without issues. Each test has the RequiresSTA attribute and runs fine. When I try run all the tests in the class (TestFixture) I get the following error: One or more child tests had errors Exception doesn't have a stacktrace <testname> ignored: Invalid signature for SetUp or TearDown method: TestSetup <testname> ignored: Invalid signature for SetUp or TearDown method: TestSetup <testname> ignored: Invalid signature for SetUp or TearDown method: