Exemplo n.º 1
0
        public void GetNextDocumentSize_changing_default_length_when_end_of_stream_was_reached()
        {
            Stream stream = new MemoryStream();

            stream.Write(Encoding.UTF8.GetBytes("000001024"), 0, 9);
            stream.Position = stream.Length;

            using (JsonStreamMock jsonStream = new JsonStreamMock(stream, Modes.ReadAndWrite, 9))
            {
                int  size     = jsonStream.GetNextDocumentSize();
                long position = stream.Position;

                Assert.AreEqual(0, size);
                Assert.AreEqual(stream.Length, position);
            }
        }
Exemplo n.º 2
0
        public void GetNextDocumentSize_changing_default_length_value_pass()
        {
            Stream stream = new MemoryStream();

            stream.Write(Encoding.UTF8.GetBytes("000001024"), 0, 9);
            stream.Position = 0;

            using (JsonStreamMock jsonStream = new JsonStreamMock(stream, Modes.ReadAndWrite, 9))
            {
                int  size     = jsonStream.GetNextDocumentSize();
                long position = stream.Position;

                Assert.AreEqual(1024, size);
                Assert.AreEqual(jsonStream.DocumentSizeLengthInBytes, position);
            }
        }
Exemplo n.º 3
0
        public void GetNexDocumentSize_when_size_descriptor_is_invalid()
        {
            Stream stream = new MemoryStream();

            stream.Write(Encoding.UTF8.GetBytes("AsWedbUp"), 0, 8);
            stream.Position = 0;

            using (JsonStreamMock jsonStream = new JsonStreamMock(stream, Modes.ReadAndWrite, 8))
            {
                InvalidDocumentSizeLengthException exception = Assert.ThrowsException <InvalidDocumentSizeLengthException>(() =>
                {
                    int size = jsonStream.GetNextDocumentSize();
                });

                Assert.AreEqual(default(int), exception.ExpectedDocumentSizeLength);
                Assert.AreEqual(default(int), exception.ReadDocumentSizeLength);
                Assert.AreEqual("Error interpreting document size.", exception.Message);
            }
        }
Exemplo n.º 4
0
        public void GetNextDocumentSize_changing_default_length_when_cant_read_all_expected_buffer()
        {
            Stream stream = new MemoryStream();

            stream.Write(Encoding.UTF8.GetBytes("000001024"), 0, 9);
            stream.Position = 1;

            using (JsonStreamMock jsonStream = new JsonStreamMock(stream, Modes.ReadAndWrite, 9))
            {
                InvalidDocumentSizeLengthException exception = Assert.ThrowsException <InvalidDocumentSizeLengthException>(() =>
                {
                    int size = jsonStream.GetNextDocumentSize();
                });

                Assert.AreEqual(jsonStream.DocumentSizeLengthInBytes, exception.ExpectedDocumentSizeLength);
                Assert.AreNotEqual(exception.ReadDocumentSizeLength, exception.ExpectedDocumentSizeLength);
                Assert.IsTrue(exception.ReadDocumentSizeLength < exception.ExpectedDocumentSizeLength);
            }
        }