• ### Question

• Hey there, Im studying a .net module atm, and we are doing unit testing.  Im trying to get some advice on whats going on, so my first example is a working one and the 2nd and third examples are my questions:

```//this is my calculator class
public class calculator
{
public int Add(int n1, int n2)
{
return n1 + n2;
}
public int Subtract(int n1, int n2)
{
return n1 - n2;
}
public int Multiply(int n1, int n2)
{
return n1 * n2;
}
public int Divide(int n1, int n2)
{
return n1 / n2;
}
}

//so this is a seperate class to testing the add method in my //calculator class...
using ...
using NUnit.Framework;

namespace CalcLib
{
[TestFixture]
class CalculatorTest
{
[Test]
{
calculator calc = new calculator();
}

}
}

```

The following methods are available for the Box class:
Box (int x, int y, int height, int width) //constructor
getX () //returns the x coordinate of the lower left corner of the Box object
getY () //returns the y coordinate of the lower left corner of the Box object
getHeight () //returns the height of the Box object in pixels
get Width () //returns the width of the Box object in pixels

The following methods are available for the Point class:
Point (int x, int y) //constructor
getX () //returns the x coordinate of the Point object
getY () //returns the y coordinate of the Point object
The lower left corner of the screen has the coordinates (0, 0).

A new method is required for the fictional ClickChecker class which can be used to check if a person has clicked the mouse (generating an instance of the Point class) within a rectangular box positioned on screen (represented by an instance of the Box class).
Demonstrate, by writing the C# code needed and by outlining the steps that could be taken, how the Test Driven Development cycle may be applied when carrying out this task.

So i'm trying:

```Using...
using NUnit.Framework;

namespace Boxes
{
[Text Fixture]
class ClickChecker
{
[Test}
public void mouseClickes()
{
Point p = new Point(x,y);
mouseposition aswer = p.Point(x,y);
}
}
```

Keeping my first example in mind could someone please point me out what Im doing wrong and possibly how to amend it, I know I have to get the new point and compare it to the current.

Another example is something like:

The following task is taken from a fictional Sprint Backlog.
Add a new method to the (fictional) StringValidator class to check if a string meets the following criteria:
o
Contains at least one digit
o
Contains at least one letter
o
Contains no spaces
o
Is at least 9 characters long
Demonstrate, by showing the C# code written and by outlining the steps taken, how the Test Driven Development cycle should be applied when carrying out this task.

Any suggestions would be greatly appreciated.

Thanks again guys

Wednesday, January 18, 2012 4:11 AM

### All replies

• Hey there, Im studying a .net module atm, and we are doing unit testing.  Im trying to get some advice on whats going on, so my first example is a working one and the 2nd and third examples are my questions:

```//this is my calculator class
public class calculator
{
public int Add(int n1, int n2)
{
return n1 + n2;
}
public int Subtract(int n1, int n2)
{
return n1 - n2;
}
public int Multiply(int n1, int n2)
{
return n1 * n2;
}
public int Divide(int n1, int n2)
{
return n1 / n2;
}
}

//so this is a seperate class to testing the add method in my //calculator class...
using ...
using NUnit.Framework;

namespace CalcLib
{
[TestFixture]
class CalculatorTest
{
[Test]
{
calculator calc = new calculator();
}

}
}

```

The following methods are available for the Box class:
Box (int x, int y, int height, int width) //constructor
getX () //returns the x coordinate of the lower left corner of the Box object
getY () //returns the y coordinate of the lower left corner of the Box object
getHeight () //returns the height of the Box object in pixels
get Width () //returns the width of the Box object in pixels

The following methods are available for the Point class:
Point (int x, int y) //constructor
getX () //returns the x coordinate of the Point object
getY () //returns the y coordinate of the Point object
The lower left corner of the screen has the coordinates (0, 0).

A new method is required for the fictional ClickChecker class which can be used to check if a person has clicked the mouse (generating an instance of the Point class) within a rectangular box positioned on screen (represented by an instance of the Box class).
Demonstrate, by writing the C# code needed and by outlining the steps that could be taken, how the Test Driven Development cycle may be applied when carrying out this task.

So i'm trying:

```Using...
using NUnit.Framework;

namespace Boxes
{
[Text Fixture]
class ClickChecker
{
[Test}
public void mouseClickes()
{
Point p = new Point(x,y);
mouseposition aswer = p.Point(x,y);
}
}
```

Keeping my first example in mind could someone please point me out what Im doing wrong and possibly how to amend it, I know I have to get the new point and compare it to the current.

Another example is something like:

The following task is taken from a fictional Sprint Backlog.
Add a new method to the (fictional) StringValidator class to check if a string meets the following criteria:
o
Contains at least one digit
o
Contains at least one letter
o
Contains no spaces
o
Is at least 9 characters long
Demonstrate, by showing the C# code written and by outlining the steps taken, how the Test Driven Development cycle should be applied when carrying out this task.

Any suggestions would be greatly appreciated.

Thanks again guys

Wednesday, January 18, 2012 4:12 AM
• Hi xnaLearner,

Thank you for visiting the MSDN forum. This forum is to discuss Visual Studio Unit tests.  Based on your description, it is related to the NUnit. I am moving your question to the Off-topic forum .Thanks for your understanding.

Thanks,

Jack Zhai [MSFT]
MSDN Community Support | Feedback to us
Thursday, January 19, 2012 6:00 AM