public void StringCounter_ParseTest_InputStringForSearch_CorrectExecution(string stringForSearch, int expectedCount) { // Arrange string path = @"Resources\File.txt"; FileParser fileParser = StringCounter.Initialize(path, stringForSearch); // Act int actualCount = fileParser.Parse(); // Assert Assert.AreEqual(expectedCount, actualCount); }
public void StringCounter_InitializeTest_InputNotExistingFile_ExpectedFileNotFoundException() { // Arrange string path = "FileNotExist.txt"; string stringForCount = "123"; // Act FileParser fileParser = StringCounter.Initialize(path, stringForCount); // Assert Assert.Fail(); }
/// <summary> /// The starting point of application /// </summary> /// <param name="args">The arguments from command line</param> /// <returns>Return Code</returns> public int Run(string[] args) { Logger.InitLogger(); try { FileParser fileParser; switch (args.Length) { case NULL_ARGUMENTS_COUNT: this.ShowAbout(); Console.ReadKey(); break; case NOT_ENOUGH_ARGUMENTS_COUNT: throw new ArgumentException("You don't have enough arguments in command line!"); case MIN_ARGUMENTS_COUNT: fileParser = StringCounter.Initialize(args[0], args[1]); int stringsCount = fileParser.Parse(); Console.WriteLine($"There are {stringsCount} strings in file {args[0]}"); break; case MAX_ARGUMENTS_COUNT: fileParser = StringReplacer.Initialize(args[0], args[1], args[2]); int replacedStringsCount = fileParser.Parse(); Console.WriteLine($"There were {replacedStringsCount} strings replaced in file {args[0]}"); break; default: if (args.Length > MAX_ARGUMENTS_COUNT) { throw new ArgumentException("You have too many arguments in command line!"); } break; } } catch (ArgumentException exception) { HandleExceptions(exception, args); return((int)ReturnCode.Error); } catch (FileNotFoundException exception) { HandleExceptions(exception, args); return((int)ReturnCode.Error); } Logger.Log.Info("The program was ended with return code: Success. " + "The command line arguments: " + this.GetArgumentsAsString(args)); return((int)ReturnCode.Success); }