Пример #1
0
 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>());
 }
Пример #2
0
        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,
            };
        }
Пример #3
0
        public void Creates_IonReader_For_Existing_File_Path()
        {
            var actual = IonReaderFactory.Create(FileLoader.GetExamplesIonPath());

            Expect(actual, Is.Not.Null);
            Expect(actual, Is.TypeOf <IonReader>());
        }
Пример #4
0
 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));
 }
Пример #5
0
        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]);
        }
Пример #6
0
        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);
        }
Пример #7
0
 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);
 }
Пример #8
0
        private static IIonReader CreateReaderForInput(string input)
        {
            var reader = IonReaderFactory.Create(new MemoryStream(Encoding.UTF8.GetBytes(input)));

            reader.Read();
            return(reader);
        }
Пример #9
0
        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>());
        }
Пример #10
0
        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());
        }
Пример #11
0
        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));
        }
Пример #12
0
        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);
        }
Пример #13
0
 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);
     }
 }
Пример #14
0
        public void Throws_Exception_When_FilePath_Does_Not_Exists(string filePath, string expectedExceptionMessage)
        {
            void subject() => IonReaderFactory.Create(filePath);

            Assert.Throws <ArgumentException>(subject, expectedExceptionMessage);
        }