示例#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");
 }
示例#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");
        }
示例#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);
        }
示例#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);
        }