Ejemplo n.º 1
0
        public void When_reading_file_with_large_Lines_and_small_buffer_matches_result_of_streamreader()
        {
            var filename = $"{this.GetDataDirectory()}\\data\\LargeLineFile.txt";
            var sw = new Stopwatch();
            sw.Start();
            using (var fileStreamEx = new FileStreamEx(filename, 1000))
            {
                fileStreamEx.ReadLine();
                fileStreamEx.ReadLine();
                Action a = () => fileStreamEx.ReadLine();

                a.ShouldThrow<ArgumentException>();
            }
            sw.Stop();
            Console.WriteLine("Time: " + sw.ElapsedMilliseconds);
        }
Ejemplo n.º 2
0
 public void When_reading_file_with_medium_Lines_and_large_buffer_matches_result_of_streamreader()
 {
     var filename = $"{this.GetDataDirectory()}\\data\\MediumLineFile.txt";
     var sw = new Stopwatch();
     sw.Start();
     using (var fileStreamEx = new FileStreamEx(filename))
     {
         using (var streamEx = new StreamReader(filename))
         {
             Line line;
             while ((line = fileStreamEx.ReadLine()) != null)
             {
                 var streamText = streamEx.ReadLine();
                 var fileStreamText = line.Text;
                 streamText.ShouldBeEquivalentTo(fileStreamText);
             }
         }
     }
     sw.Stop();
     Console.WriteLine("Time: " + sw.ElapsedMilliseconds);
 }
Ejemplo n.º 3
0
        public void When_checking_line_contains_characters_false_is_returned_if_they_do_not()
        {
            var filename = $"{this.GetDataDirectory()}\\data\\SingleLine.txt";
            using (var fileStreamEx = new FileStreamEx(filename))
            {
                Line line;
                while ((line = fileStreamEx.ReadLine()) != null)
                {
                    var actual = line.Contains('Y');

                    actual.Should().BeFalse();
                }
            }
        }
Ejemplo n.º 4
0
        public void When_checking_line_IsNullOrEmpty_true_is_returned_if_line_does_not_contain_characters_other_than_spaces()
        {
            var filename = $"{this.GetDataDirectory()}\\data\\ThreeLinesWIthSeondEmpty.txt";
            using (var fileStreamEx = new FileStreamEx(filename))
            {
                Line line;
                line = fileStreamEx.ReadLine(); // Not Empty
                line = fileStreamEx.ReadLine(); // Empty
                var actual = line.IsNullOrEmpty();

                actual.Should().BeTrue();
            }
        }
Ejemplo n.º 5
0
        public void When_stripping_characters_from_a_line_the_characters_are_removed()
        {
            var filename = $"{this.GetDataDirectory()}\\data\\SingleLine.txt";
            using (var fileStreamEx = new FileStreamEx(filename))
            {
                Line line;
                while ((line = fileStreamEx.ReadLine()) != null)
                {
                    var newLine = line.Strip(' ', '.');

                    var expected = line.Text.Replace(" ", "").Replace(".", "");
                    expected.ShouldBeEquivalentTo(newLine.Text);
                }
            }
        }
Ejemplo n.º 6
0
 public void When_checking_end_of_a_line_returns_false_if_line_does_not_end_with_character_supplied()
 {
     var filename = $"{this.GetDataDirectory()}\\data\\SingleLine.txt";
     using (var fileStreamEx = new FileStreamEx(filename))
     {
         Line line;
         while ((line = fileStreamEx.ReadLine()) != null)
         {
             var found = line.EndsWith('Z');
             found.Should().BeFalse();
         }
     }
 }
Ejemplo n.º 7
0
 public void When_checking_start_of_a_line_returns_true_if_line_starts_with_character_supplied()
 {
     var filename = $"{this.GetDataDirectory()}\\data\\SingleLineEndingWithSpace.txt";
     using (var fileStreamEx = new FileStreamEx(filename))
     {
         Line line;
         while ((line = fileStreamEx.ReadLine()) != null)
         {
             var found = line.StartsWith('T');
             found.Should().BeTrue();
         }
     }
 }
Ejemplo n.º 8
0
 public void When_splitting_a_line_with_that_does_not_have_the_seperator_returns_a_single_item_array_of_Line_objects()
 {
     var filename = $"{this.GetDataDirectory()}\\data\\ThreeLinesWIthSeondEmpty.txt";
     using (var fileStreamEx = new FileStreamEx(filename))
     {
         Line line;
         while ((line = fileStreamEx.ReadLine()) != null)
         {
             var expectedParts = line.Text.Split('\t');
             var columns = line.Split('\t');
             columns.Count.Should().Be(expectedParts.Length);
             for (int i = 0; i < expectedParts.Length; i++)
             {
                 columns[i].Text.ShouldBeEquivalentTo(expectedParts[i]);
             }
         }
     }
 }
Ejemplo n.º 9
0
 public void When_splitting_a_line_with_seperator_at_end_of_line_returns_an_array_of_Line_objects()
 {
     var filename = $"{this.GetDataDirectory()}\\data\\SingleLineEndingWithSpace.txt";
     using (var fileStreamEx = new FileStreamEx(filename))
     {
         Line line;
         while ((line = fileStreamEx.ReadLine()) != null)
         {
             var expectedParts = line.Text.Split(' ');
             var columns = line.Split(' ');
             columns.Count.Should().Be(expectedParts.Length);
             for (int i = 0; i < expectedParts.Length; i++)
             {
                 columns[i].Text.ShouldBeEquivalentTo(expectedParts[i]);
             }
         }
     }
 }