I would like to check the ApplicationExitCode for my C# Console Program under test. Below is my NUnit test method. I am uncertain what to replace the question marks with.
My testing class method:
[Test]
public void ExitApplicationWithZeroOnNoErrors()
{
string[] arguments = { "--version=43" };
var program = new Program(arguments);
Assert.AreEqual(Utility.Status.Success, ?????);
}
My main application Program.cs.
public class Program
{
public int? Version { get; private set; }
[STAThread]
public static int Main(string[] arguments)
{
var program = new Program(arguments);
return (int)Utility.Status.Success;
}
public Program(IEnumerable<string> arguments)
{
var parameters = new OptionSet()
{
{"v|version=", "Client version number.", (int v) => Version = v},
};
parameters.Parse(arguments);
}
}
As an aside I am using NDesk.Options class for my parameter gathering. I attempting to write Unit Tests and utilize TDD for this project.
In order to check the exit code as would be returned to the OS, you should check the value returned from
Main. So you will have to runMain: