Esempio n. 1
0
 public async void Should_parse_one_line()
 {
     // given
     byte[] buffer = Encoding.ASCII.GetBytes("first line\n\n");
     var stream = new MemoryStream(buffer);
     var parser = new LineParser();
     // when
     var lines = await parser.Parse(stream, CancellationToken.None);
     // then 
     Check.That(lines).HasSize(1);
     Check.That(lines.ElementAt(0)).IsEqualTo("first line");
 }
Esempio n. 2
0
        public async void Should_parse_one_line()
        {
            // given
            byte[] buffer = Encoding.ASCII.GetBytes("first line\n\n");
            var    stream = new MemoryStream(buffer);
            var    parser = new LineParser();
            // when
            var lines = await parser.Parse(stream, CancellationToken.None);

            // then
            Check.That(lines).HasSize(1);
            Check.That(lines.ElementAt(0)).IsEqualTo("first line");
        }
Esempio n. 3
0
        public async void Should_parse_lines_till_cancelled()
        {
            // given
            byte[] buffer = Encoding.ASCII.GetBytes("first line\nsecond");
            var stream = new MemoryStream(buffer);

            var parser = new LineParser();
            // when
            var source = new CancellationTokenSource();
            var parsingTask = Task.Run(() => parser.Parse(stream, source.Token));
            await Task.Delay(200);
            source.Cancel();
            await Task.Delay(1000);
            // then
            Check.That(parsingTask.Status).IsNotEqualTo(TaskStatus.Running);
        }
Esempio n. 4
0
        public async void Should_parse_lines_till_cancelled()
        {
            // given
            byte[] buffer = Encoding.ASCII.GetBytes("first line\nsecond");
            var    stream = new MemoryStream(buffer);

            var parser = new LineParser();
            // when
            var source      = new CancellationTokenSource();
            var parsingTask = Task.Run(() => parser.Parse(stream, source.Token));
            await Task.Delay(200);

            source.Cancel();
            await Task.Delay(1000);

            // then
            Check.That(parsingTask.Status).IsNotEqualTo(TaskStatus.Running);
        }