Beispiel #1
0
            public void WritesRunMessageCorrectly()
            {
                var mocks  = new WriterTests.Mocks();
                var writer = new BoltWriter(mocks.OutputStream);

                writer.Write(new RunMessage("RETURN 1 AS num"));
                writer.Flush();

                mocks.VerifyResult("00 13 b2 10 8f 52 45 54 55 52 4e 20 31 20 41 53 20 6e 75 6d a0 00 00");
            }
Beispiel #2
0
            public async void WritesAckFailureMessageCorrectly()
            {
                var mocks  = new WriterTests.Mocks();
                var writer = new BoltWriter(mocks.OutputStream);

                writer.Write(new AckFailureMessage());
                await writer.FlushAsync();

                mocks.VerifyResult("00 02 B0 0E 00 00");
            }
Beispiel #3
0
            public void WritesInitMessageCorrectly()
            {
                var mocks  = new WriterTests.Mocks();
                var writer = new BoltWriter(mocks.OutputStream);

                writer.Write(new InitMessage("a", new Dictionary <string, object>()));
                writer.Flush();

                mocks.VerifyResult("00 05 B2 01 81 61 A0 00 00");
            }
Beispiel #4
0
        public void ShouldPropogateErrorOnUnsupportedRequestMessage()
        {
            var stream = new MemoryStream();
            var writer = new BoltWriter(stream, CreatePackStreamFactory());

            var ex = Record.Exception(() => writer.Write(new UnsupportedRequestMessage()));

            ex.Should().NotBeNull();
            ex.Should().BeOfType <ProtocolException>();
        }
Beispiel #5
0
            public void WritesResetMessageCorrectly()
            {
                var mocks  = new WriterTests.Mocks();
                var writer = new BoltWriter(mocks.OutputStream);

                writer.Write(new ResetMessage());
                writer.Flush();

                mocks.VerifyResult("00 02 B0 0F 00 00");
            }
Beispiel #6
0
        public void ShouldNotWriteToStreamUntilFlushed()
        {
            var stream = new MemoryStream();
            var writer = new BoltWriter(stream, CreatePackStreamFactory());

            writer.Write(new RunMessage("RETURN $x", new Dictionary <string, object> {
                { "x", 1L }
            }));

            Assert.Empty(stream.ToArray());
        }
Beispiel #7
0
        public async void ShouldWriteToStreamWhenFlushedAsync()
        {
            var stream = new MemoryStream();
            var writer = new BoltWriter(stream, CreatePackStreamFactory());

            writer.Write(new RunMessage("RETURN $x", new Dictionary <string, object> {
                { "x", 1L }
            }));

            await writer.FlushAsync();

            Assert.NotEmpty(stream.ToArray());
        }
Beispiel #8
0
        public void ShouldAppendEoMMarkerOnWrite()
        {
            var stream = new MemoryStream();
            var writer = new BoltWriter(stream, CreatePackStreamFactory());

            writer.Write(new RunMessage("RETURN $x", new Dictionary <string, object> {
                { "x", 1L }
            }));

            writer.Flush();

            stream.ToArray().Should().EndWith(new byte[] { 0x00, 0x00 });
        }
Beispiel #9
0
        public static byte[] GenerateBoltMessage(int paramBytesLength)
        {
            using (var data = new MemoryStream())
            {
                var boltWriter = new BoltWriter(data);
                boltWriter.Write(new RunMessage("RETUN {a}", new Dictionary <string, object>
                {
                    { "a", Enumerable.Repeat((byte)0, paramBytesLength).ToArray() }
                }));
                boltWriter.Flush();

                return(data.ToArray());
            }
        }
Beispiel #10
0
            public void WritesRunMessageWithBoolParamCorrectly(bool value, string expectedBytes)
            {
                var mocks  = new WriterTests.Mocks();
                var writer = new BoltWriter(mocks.OutputStream);

                var values = new Dictionary <string, object> {
                    { "value", value }
                };

                writer.Write(new RunMessage("", values));
                writer.Flush();

                mocks.VerifyResult(expectedBytes);
            }
Beispiel #11
0
            public async void WritesRunMessageWithArrayParamCorrectly()
            {
                var mocks  = new WriterTests.Mocks();
                var writer = new BoltWriter(mocks.OutputStream);

                var values = new Dictionary <string, object> {
                    { "value", new[] { 1, 2 } }
                };

                writer.Write(new RunMessage("", values));
                await writer.FlushAsync();

                mocks.VerifyResult("00 0D B2 10 80 A1 85 76 61 6C 75 65 92 01 02 00 00");
            }
Beispiel #12
0
            public async void WritesRunMessageWithIntegerParamCorrectly(long value, string expectedBytes)
            {
                var mocks  = new WriterTests.Mocks();
                var writer = new BoltWriter(mocks.OutputStream);

                var values = new Dictionary <string, object> {
                    { "integer", value }
                };

                writer.Write(new RunMessage("", values));
                await writer.FlushAsync();

                mocks.VerifyResult(expectedBytes);
            }
Beispiel #13
0
            public void WritesRunMessageWithArrayListParamCorrectly()
            {
                var mocks  = new WriterTests.Mocks();
                var writer = new BoltWriter(mocks.OutputStream);

                var values = new Dictionary <string, object> {
                    { "value", new ArrayList() }
                };

                writer.Write(new RunMessage("", values));
                writer.Flush();

                mocks.VerifyResult("00 0B B2 10 80 A1 85 76 61 6C 75 65 90 00 00");
            }
Beispiel #14
0
            public async void WritesRunMessageWithDictionaryParamCorrectly()
            {
                var mocks  = new WriterTests.Mocks();
                var writer = new BoltWriter(mocks.OutputStream);

                var values = new Dictionary <string, object>
                {
                    { "value", new Dictionary <string, object> {
                          { "key1", 1 }, { "key2", 2 }
                      } }
                };

                writer.Write(new RunMessage("", values));
                await writer.FlushAsync();

                mocks.VerifyResult("00 17 B2 10 80 A1 85 76 61 6C 75 65 A2 84 6B 65 79 31 01 84 6B 65 79 32 02 00 00");
            }
Beispiel #15
0
            public void WritesRunMessageWithDictionaryMixedTypesParamCorrectly()
            {
                var mocks  = new WriterTests.Mocks();
                var writer = new BoltWriter(mocks.OutputStream);

                var values = new Dictionary <string, object>
                {
                    { "value", new Dictionary <string, object> {
                          { "key1", 1 }, { "key2", "a string value" }
                      } }
                };

                writer.Write(new RunMessage("", values));
                writer.Flush();

                mocks.VerifyResult(
                    "00 25 B2 10 80 A1 85 76 61 6C 75 65 A2 84 6B 65 79 31 01 84 6B 65 79 32 8E 61 20 73 74 72 69 6E 67 20 76 61 6C 75 65 00 00");
            }