Exemplo n.º 1
0
        public void ParseFunctions_ReadLine_SetsInputAndCallsNextFunction()
        {
            // Arrange

            // Note that the string being used here has some extra white
            // space around it.
            var buffer    = Encoding.ASCII.GetBytes("  Lorem ipsum ");
            var memStream = new MemoryStream(buffer);
            var reader    = new StreamReader(memStream);
            var state     = new object();
            var context   = new ParseContext(reader, state);

            var numCallsMadeToNextFunction = 0;

            Task next()
            {
                numCallsMadeToNextFunction++;
                return(Task.CompletedTask);
            }

            // Act
            ParseFunctions.ReadLine(context, next).Wait();

            // Assert

            // Note that the expected value is a trimmed version of the one
            // used above to create the buffer variable.
            Assert.AreEqual("Lorem ipsum", context.Input);
            Assert.AreEqual(1, numCallsMadeToNextFunction);
        }
Exemplo n.º 2
0
        public void ParseFunctions_ReadLine_ThrowsOnNullParseContext()
        {
            // Arrange
            ParseContext nullParseContext = null;

            Task next() => Task.CompletedTask;

            // Act
            ParseFunctions.ReadLine(nullParseContext, next);
        }
Exemplo n.º 3
0
        public void ParseFunctions_ReadLine_ThrowsOnNullNextFunction()
        {
            // Arrange
            var reader  = new StreamReader(new MemoryStream());
            var state   = new object();
            var context = new ParseContext(reader, state);

            Func <Task> nullNextFunction = null;

            // Act
            ParseFunctions.ReadLine(context, nullNextFunction);
        }