nunit

Why does this unit test fail when testing DateTime equality?

那年仲夏 提交于 2019-12-19 16:48:41
问题 Using NUnit 2.2 on .NET 3.5, the following test fails when using DateTime.Equals. Why? [TestFixture] public class AttributeValueModelTest { public class HasDate { public DateTime? DateValue { get { DateTime value; return DateTime.TryParse(ObjectValue.ToString(), out value) ? value : new DateTime?(); } } public object ObjectValue { get; set; } } [Test] public void TwoDates() { DateTime actual = DateTime.Now; var date = new HasDate {ObjectValue = actual}; Assert.IsTrue(date.DateValue.Value

Check several different example inputs in a single test?

二次信任 提交于 2019-12-19 13:50:09
问题 Let's say I want to write a function that validates an email address with a regex. I write a little test to check my function and write the actual function. Make it pass. However, I can come up with a bunch of different ways to test the same function (test@test.com; test234@test.com; test.test.com, etc). Do I put all the incantations that I need to check in the same, single test with several ASSERTS or do I write a new test for every single thing I can think of? Thanks! 回答1: Most testing

NUnit doesn't work well with Assert.AreEqual

两盒软妹~` 提交于 2019-12-19 13:45:38
问题 I'm new to unit testing and NUit in particular. I'm just typing some examples from the book which refers to Java and JUnit. But I'm using C# instead. The problem is: I've got a class with overriden methods such as Equals() and GetHashCode() , but when I am trying to compare two objects of this class with Assert.AreEqual() my code is not called, so I get an exception. Assert.True(MyClass.Equals(MyClass2)) does work well. But I don't want to use this construction instead of Assert.AreEqual() .

Unit Testing and Mocking using RhinoMocks

£可爱£侵袭症+ 提交于 2019-12-19 11:18:04
问题 I am trying to setup tests for my new projects and come across some difficulties. I am using NUnit and Rhino Mocks. The Code that I am trying to test is this, public DocumentDto SaveDocument(DocumentDto documentDto) { Document document = null; using (_documentRepository.DbContext.BeginTransaction()) { try { if (documentDto.IsDirty) { if (documentDto.Id == 0) { document = CreateNewDocument(documentDto); } else if (documentDto.Id > 0) { document = ChangeExistingDocument(documentDto); } document

C# NUnit 3 Data Driven from Excel

梦想与她 提交于 2019-12-19 10:55:10
问题 Hello I have the following file: testexcel.xlsx > sheet 1 I want to execute this test twice as there are 2 rows with data. [Test] [TestCaseSource("Data")] public void Login(String username, String password) { loginPageModel.DoLogin(username, password); } How can I convert that excel data into this kind of data as explained in NUnit 3 official documentation? static object[] Data = { new object[] {username, password} }; 回答1: What i did is the following and it's working I have the Test: [Test

Unit testing c# code in a ScriptSharp project

扶醉桌前 提交于 2019-12-19 09:16:21
问题 Im using ScriptSharp to create a RIA app. Works nice besides some oddities. However finding and fixing problems using Firebug isn't really convinient. Since scriptsharp also delivers a Dll I was hoping to use a separate testproject using Nunit to test some parts of my code. Issue that arises is that the generated dll references mscorlib 0.7 resulting in conflict with mscorlib 4 in the test project. A simple solution is to create a second plain C# project and copy codefiles around. But

Entity Framework 4.1 “Code First” SetInitializer not being called again after Database.Delete

被刻印的时光 ゝ 提交于 2019-12-19 07:29:26
问题 Trying to do some unit testing with EF 4.1 code first. I have my live db (SQL Server) and my unit test DB( Sql CE). After fighting (and losing) with EF, Sql CE 4.0 and Transaction support I decided the simplest way to run my test was to: Create Db Run Test Delete Db Rinse and repeat I have my [Setup] and [TearDown] functions: [SetUp] public void Init() { System.Data.Entity.Database.SetInitializer(new MyTestContextInitializer()); _dbContext = ContainerFactory.Container.GetInstance<IContext>();

Entity Framework 4.1 “Code First” SetInitializer not being called again after Database.Delete

删除回忆录丶 提交于 2019-12-19 07:29:07
问题 Trying to do some unit testing with EF 4.1 code first. I have my live db (SQL Server) and my unit test DB( Sql CE). After fighting (and losing) with EF, Sql CE 4.0 and Transaction support I decided the simplest way to run my test was to: Create Db Run Test Delete Db Rinse and repeat I have my [Setup] and [TearDown] functions: [SetUp] public void Init() { System.Data.Entity.Database.SetInitializer(new MyTestContextInitializer()); _dbContext = ContainerFactory.Container.GetInstance<IContext>();

OpenCover/NUnit can't find PDB files

∥☆過路亽.° 提交于 2019-12-19 07:24:33
问题 I'm using OpenCover http://nuget.org/packages/opencover and have written the following batch file to run the unit tests and generate code coverage stats: echo off echo *************************** echo *** Running NUnit tests *** echo *************************** "..\packages\OpenCover.4.0.804\OpenCover.Console.exe" -register:user -target:"..\NUnit 2.6\bin\nunit-console-x86.exe" -targetargs:"..\Web.UnitTests\bin\Debug\Web.UnitTests.dll" -output:coverage.xml echo ********************************

OpenCover/NUnit can't find PDB files

早过忘川 提交于 2019-12-19 07:24:13
问题 I'm using OpenCover http://nuget.org/packages/opencover and have written the following batch file to run the unit tests and generate code coverage stats: echo off echo *************************** echo *** Running NUnit tests *** echo *************************** "..\packages\OpenCover.4.0.804\OpenCover.Console.exe" -register:user -target:"..\NUnit 2.6\bin\nunit-console-x86.exe" -targetargs:"..\Web.UnitTests\bin\Debug\Web.UnitTests.dll" -output:coverage.xml echo ********************************