nunit

“Hello World” - The TDD way?

丶灬走出姿态 提交于 2019-12-20 09:03:22
问题 Well I have been thinking about this for a while, ever since I was introduced to TDD. Which would be the best way to build a "Hello World" application ? which would print "Hello World" on the console - using Test Driven Development. What would my Tests look like ? and Around what classes ? Request: No " wikipedia-like " links to what TDD is, I'm familiar with TDD. Just curious about how this can be tackled. 回答1: You need to hide the Console behind a interface. (This could be considered to be

Different return values the first and second time with Moq

荒凉一梦 提交于 2019-12-20 07:58:30
问题 I have a test like this: [TestCase("~/page/myaction")] public void Page_With_Custom_Action(string path) { // Arrange var pathData = new Mock<IPathData>(); var pageModel = new Mock<IPageModel>(); var repository = new Mock<IPageRepository>(); var mapper = new Mock<IControllerMapper>(); var container = new Mock<IContainer>(); container.Setup(x => x.GetInstance<IPageRepository>()).Returns(repository.Object); repository.Setup(x => x.GetPageByUrl<IPageModel>(path)).Returns(() => pageModel.Object);

Can't open sqlconnection within nunit test

回眸只為那壹抹淺笑 提交于 2019-12-20 07:18:06
问题 I'm having a weird issue that I can't figure out. I'm trying to write some integration tests around some database code and my unit tests fail with a weird exception. Running the code normally under a console application work just fine. public static class DatabaseManager { public static VerifyServceConnectionResult VerifyServerConnection(Server server) { try { using (var conn = new SqlConnection(BuildConnectionString(server))) { conn.Open(); } return new VerifyServceConnectionResult {

Need guidance to do Nunit test case for data insert scenario in .NET

馋奶兔 提交于 2019-12-20 04:32:37
问题 I have the below Employee model class and console client. Employee class:- public class Employee { public int EmployeeId { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public int Age { get; set; } public int phoneNumber { get; set; } public Employee() { } public Employee(string fname,string lname,int age,int phone) { this.FirstName = fname; this.LastName = lname; this.Age = age; this.phoneNumber = phone; } public void InsertEmployee() { SqlConnection

Need guidance to do Nunit test case for data insert scenario in .NET

为君一笑 提交于 2019-12-20 04:32:21
问题 I have the below Employee model class and console client. Employee class:- public class Employee { public int EmployeeId { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public int Age { get; set; } public int phoneNumber { get; set; } public Employee() { } public Employee(string fname,string lname,int age,int phone) { this.FirstName = fname; this.LastName = lname; this.Age = age; this.phoneNumber = phone; } public void InsertEmployee() { SqlConnection

AutoFixture constrained string parameter

∥☆過路亽.° 提交于 2019-12-20 04:31:38
问题 Is there a simple way to specify a list of possible values for the parameter orderBy? Not one by one please, otherwise I would not be making the question. I want to specify that orderby makes sense only if it is chosen from a predetermined list. Suppose the list is very large...still not random. This cannot be that hard...no single example of such a simple task. [Test, AutoData] public override void IndexReturnsView(int? pageIndex, int? pageSize, string orderBy, bool? desc) { ..... } EDIT:

NUnit failed to load in TFS build

荒凉一梦 提交于 2019-12-20 02:56:20
问题 I’m having a "build partially succeeded" issue with this error “NUnit failed to load e:\Builds\184\CSTax\706USServices_Test\bin\Calc.Tests.dll”, but all of the unit test in this project ran and passed (all green). Build environment 1) Using NUnit 2.6.4 and NUnit Test Adapter 2.0.0 2) TFS 2013 – upgraded from 2012 3) Visual studio 2012 and 2013 have been installed on the server 4) I did install the NUnit Test Adapter, using the Extensions and Updates in 2013 Visual Studio 5) Using build

Passing a string to attribute argument by calling method

前提是你 提交于 2019-12-20 02:15:45
问题 I'm trying to use NUnit and pass in a string argument to the TestCase attribute but I get "An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type" This is a simplified version but MyStatic is a call that returns a built up RegEx string, so each method in MyStatic that is called appends to a stringbuilder and has an implicit conversion to string. I want to keep this method because if I create separate unit tests I'd be

Populating SQLite in memory for unit testing

五迷三道 提交于 2019-12-19 19:45:21
问题 I am thinking of using SQLite as an in memory stub for my Oracle database. I can easily direct all my DAL commands to the SQLite, but I am now wondering how I should easily populate the data for each test method. Should each method begin by creating the needed table(s) and inserting the rows for the specific test? Should I populate in the Fixture SetUp phase the data in the memory? Is there some other way (Like reading it from some file, but discarding the changes so that the next read will

Can nunit-console list all test names in a test fixture?

痞子三分冷 提交于 2019-12-19 19:38:06
问题 I'd like to report them before they're run, and have the option to run individual tests through shell scripts without managing categories. We have some unmanaged code which can leave the process in a bad state, and sometimes are happy to run each test individually per nunit-console run. 回答1: There is now the --explore command-line option that can be used to list all test cases without running tests. More specifically nunit3-console.exe MyProject.dll --explore For more info: https://github.com