public void Creates_IonReader_For_FileStream() { using FileStream fileStream = new FileStream(FileLoader.GetExamplesIonPath(), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); using var ionReader = IonReaderFactory.Create(fileStream); Expect(ionReader, Is.Not.Null); Expect(ionReader, Is.TypeOf <IonReader>()); }
public void Before_All_Test() { this.target = IonReaderFactory.Create(FileLoader.GetExamplesIonPath()); this.assertions = new List <Action> { IsSectionHeader_InFirstLine, IsProperty_InSecondLine, IsProperty_InThirdLine, IsEmptyLine_InFourthLine, IsProperty_InFifthLine, IsEmptyLine_InSixthLine, IsSectionHeader_InSeventhLine, IsTableRow_InEighthLine, IsTableHeaderSeparatorRow_InNinethLine, IsTableRow_InTenthLine, IsTableRow_InEleventhLine, IsEmptyLine_InTwelfthLine, IsEmptyLine_InThirteenthLine, IsEmptyLine_InFourteenthLine, IsSectionHeader_InFiftheenthLine, IsTableRow_InSixteenthLine, IsTableHeaderSeparatorRow_InSeventeenthLine, IsTableRow_InEighteenthLine, }; }
public void Creates_IonReader_For_Existing_File_Path() { var actual = IonReaderFactory.Create(FileLoader.GetExamplesIonPath()); Expect(actual, Is.Not.Null); Expect(actual, Is.TypeOf <IonReader>()); }
public void IonProperty_Throws_InvalidOperationException(string input) { using var reader = IonReaderFactory.Create(new MemoryStream(Encoding.UTF8.GetBytes(input))); reader.Read(); Assert.False(reader.IsProperty); Assert.Throws <InvalidOperationException>(() => new IonProperty(reader)); }
public void Should_Read_Ion_With_Windows_Line_Endings() { var props = new List <string>(); using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(FileLoader.GetIonWithWindowsLineEndings()))) using (var reader = IonReaderFactory.Create(stream)) { while (reader.Read()) { if (reader.CurrentSection != "DEFAULTS") { continue; } if (reader.IsEmptyLine) { break; } if (reader.IsProperty) { props.Add(reader.CurrentLine); } } } Assert.AreEqual(8, props.Count); Assert.AreEqual("currency = \"EUR\"", props[0]); Assert.AreEqual("language = \"de\"", props[1]); Assert.AreEqual("sales_market = \"DE\"", props[2]); Assert.AreEqual("timeout = 5000", props[3]); Assert.AreEqual("sipp = \"ECAR\"", props[4]); Assert.AreEqual("price_margin = %5", props[5]); Assert.AreEqual("disabled_log_urls = [ \"/G\", \"/cars\", \"/cars_group_by\" ]", props[6]); Assert.AreEqual("enabled_log_urls = [ ]", props[7]); }
public void Should_Read_Ins_Ion() { int counter = 0; using (var stream = File.OpenRead(FileLoader.GetInsIonPath())) using (var reader = IonReaderFactory.Create(stream)) { while (reader.Read()) { if (reader.CurrentSection != "INSURANCE") { continue; } if (reader.IsEmptyLine) { break; } if (reader.IsTableDataRow) { counter++; var columns = reader.CurrentLine.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries); Assert.AreEqual(12, columns.Length); if (counter == 1) { Assert.AreEqual("Berlin Mitte Kronenstraße", columns[0].Trim()); } if (counter == 2) { Assert.AreEqual("DANS PARKING AUTOCIT®Õ NIVEAU -2", columns[0].Trim()); } } } } Assert.AreEqual(3, counter); }
public void CurrentSection_Returns_Null_Before_First_Read() { using var reader = IonReaderFactory.Create(Stream.Null); Assert.Null(reader.CurrentSection); reader.Read(); Assert.NotNull(reader.CurrentSection); }
private static IIonReader CreateReaderForInput(string input) { var reader = IonReaderFactory.Create(new MemoryStream(Encoding.UTF8.GetBytes(input))); reader.Read(); return(reader); }
public void Creates_IonReader_For_MemoryStream() { var rawFileContent = Encoding.UTF8.GetBytes(File.ReadAllText(FileLoader.GetExamplesIonPath())); using MemoryStream fileStream = new MemoryStream(rawFileContent); using var ionReader = IonReaderFactory.Create(fileStream); Expect(ionReader, Is.Not.Null); Expect(ionReader, Is.TypeOf <IonReader>()); }
public void IonProperty_Test(string input, string key, string value) { using var reader = IonReaderFactory.Create(new MemoryStream(Encoding.UTF8.GetBytes(input))); reader.Read(); Assert.True(reader.IsProperty); var property = new IonProperty(reader); Assert.AreEqual(key, property.Key.ToString()); Assert.AreEqual(value, property.Value.ToString()); }
public static void Main(string[] args) { Stopwatch stopwatch = new Stopwatch(); int linesCount = 0; double fileSizeInMb = GetFileSizeInMB("example.ion"); using (IIonReader reader = IonReaderFactory.Create("example.ion")) { stopwatch.Start(); linesCount = ReadIonLines(reader); stopwatch.Stop(); } Console.WriteLine("Performance analysis:"); Console.WriteLine(string.Format("IonReader read {0}MB file containing {1} lines in {2}ms", fileSizeInMb, linesCount, stopwatch.ElapsedMilliseconds)); }
public void Should_Read_Multiple_Sections() { var counter = 0; using (var stream = File.OpenRead(FileLoader.GetInsIonPath())) using (var reader = IonReaderFactory.Create(stream)) { var sectionReader = new GenericSectionReader(reader); sectionReader.OnReadSection += (sender, args) => { Assert.That(args.SectionName, Is.AnyOf("META", "INSURANCE")); counter++; }; sectionReader.Read(); } Assert.AreEqual(2, counter); }
public int Read() { using (var reader = IonReaderFactory.Create(FileLoader.GetExamplesIonPath())) { int total = 0; while (reader.Read()) { if (reader.CurrentSection == "STATION") { if (reader.IsTableDataRow) { var row = reader.CurrentRawLine.AsSpan(); total += row.Length; } } } return(total); } }
public void Throws_Exception_When_FilePath_Does_Not_Exists(string filePath, string expectedExceptionMessage) { void subject() => IonReaderFactory.Create(filePath); Assert.Throws <ArgumentException>(subject, expectedExceptionMessage); }