Esempio n. 1
0
            public void ShouldWriteNullSuccessfully()
            {
                var mocks  = new WriterTests.Mocks();
                var writer = new PackStreamWriter(mocks.OutputStream);

                writer.WriteNull();

                mocks.VerifyWrite(PackStream.Null);
            }
Esempio n. 2
0
            public void ShouldWriteEmptyStringSuccessfully()
            {
                var mocks  = new WriterTests.Mocks();
                var writer = new PackStreamWriter(mocks.OutputStream);

                writer.Write(string.Empty);

                mocks.VerifyWrite(PackStream.TinyString | 0);
            }
Esempio n. 3
0
            public void ShouldWriteBoolSuccessfully(bool input)
            {
                var mocks  = new WriterTests.Mocks();
                var writer = new PackStreamWriter(mocks.OutputStream);

                writer.Write(input);

                mocks.VerifyWrite(input ? PackStream.True : PackStream.False);
            }
Esempio n. 4
0
            public void ShouldWriteAsNullIfDictionaryIsNull()
            {
                var mocks  = new WriterTests.Mocks();
                var writer = new PackStreamWriter(mocks.OutputStream);

                writer.Write((IDictionary)null);

                mocks.VerifyWrite(PackStream.Null);
            }
Esempio n. 5
0
            public void ShouldWriteFloatNumbersAsDouble(object input, byte expected)
            {
                var mocks  = new WriterTests.Mocks();
                var writer = new PackStreamWriter(mocks.OutputStream);

                writer.Write(input);

                mocks.VerifyWrite(expected);
            }
Esempio n. 6
0
            public void ShouldWriteNullableAsNull(sbyte?input, byte expected)
            {
                var mocks  = new WriterTests.Mocks();
                var writer = new PackStreamWriter(mocks.OutputStream);

                writer.Write(input);

                mocks.VerifyWrite(expected);
            }
Esempio n. 7
0
            public void ShouldWriteDoubleSuccessfully(double input, string expected)
            {
                var mocks  = new WriterTests.Mocks();
                var writer = new PackStreamWriter(mocks.OutputStream);

                writer.Write(input);

                mocks.VerifyWrite(PackStream.Float64);
                mocks.VerifyWrite(expected.ToByteArray());
            }
Esempio n. 8
0
        public void ShouldThrowWhenBytesIsSent()
        {
            var mocks  = new WriterTests.Mocks();
            var writer = new PackStreamWriterBytesIncompatible(mocks.OutputStream);

            var ex = Record.Exception(() => writer.Write(new byte[10]));

            ex.Should().NotBeNull();
            ex.Should().BeOfType <ProtocolException>();
        }
Esempio n. 9
0
            public void ShouldWriteEmptyByteSuccessfully()
            {
                var mocks  = new WriterTests.Mocks();
                var writer = new PackStreamWriter(mocks.OutputStream);

                writer.Write(new byte[] { });

                mocks.VerifyWrite(PackStream.Bytes8);
                mocks.VerifyWrite(new byte[] { 0 });
            }
Esempio n. 10
0
            public void ShouldWriteStructHeaderCorrectly(int size, byte marker, byte[] expected)
            {
                var mocks  = new WriterTests.Mocks();
                var writer = new PackStreamWriter(mocks.OutputStream);

                writer.WriteStructHeader(size, 0x77);

                mocks.VerifyWrite(marker);
                mocks.VerifyWrite(expected);
            }
Esempio n. 11
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");
            }
Esempio n. 12
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");
            }
Esempio n. 13
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");
            }
Esempio n. 14
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");
            }
Esempio n. 15
0
            public void ShouldWriteAsString()
            {
                const string input = "abc";

                var mocks  = new WriterTests.Mocks();
                var writer = new PackStreamWriter(mocks.OutputStream);

                writer.Write((object)input);

                mocks.VerifyWrite(PackStream.TinyString | 3);
            }
Esempio n. 16
0
            public void ShouldWriteCharAsString()
            {
                const char input = 'a';

                var mocks  = new WriterTests.Mocks();
                var writer = new PackStreamWriter(mocks.OutputStream);

                writer.Write((object)input);

                mocks.VerifyWrite(PackStream.TinyString | 1);
            }
Esempio n. 17
0
            public void ShouldWriteAsByteArray()
            {
                var mocks  = new WriterTests.Mocks();
                var writer = new PackStreamWriter(mocks.OutputStream);
                var input  = new byte[] { 1, 2, 3 };

                writer.Write((object)input);

                mocks.VerifyWrite(PackStream.Bytes8);
                mocks.VerifyWrite(new byte[] { 3 });
            }
Esempio n. 18
0
            public void ShouldWriteDecimalNumbersAsDouble()
            {
                object input = (double)1.34m;

                var mocks  = new WriterTests.Mocks();
                var writer = new PackStreamWriter(mocks.OutputStream);

                writer.Write(input);

                mocks.VerifyWrite(PackStream.Float64);
            }
Esempio n. 19
0
            public void ShouldWriteStructHeaderStruct16Correctly()
            {
                var mocks  = new WriterTests.Mocks();
                var writer = new PackStreamWriter(mocks.OutputStream);

                writer.WriteStructHeader(short.MaxValue, 0x77);

                mocks.VerifyWrite(PackStream.Struct16);
                mocks.VerifyWrite(new byte[] { 0x7F, 0xFF });
                mocks.VerifyWrite(0x77);
            }
Esempio n. 20
0
            public void ShouldWriteLongSuccessfully(long input, byte marker, string expected)
            {
                var mocks  = new WriterTests.Mocks();
                var writer = new PackStreamWriter(mocks.OutputStream);

                writer.Write(input);

                mocks.VerifyWrite(marker);
                if (expected != null)
                {
                    mocks.VerifyWrite(expected.ToByteArray());
                }
            }
Esempio n. 21
0
            public void ShouldWriteArrayAsList()
            {
                var list = new[] { 1, 2 };

                var mocks  = new WriterTests.Mocks();
                var writer = new PackStreamWriter(mocks.OutputStream);

                writer.Write((object)list);

                mocks.VerifyWrite((byte)(PackStream.TinyList | list.Length));
                mocks.VerifyWrite(1);
                mocks.VerifyWrite(2);
            }
Esempio n. 22
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);
            }
Esempio n. 23
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");
            }
Esempio n. 24
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);
            }
Esempio n. 25
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");
            }
Esempio n. 26
0
            public void ShouldWriteListOfDifferentTypeCorrectly()
            {
                var list = new List <object>(new object[] { 1, true, "a" });

                var mocks  = new WriterTests.Mocks();
                var writer = new PackStreamWriter(mocks.OutputStream);

                writer.Write(list);

                mocks.VerifyWrite((byte)(PackStream.TinyList | list.Count));
                mocks.VerifyWrite(1);
                mocks.VerifyWrite(PackStream.True);
                mocks.VerifyWrite(PackStream.TinyString | 1);
                mocks.VerifyWrite(new byte[] { 97 });
            }
Esempio n. 27
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");
            }
Esempio n. 28
0
            public void ShouldWriteMapOfDifferentTypeCorrectly()
            {
                var dict = new Dictionary <object, object>()
                {
                    { true, "a" }
                };

                var mocks  = new WriterTests.Mocks();
                var writer = new PackStreamWriter(mocks.OutputStream);

                writer.Write(dict);

                mocks.VerifyWrite((byte)(PackStream.TinyMap | dict.Count));
                mocks.VerifyWrite(PackStream.True);
                mocks.VerifyWrite(PackStream.TinyString | 1);
                mocks.VerifyWrite(new byte[] { 97 });
            }
Esempio n. 29
0
            public void ShouldWriteStringSuccessfully(int size, byte marker, byte[] sizeByte)
            {
                var mocks  = new WriterTests.Mocks();
                var writer = new PackStreamWriter(mocks.OutputStream);

                var expected = new byte[size];

                for (int i = 0; i < size; i++)
                {
                    expected[i] = 97;
                }

                writer.Write(expected);

                mocks.VerifyWrite(marker);
                mocks.VerifyWrite(sizeByte);
                mocks.VerifyWrite(expected);
            }
Esempio n. 30
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");
            }