public void RunOptionsInvalidTests(string input) { var runOptions = new RunOptions(_serviceProvider) { Input = input }; Assert.False(runOptions.IsValid()); }
public void RunOptionsQuitTestInvalid(string input) { var runOptions = new RunOptions(_serviceProvider) { Input = input }; runOptions.IsValid(); Assert.False(runOptions.HasUserQuit()); }
static void Main(string[] args) { // Setup and build configration file. IConfiguration Configuration = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .Build(); //Setup dependency Injection for logger. var serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton <ILogger, NLogLogger>(); //Bind the json file properties to the class. var programSettings = Configuration.Get <ProgramSettings>(); if (programSettings != null) { Configuration.Bind("ProgramSettings", programSettings); serviceCollection.AddSingleton(programSettings); } var serviceProvider = serviceCollection.BuildServiceProvider(); //Helpful startup text. Console.WriteLine("---- Read Me ----"); Console.WriteLine("---- To calculate your monthly payslip please enter valid arugements such as 'GenerateMonthlyPayslip \"[Your Name]\" [Gross Salary]'"); Console.WriteLine("---- For example: GenerateMonthlyPayslip \"Mary Song\" 60000"); Console.WriteLine("---- To quit, please enter q or quit as the input and hit enter."); Console.WriteLine("---- Thank you ----"); Console.WriteLine(""); Console.WriteLine(""); // Step 1 - Create run options and start it to read in the arguments from the user. var runOptions = new RunOptions(serviceProvider); //Run if options are valid and keep program alive until user quits. do { // Read the options and generate the payslip if the options provided are valid. runOptions.ReadInput(); if (runOptions.IsValid()) { Run(serviceProvider, runOptions); } } while (!runOptions.HasUserQuit()); }