public void Constructor_with_message()
        {
            InvalidDocumentSizeLengthException exception = new InvalidDocumentSizeLengthException("Message");

            Assert.AreEqual("Message", exception.Message);
            Assert.AreEqual(default(int), exception.ReadDocumentSizeLength);
            Assert.AreEqual(default(int), exception.ExpectedDocumentSizeLength);
        }
        public void Constructor_with_expected_and_read()
        {
            int expectedDocumentSizeLength = 1;
            int readDocumentSizeLength     = 2;
            InvalidDocumentSizeLengthException exception = new InvalidDocumentSizeLengthException(expectedDocumentSizeLength, readDocumentSizeLength);

            Assert.AreEqual($"The expected DocumentSizeLength value {expectedDocumentSizeLength} is different from the read value {readDocumentSizeLength}", exception.Message);
            Assert.AreEqual(readDocumentSizeLength, exception.ReadDocumentSizeLength);
            Assert.AreEqual(expectedDocumentSizeLength, exception.ExpectedDocumentSizeLength);
        }
        public void Constructor_with_message_and_exception()
        {
            Exception baseException = new Exception();
            InvalidDocumentSizeLengthException exception = new InvalidDocumentSizeLengthException("Message", baseException);

            Assert.AreEqual("Message", exception.Message);
            Assert.AreSame(baseException, exception.InnerException);
            Assert.AreEqual(default(int), exception.ReadDocumentSizeLength);
            Assert.AreEqual(default(int), exception.ExpectedDocumentSizeLength);
        }
        public void Constructor_with_message_expected_and_read()
        {
            int expectedDocumentSizeLength = 1;
            int readDocumentSizeLength     = 2;
            InvalidDocumentSizeLengthException exception = new InvalidDocumentSizeLengthException("Message", expectedDocumentSizeLength, readDocumentSizeLength);

            Assert.AreEqual("Message", exception.Message);
            Assert.AreEqual(readDocumentSizeLength, exception.ReadDocumentSizeLength);
            Assert.AreEqual(expectedDocumentSizeLength, exception.ExpectedDocumentSizeLength);
        }
Ejemplo n.º 5
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);
            }
        }
Ejemplo n.º 6
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);
            }
        }
Ejemplo n.º 7
0
        public void GetNextDocumentSizeAsync_with_default_value_when_cant_read_all_expected_buffer()
        {
            Stream stream = new MemoryStream();

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

            using (JsonStreamMock jsonStream = new JsonStreamMock(stream))
            {
                InvalidDocumentSizeLengthException exception = Assert.ThrowsException <InvalidDocumentSizeLengthException>(() =>
                {
                    int size = jsonStream.GetNextDocumentSizeAsync().GetAwaiter().GetResult();
                });

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