Пример #1
0
        public async Task Should_parse_one_line()
        {
            // given
            var 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 Task Should_parse_lines_till_cancelled()
        {
            // given
            var 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);
        }