public void TestRead() { File.WriteAllText(CopyPath, String.Empty); File.AppendAllText(CopyPath, "test test "); var textFile = new ReadTextFile(CopyPath); var result = textFile.Read(null); result.Should().Be(2); }
public static ReadTextFile Create(string file) { ReadTextFile rf = new ReadTextFile(); rf.m_file = file; rf.m_bHttp = file.Contains("http:") || file.Contains("https:"); rf.m_error = null; rf.Read(); return(rf); }
public void ReadTest_Pass() { //Arrange string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"TestInputFiles/testInput.txt"); IEnumerable <string> inputLines = null; //Act using (ReadTextFile readFile = new ReadTextFile()) { inputLines = readFile.Read(path); } //Assert Assert.True(inputLines != null); }
public void ReadTest_Fail() { //Arrange string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"input99.txt"); ActualValueDelegate <object> testDelegate; //Act using (ReadTextFile readFile = new ReadTextFile()) { testDelegate = () => readFile.Read(path); } //Assert Assert.That(testDelegate, Throws.TypeOf <FileNotFoundException>()); }
/// <summary> /// Prepares the game setup. /// </summary> /// <param name="inputInstructionsFilePath">The input instructions file path.</param> /// <exception cref="InvalidInputFileException"></exception> public override void PrepareGameSetup(string inputInstructionsFilePath) { if (!string.IsNullOrWhiteSpace(inputInstructionsFilePath)) { //fetch Setup details using (IRead reader = new ReadTextFile()) { try { var arrayOfDataLines = reader.Read(inputInstructionsFilePath).ToArray(); if (arrayOfDataLines != null && arrayOfDataLines.Length > 0) { PrepareBattleGameSetupInstance(inputInstructionsFilePath, arrayOfDataLines, this); } else { throw new InvalidInputFileException(inputInstructionsFilePath); } } catch (FileNotFoundException) { Handler.HandleException("Setup file Path not found in system", false); return; } catch (InvalidInputFileException exception) { Handler.HandleException(exception.Message, true); return; } catch (Exception exception) { Handler.HandleException(exception.Message, true); } } } else { Handler.HandleException("Setup Input file Path not provided.", false); } }