コード例 #1
0
        public void ResetJsonTextReaderErrorCount()
        {
            ToggleReaderError toggleReaderError = new ToggleReaderError(new StringReader("{'first':1,'second':2,'third':3}"));
            JsonTextReader    jsonTextReader    = new JsonTextReader(toggleReaderError);

            Assert.IsTrue(jsonTextReader.Read());

            toggleReaderError.Error = true;

            ExceptionAssert.Throws <Exception>(() => jsonTextReader.Read(), "Read error");
            ExceptionAssert.Throws <Exception>(() => jsonTextReader.Read(), "Read error");

            toggleReaderError.Error = false;

            Assert.IsTrue(jsonTextReader.Read());
            Assert.AreEqual("first", jsonTextReader.Value);

            toggleReaderError.Error = true;

            ExceptionAssert.Throws <Exception>(() => jsonTextReader.Read(), "Read error");

            toggleReaderError.Error = false;

            Assert.IsTrue(jsonTextReader.Read());
            Assert.AreEqual(1L, jsonTextReader.Value);

            toggleReaderError.Error = true;

            ExceptionAssert.Throws <Exception>(() => jsonTextReader.Read(), "Read error");
            ExceptionAssert.Throws <Exception>(() => jsonTextReader.Read(), "Read error");
            ExceptionAssert.Throws <Exception>(() => jsonTextReader.Read(), "Read error");

            toggleReaderError.Error = false;
        }
コード例 #2
0
        public async Task ResetJsonTextReaderErrorCountAsync()
        {
            ToggleReaderError toggleReaderError = new ToggleReaderError(new StringReader("{'first':1,'second':2,'third':3}"));
            JsonTextReader    jsonTextReader    = new JsonTextReader(toggleReaderError);

            Assert.IsTrue(await jsonTextReader.ReadAsync());

            toggleReaderError.Error = true;

            await ExceptionAssert.ThrowsAsync <Exception>(async() => await jsonTextReader.ReadAsync(), "Read error");

            await ExceptionAssert.ThrowsAsync <Exception>(async() => await jsonTextReader.ReadAsync(), "Read error");

            toggleReaderError.Error = false;

            Assert.IsTrue(await jsonTextReader.ReadAsync());
            Assert.AreEqual("first", jsonTextReader.Value);

            toggleReaderError.Error = true;

            await ExceptionAssert.ThrowsAsync <Exception>(async() => await jsonTextReader.ReadAsync(), "Read error");

            toggleReaderError.Error = false;

            Assert.IsTrue(await jsonTextReader.ReadAsync());
            Assert.AreEqual(1L, jsonTextReader.Value);

            toggleReaderError.Error = true;

            await ExceptionAssert.ThrowsAsync <Exception>(async() => await jsonTextReader.ReadAsync(), "Read error");

            await ExceptionAssert.ThrowsAsync <Exception>(async() => await jsonTextReader.ReadAsync(), "Read error");

            await ExceptionAssert.ThrowsAsync <Exception>(async() => await jsonTextReader.ReadAsync(), "Read error");

            toggleReaderError.Error = false;
        }