Skip to content

Instantly share code, notes, and snippets.

@shyassure
Created April 2, 2019 08:07
Show Gist options
  • Save shyassure/78fcb2e5a497d2d266f44f579e0c37d3 to your computer and use it in GitHub Desktop.
Save shyassure/78fcb2e5a497d2d266f44f579e0c37d3 to your computer and use it in GitHub Desktop.
public class MailAndSmsWarningSender
{
internal class Options
{
[Option("task")]
public string Task { get; set; }
}
public void ParseArgumentsAndRun(string[] args)
{
try
{
Parser.Default.ParseArguments<Options>(args)
.WithParsed(ExecuteTaskWithOptions)
.WithNotParsed(HandleParseError);
}
catch (Exception e)
{
DisplayErrorMessage(e);
}
}
private void HandleParseError(IEnumerable<Error> errs)
{
//This is never being run if using a test
throw new NotImplementedException();
}
private void ExecuteTaskWithOptions(Options opts)
{
Console.WriteLine("Executing");
}
}
[TestClass]
public class MailAndSmsWarningSenderTests
{
private MailAndSmsWarningSender _sut;
[TestInitialize]
public void Setup()
{
_sut = new MailAndSmsWarningSender();
}
[TestMethod]
public void SendSmsOnWarning()
{
_sut.ParseArgumentsAndRun(new []{"--task", "MailAndSmsWarningSender", "--test", "hejtest"});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment