I would put the function you want to test in another class
using System;
namespace BinaryClass
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
BinaryConverter p = new BinaryConverter();
Console.WriteLine("Binary Value of 4 = " + p.IntToBinaryString(4));
}
}
public class BinaryConverter
{
public string IntToBinaryString(int number)
{
const int mask = 1;
var binary = string.Empty;
while (number > 0)
{
binary = (number & mask) + binary;
number = number >> 1;
}
return binary;
}
}
}
Then you can add a unit test project to the solution and add a reference to the binaryclass project
You can test what the function you expect the function to return against what is actually returned. You run the tests in the unit test window
public class UnitTest1
{
[TestMethod]
public void TestBinary4()
{
BinaryClass.BinaryConverter p = new BinaryClass.BinaryConverter();
string expected = "100";
string actual = p.IntToBinaryString(4);
Assert.AreEqual(expected,actual);
}
}