private static bool CheckArgumentValidity(Dictionary <string, string> parsedArgs) { // check the argument availability if (!parsedArgs.ContainsKey(Constants.RegexKeyword) && !parsedArgs.ContainsKey(Constants.WildcardKeyword)) { ExitCode = Constants.ExitCode.RegexKeywordNotFound; } else if (!parsedArgs.ContainsKey(Constants.PatternKeyword)) { ExitCode = Constants.ExitCode.PatternKeywordNotFound; } else if ((parsedArgs.ContainsKey(Constants.RegexKeyword) && String.IsNullOrEmpty(parsedArgs[Constants.RegexKeyword])) && (parsedArgs.ContainsKey(Constants.WildcardKeyword) && String.IsNullOrEmpty(parsedArgs[Constants.WildcardKeyword]))) { ExitCode = Constants.ExitCode.RegexValueEmpty; } else if (String.IsNullOrEmpty(parsedArgs[Constants.PatternKeyword])) { ExitCode = Constants.ExitCode.PatternValueEmpty; } if (ExitCode == Constants.ExitCode.RegexKeywordNotFound || ExitCode == Constants.ExitCode.PatternKeywordNotFound || ExitCode == Constants.ExitCode.RegexValueEmpty || ExitCode == Constants.ExitCode.PatternValueEmpty) { return(false); } else { return(true); } }
public static int Main(string[] args) { ExitCode = Constants.ExitCode.Match; try { // Parse the arguments var parsedArgs = ParseArguments(args); // Check the argument validity if (CheckArgumentValidity(parsedArgs)) { CheckPatternMatching(parsedArgs); } // Display the message into console Console.WriteLine("Result: " + Constants.InfoMessage[ExitCode]); } catch (Exception ex) { Console.WriteLine("Exception: " + ex.Message); ExitCode = Constants.ExitCode.GeneralException; } //Environment.Exit((int)ExitCode); // comment this because unit test cannot get exit code return((int)ExitCode); }
private static void CheckPatternMatching(Dictionary <string, string> parsedArgs) { var regex = parsedArgs.ContainsKey(Constants.RegexKeyword) ? parsedArgs[Constants.RegexKeyword] : String.Empty; var wildcard = parsedArgs.ContainsKey(Constants.WildcardKeyword) ? parsedArgs[Constants.WildcardKeyword] : String.Empty; var pattern = parsedArgs[Constants.PatternKeyword]; var ignoreCase = parsedArgs.ContainsKey(Constants.IgnoreCaseKeyword) ? (parsedArgs[Constants.IgnoreCaseKeyword].Equals("yes") ? true : false) : false; // Check if the tester mode is for REGEX or WILDCARD if (!String.IsNullOrEmpty(regex)) { // check if regex is valid or not if (!IsValidRegex(regex)) { ExitCode = Constants.ExitCode.InvalidRegex; } else { // check if the pattern match with regex if (IsRegexMatch(regex, pattern, ignoreCase)) { ExitCode = Constants.ExitCode.Match; } else { ExitCode = Constants.ExitCode.NotMatch; } } } else // Wildcard { if (IsWildcardMatch(wildcard, pattern, !ignoreCase)) { ExitCode = Constants.ExitCode.Match; } else { ExitCode = Constants.ExitCode.NotMatch; } } }