private static void LoadLevel(ref string levelNamePath, out StringReader stringReader) { //Read the level text file string textFileContent = TextFileReader.ReadTextFile(levelNamePath); stringReader = new StringReader(textFileContent); }
public void ReadsTextFromFile() { string fileName = TestContext.CurrentDirectory + @"\testtext.txt"; string[] text = new TextFileReader().ReadTokens(fileName); Assert.That(text, Is.EqualTo(new string[] { "test", "text" })); }
static void Main(string[] args) { Console.Out.Write("Please enter search string: "); // Wait for input String line = Console.In.ReadLine(); if (line.Equals("")) { Console.Out.WriteLine("Please enter a search string..."); Console.ReadKey(); return; } // File to match in string filename = "testFile.txt"; // Read the file and place it in string string s = TextFileReader.ReadFile(filename); // Get a search term (or terms) string matchLine = getInputString(line); // Collect all matches in the string RegMatch[] allMatches = FindAllMatches(matchLine, s); printOutMatches(allMatches, s); }
public void Find_Lines_From_File_By_Regexp() { var testEntities = new List <TestEntity>() { new TestEntity("ERROR", 1234, new Guid("aeda1ea5-b49d-48cc-88d8-42e3970b2ea8")), new TestEntity("ERROR", 43, Guid.NewGuid()), new TestEntity("WARNING", 1212, Guid.NewGuid()), new TestEntity("ERROR", 54321, new Guid("dfa2259a-921c-4372-a4cc-5922bbdc51de")) }; string filePath = "D:\\Logs\\RegexpSearcherTest.txt"; var stringBuilder = new StringBuilder(); testEntities.ForEach(e => stringBuilder.AppendLine($"{e.Data} in line {e.Line}, with id {e.Id}")); File.WriteAllText(filePath, stringBuilder.ToString()); string regexpFull = "ERROR.*"; string regexpDetails = @".*in line.*(\d{4,5}).* with id (.{36})"; var lines = RegexpSearcher.Find(RegexpSearcher.Find(TextFileReader.ReadLines(filePath), regexpFull, (line, match) => line), regexpDetails, (s, match) => { var line = Int32.Parse(match.Groups[1].Value); var id = Guid.Parse(match.Groups[2].Value); return(new TestEntity(s, line, id)); }).ToList(); Assert.AreEqual(2, lines.Count); Assert.AreEqual(lines[0].Line, 1234); Assert.AreEqual(lines[0].Id, new Guid("aeda1ea5-b49d-48cc-88d8-42e3970b2ea8")); Assert.AreEqual(lines[1].Line, 4321); Assert.AreEqual(lines[1].Id, new Guid("dfa2259a-921c-4372-a4cc-5922bbdc51de")); }
//==================================================== private ==================================================== //テキストファイルの読み込み private void Read_Text(string fileName) { TextFileReader text = new TextFileReader(); text.Read_Text_File(fileName); textWords = text.textWords; }
public void A_User_Should_be_Able_to_Read_A_TextFile(string fileName) { var textFileReader = new TextFileReader(filePath, fileName); string contentFile = textFileReader.Read(); Assert.Equal("This is the file content", contentFile); }
public void A_User_Should_be_Able_to_Read_An_Encrypted_TextFile_InjectingService() { string fileName = "EncryptedContent.txt"; //Mock DecryptService Service var mockDecryptService = new Mock <IDecryptDataService>(); mockDecryptService .Setup(mock => mock.DecryptData(It.IsAny <string>())) .Returns((string param) => { StringBuilder stringBuilder = new StringBuilder(param); char[] array = stringBuilder.ToString().ToCharArray(); Array.Reverse(array); return(new string(array)); }); var textFileReader = new TextFileReader(filePath, fileName, mockDecryptService.Object); string contentFile = textFileReader.Read(); Assert.Equal("This is the file content", contentFile); }
public void TryReadRecord_MultipleRecordsWithOneHeaderRow_RecordsAreRead() { var records = new string[] { "Header", "1,A", "2,B" }; File.WriteAllLines(this.FilePath, records); using (var fileReader = new TextFileReader(this.FilePath)) { fileReader.HeaderRowCount = 1; fileReader.Open(); var couldReadRecord1 = fileReader.TryReadRecord(out var record1, out var failures1); var couldReadRecord2 = fileReader.TryReadRecord(out var record2, out var failures2); var couldReadRecord3 = fileReader.TryReadRecord(out var record3, out var failures3); Assert.IsTrue(couldReadRecord1); Assert.IsTrue(couldReadRecord2); Assert.IsFalse(couldReadRecord3); Assert.AreEqual(records[1], record1); Assert.AreEqual(records[2], record2); Assert.IsNull(failures1); Assert.IsNull(failures2); } }
bool LoadFile(FilePath filePath) { if (filePath == null) { return(true); } try { _filePath = filePath; _fileSize = filePath.FileInfo.Length; _readOnly = filePath.FileInfo.Attributes.HasFlag(FileAttributes.ReadOnly) || filePath.FileInfo.Attributes.HasFlag(FileAttributes.System); _fileEncoding = filePath.GetEncoding(Encoding.Default); var(lines, platform, eolSeparator) = TextFileReader.ReadAllLines(filePath.FullName); _text = lines.ToList(); _eolSeparator = eolSeparator; _linesSplits = new List <List <StringSegment> >(_text.Count); for (int i = 0; i < _text.Count; i++) { _linesSplits.Add(null); } _fileEOL = platform; return(true); } catch (Exception ex) { Error(ex.Message); return(false); } }
/// <summary> /// Read data from file. /// </summary> /// <param name="reader">File for reading.</param> /// <returns>Readed items, checkSum and filename.</returns> public List <Pair <string> > ReadData(TextFileReader reader) { char[] separators = new char[] { '|', }; List <Pair <string> > itemList = reader.ReadSplittedLines(separators); return(itemList); }
public void TestFindAllMatches() { string filename = "onlytext.txt"; string s = TextFileReader.ReadFile(filename); RegMatch[] matches = Program.FindAllMatches("man", s); // This is man on the pos 5 Assert.AreEqual(matches[1].pos, 5); Assert.AreEqual(matches.length, 1); foreach (RegMatch match in matches) { Assert.AreNotEqual(match.color, ConsoleColor.Blue); Assert.AreNotEqual(match.color, ConsoleColor.Red); } string filename2 = "textWithoutLinks.txt"; string s2 = TextFileReader.ReadFile(filename); RegMatch[] matches2 = Program.FindAllMatches("", s2); // This is the first occuring link Assert.AreEqual(matches2[0].pos, 50); Assert.AreEqual(matches2.length, 2); foreach (RegMatch match in matches2) { Assert.AreNotEqual(match.color, ConsoleColor.Yellow); Assert.AreNotEqual(match.color, ConsoleColor.Red); } string filename3 = "textWithoutDates.txt"; string s3 = TextFileReader.ReadFile(filename); RegMatch[] matches3 = Program.FindAllMatches("", s3); // This is the first occuring date Assert.AreEqual(matches3[0].pos, 50); Assert.AreEqual(matches3.length, 2); foreach (RegMatch match in matches3) { Assert.AreNotEqual(match.color, ConsoleColor.Yellow); Assert.AreNotEqual(match.color, ConsoleColor.Blue); } string filename4 = "textWithoutDates.txt"; string s4 = TextFileReader.ReadFile(filename); RegMatch[] matches4 = Program.FindAllMatches("man", s4); Assert.AreEqual(matches4.length, 10); // ish }
public void FileThatHasBeenReadShouldReturnSameValue() { var reader = new TextFileReader(_pathValidations, _fileSystem); var content = reader.ReadContent(_expFullNamePath); Assert.Equal(_expectedContent, content); }
/// <summary> /// Create a project using the inputted strings as sources. /// </summary> /// <param name="sources">Classes in the form of strings</param> /// <param name="language">The language the source code is in</param> /// <returns>A Project created out of the Documents created from the source strings</returns> public static Dictionary <string, Document> CreateCompilationAndReturnDocuments(IEnumerable <string> filePaths, string language = LanguageNames.CSharp) { string fileNamePrefix = DefaultFilePathPrefix; string fileExt = language == LanguageNames.CSharp ? CSharpDefaultFileExt : VisualBasicDefaultExt; var projectId = ProjectId.CreateNewId(debugName: TestProjectName); var solution = new AdhocWorkspace() .CurrentSolution .AddProject(projectId, TestProjectName, TestProjectName, language) .AddMetadataReference(projectId, CorlibReference) .AddMetadataReference(projectId, SystemCoreReference) .AddMetadataReference(projectId, CSharpSymbolsReference) .AddMetadataReference(projectId, CodeAnalysisReference); var documents = new Dictionary <string, Document>(); int count = 0; foreach (var filePath in filePaths) { var newFileName = fileNamePrefix + count + "." + fileExt; var documentId = DocumentId.CreateNewId(projectId, debugName: newFileName); var source = TextFileReader.ReadFile(filePath); solution = solution.AddDocument(documentId, newFileName, SourceText.From(source)); count++; documents.Add(filePath, solution.GetDocument(documentId)); } return(documents); }
public void SplitBills_ShouldReturnListOfTripsThatContainsExpensesOwnedPerPerson() { string filePath = Path.GetFullPath("Resources/testfile.txt"); decimal[] expected = new decimal[] { -1.99m, -8.01m, 10.01m, 0.98m, -0.98m }; IFileReader fileReader = new TextFileReader(); IFileWriter fileWriter = new TextFileWriter(); IExpensesCalculator calculator = new ExpensesCalculator(); SplitBillsService service = new SplitBillsService(fileReader, fileWriter, calculator); bool isSuccess = service.SplitBills(filePath); Assert.True(isSuccess); int i = 0; foreach (var trip in service.Trips) { foreach (var participant in trip.Participants) { Assert.Equal(expected[i++], participant.ExpensesShouldBePaid); } } }
/// <summary> /// Writes a file containing the sha1 hash code of the file given. The file is named <paramref name="filePath"/>.sha1 /// </summary> /// <param name="filePath">The file path.</param> public void WriteSha1HashFile(string filePath) { ITextReader reader = new TextFileReader(filePath); ITextWriter writer = new TextFileWriter(GetSha1FilePath(filePath)); this.hashService.WriteHash(reader, writer); }
public void ReadSimpleTextTest() { TextFileReader reader = new TextFileReader("test1.txt"); var content = reader.Read(); Assert.AreEqual(content, "hello"); }
/// <summary> /// Read items from a file. /// </summary> /// <param name="path">Full path to the file.</param> /// <returns>Number of items read.</returns> public int ReadFile(string path, CheckSumType currentSumType) { TextFileReader reader = new TextFileReader(path); IFile sumFile = InitSumFile(currentSumType); List <Pair <string> > itemList = sumFile.ReadData(reader); int items = 0; foreach (Pair <string> item in itemList) { // TODO: must validity-check values! string filename = item.Item2; FileInfo fi = new FileInfo(filename); // Check if fhe file is found and accessible try { if (fi.Exists) { string fullpath = Path.Combine(fi.DirectoryName, fi.Name); _list.AddFile(fullpath, item.Item1); ++items; continue; } } catch { continue; } } return(items); }
private void ReadFile(string path) { TextFileReader tr = new TextFileReader(); var lines = tr.Parse(path); Parser parser = new Parser(); parser.Parse(lines, out _nodes, out _connections); }
public void ReadEncodedTest() { ReverseEncryption encryptionStrategy = new ReverseEncryption(); TextFileReader reader = new TextFileReader("encryptedText.txt", encryptionStrategy); string decodedText = reader.ReadEncoded(); Assert.AreEqual(decodedText, "hello"); }
public void TestReadFile() { TextFileReader tfr = new TextFileReader("input2.txt"); string buf = tfr.ToString(); Assert.AreEqual(31, buf.Length); }
public void WriteReadFile() { TextFileWriter writer = new TextFileWriter(path); writer.Write(content); TextFileReader reader = new TextFileReader(path); Assert.AreEqual(content, reader.GetString()); }
public void ReadContent_WhenFileExists() { var reader = new TextFileReader(); var path = "TestFiles/TextFile.txt"; string content = reader.ReadContent(path); Assert.NotEmpty(content); }
public void TestReadInvalidPath(string fileName) { string fullPath = string.Concat(Path.GetDirectoryName(ResourceAssembly.Location), "\\", fileName); //Test the file reading Library TextFileReader textFileReader = new TextFileReader(); Assert.Throws <ArgumentException>(() => textFileReader.ReadTextFile(fullPath), "The requested path is not a file"); }
public void Error_WrongConstructor_Read_An_Encrypted_TextFile() { string fileName = "EncryptedContent.txt"; var textFileReader = new TextFileReader(filePath, fileName); string contentFile = textFileReader.Read(); Assert.NotEqual("This is the file content", contentFile); }
public void TestReadNotSupported(string fileName) { string fullPath = string.Concat(Path.GetDirectoryName(ResourceAssembly.Location), "\\", fileName); //Test the file reading Library TextFileReader textFileReader = new TextFileReader(); Assert.Throws <ArgumentOutOfRangeException>(() => textFileReader.ReadTextFile(fullPath), "Specified type is not supported"); }
public void TestReadNotExist(string fileName) { string fullPath = string.Concat(Path.GetDirectoryName(ResourceAssembly.Location), "\\", fileName); //Test the file reading Library TextFileReader textFileReader = new TextFileReader(); Assert.Throws <FileNotFoundException>(() => textFileReader.ReadTextFile(fullPath), string.Format("Text File {0} does not exist", fullPath)); }
public void ReadFileAndCheckRowCount() { TextFileReader reader = new TextFileReader(TestFolder + "TestFile1.md5"); MD5File sumFile = new MD5File(); List <Pair <string> > itemList = sumFile.ReadData(reader); Assert.AreEqual(itemList.Count, _testFile1RowCount); }
public void ReadFromFile() { TextFileReader textFileReader = new TextFileReader(); string[] data = textFileReader.FetchStringArrayByLocation(System.AppDomain.CurrentDomain.BaseDirectory + @"..\..\..\Data\UserData.txt"); CurrentSavings = float.Parse(data[0]); MonthlySalary = float.Parse(data[1]); }
public static void InitializeComponents(string[] args) { TextFileReader.processID = args[0]; Logger.processID = args[0]; TextFileReader.FindIPFromFile(); ConnectionThreader c = new ConnectionThreader(int.Parse(TextFileReader.processID), TextFileReader.dict); c.ConnectProcesses(); }
public void ReturnsEmptyConstructor_When_MethodBodyIsNull(string filePath, string className, string expected) { var source = TextFileReader.ReadFile(filePath); var syntaxGenerator = new SyntaxGeneratorProvider().GetSyntaxGenerator(source); var actual = _target.Constructor(className, null, syntaxGenerator); Assert.Equal(expected.RemoveWhitespace(), actual.GetText().ToString()); }
public void A_User_Should_be_Able_to_Read_An_Encrypted_TextFile_ExtensionMethod() { string fileName = "EncryptedContent.txt"; var textFileReader = new TextFileReader(filePath, fileName); string contentFile = textFileReader.ReadAndDecrypt(); Assert.Equal("This is the file content", contentFile); }
public void WriteReadFileStream() { new TextFileWriter(path).Write(content); using (Stream stream = new TextFileReader(path).GetStream()) { new TextFileWriter(path2).Write(stream, 3); } Assert.AreEqual(content, new TextFileReader(path2).GetString()); }
public void TestRead() { var reader = new TextFileReader<TextItem>(TestTextFileDefinition.DefinitionFile); var items = reader.ReadFromFile(@"../../../data/TextFile.txt"); Assert.AreEqual(2, items.Count); Assert.AreEqual(2.1, items[0].PropName1); Assert.AreEqual(1, items[0].PropName2); Assert.AreEqual("hahaha", items[0].PropName3); Assert.AreEqual(3.1, items[1].PropName1); Assert.AreEqual(2, items[1].PropName2); Assert.AreEqual("lalala", items[1].PropName3); }
public void Test2() { var formatFile = FileUtils.GetAssemblyPath() + "\\template\\ataqs.srmformat"; var reader = new TextFileReader<SrmTransition>(formatFile); var mrms = reader.ReadFromFile(data); Assert.AreEqual(2000, mrms.Count); Assert.AreEqual("YBL100C", mrms[0].ObjectName); Assert.AreEqual("AAAAGLAALVELIR", mrms[0].PrecursorFormula); Assert.AreEqual(669.91, mrms[0].PrecursorMZ, 0.01); Assert.AreEqual(884.56, mrms[0].ProductIon, 0.01); Assert.AreEqual(43.16, mrms[0].ExpectCenterRetentionTime); }
/// <summary> /// Calculates the sha1 hash value for the file path given /// </summary> /// <param name="filePath">The file path.</param> /// <returns>The sha1 hash value for the file path given</returns> public string CalculateSha1HashValue(string filePath) { ITextReader reader = new TextFileReader(filePath); return this.hashService.GetHashFromReader(reader); }
/// <summary> /// Reads the sha1 hash value from the file named <paramref name="filePath"/>.sha1 /// </summary> /// <param name="filePath">The file path of the origin file, not the hash file.</param> /// <returns>The sha1 hash value from the file given</returns> public string ReadSha1HashFile(string filePath) { ITextReader reader = new TextFileReader(GetSha1FilePath(filePath)); return reader.GetString(); }