OCR - optical character recognition, with MODI - microsoft office document imaging.

Microsoft has developed tool for OCR, which we can use it as a COM object.

First you need to install MODI on your computer, then, you can use it like this:

Document md = new Document();
String ocrText = String.Empty;

md.Create(openFileDialog1.FileName);
const bool ocrOrientImage = false;
const bool ocrStraightenImage = false;
md.OCR(MiLANGUAGES.miLANG_ENGLISH, ocrOrientImage, ocrStraightenImage);

var image = (MODI.Image)md.Images[0];
var layout = image.Layout;

foreach (Word word in layout.Words)
{
 if (ocrText.Length > 0)
 {
   ocrText += " ";
 }

  ocrText += word.Text;
}
textBox1.Text = ocrText;

Only problem is if you want to really release the object md, then you ave to use SaveAs method something like:

 

string path = Path.GetDirectoryName(openFileDialog1.FileName);

md.SaveAs(path + "\\deleteMe.tif", MODI.MiFILE_FORMAT.miFILE_FORMAT_DEFAULTVALUE, 
MODI.MiCOMP_LEVEL.miCOMP_LEVEL_MEDIUM);

Taken from here, and from this source code.

My source you can download from here, and exe file can be found here.

Open new form in "modal" style:

  Form2 frmTest = new Form2();
  frmTest.ShowDialog();

To get path from file name:

using System.IO;
...
string path = Path.GetDirectoryName(openFileDialog1.FileName);

In my case I decided to go to NUnit download page and download NUnit directly (NUnit.3.2.1.msi).

Start new console application. In the solution add new class library. Then, in that class library add reference to NUnit, in my case file is:

C:\Program Files (x86)\NUnit.org\framework\3.2.1.0\net-4.5\nunit.framework.dll

Also add reference in class library to console application (application which we are going to test)

We will also need NUnit Test Adapter, in order to see our tests in test explorer.

Go to Tools -> Extensions and Updates

Go to online and search for NUnit3 Test Adapter - in my case I needed NUnit3 because of VS 2015

Install it. Restart VS. Code in console application which I am going to test looks like:

namespace NUnit
{
  public class Program
  {
    static void Main(string[] args)
    {
    }

    public string ATest()
    {
      return "Hello World";
    }
  }
}

Class library looks like:

using NUnit.Framework;
using NUnit;

namespace NUnitTest
{
  [TestFixture]
  public class HelloWorldTest
  {
    Program source;

    [SetUp]
    public void Init()
    {
      source = new Program();
    }

    [Test]
    public void ShouldShowHelloWorld()
    {
      Assert.AreEqual("Hello World", source.ATest());
    }
  }
}

Now rebuild solution. Open Test Explorer (Test -> Window -> Test Explorer)

And run all tests:

For parameterized tests I've created solution with two projects, one is console application, and second one (where my tests are actually) is class library.

My main, console, application looks like this: 

static void Main(string[] args)
{
	Summation mySum = new Summation();
	Console.WriteLine(mySum.MySummation(10).ToString());
	Console.ReadKey();
}

Where class "Summation" is like:

public class Summation
{
	public int MySummation(int myValue)
	{
		return myValue + myValue;
	}
}

Now, let's say that we want to create unit test for 10, 20 and 30 values. Instead of writing three tests we will use parameterized tests like:

[Test]
[Sequential]
public void Summ_results([Values(10, 20, 30)] int sumResult)
{
	Summation mySum = new Summation();
	Assert.AreEqual(sumResult + sumResult, mySum.MySummation(sumResult));
}

Notice part:

[Values(10, 20, 30)] 

With that line and class attribute [Sequential] we said that our test will be executed three times where each time sumResult will be 10, 20 or 30.

Example project you can download from here.