Exemple #1
0
                public void ShouldThrowExceptionIfSizeIsGreaterThanShortMax()
                {
                    var packer = new PackStream.Packer(null);
                    var ex     = Xunit.Record.Exception(() => packer.PackStructHeader(short.MaxValue + 1, 0x1));

                    ex.Should().BeOfType <ProtocolException>();
                }
Exemple #2
0
                public void ShouldThrowExceptionIfTypeUnknown()
                {
                    var packer = new PackStream.Packer(null);
                    var ex     = Xunit.Record.Exception(() => packer.Pack(new { Name = "Test" }));

                    ex.Should().BeOfType <ProtocolException>();
                }
                public void ShouldPackEmptyStringSuccessfully()
                {
                    var mocks = new Mocks();
                    var u     = new PackStream.Packer(mocks.OutputStream, new BigEndianTargetBitConverter());

                    u.Pack(string.Empty);
                    mocks.VerifyWrite(PackStream.TINY_STRING | 0);
                }
Exemple #4
0
                public void ShouldPackEmptyByteSuccessfully()
                {
                    var mocks = new Mocks();
                    var u     = new PackStream.Packer(mocks.OutputStream);

                    u.Pack(new byte[] {});
                    mocks.VerifyWrite(PackStream.BYTES_8, new byte[] { 0 });
                }
Exemple #5
0
                public void ShouldPackEmptyStringSuccessfully()
                {
                    var mocks = new Mocks();
                    var u     = new PackStream.Packer(mocks.OutputStream);

                    u.Pack(string.Empty);
                    mocks.VerifyWrite(PackStream.TINY_STRING | 0);
                }
Exemple #6
0
                public void ShouldPackFloatNumbersAsDouble(object input, byte expected)
                {
                    var mocks = new Mocks();
                    var u     = new PackStream.Packer(mocks.OutputStream);

                    u.Pack(input);
                    mocks.VerifyWrite(expected);
                }
                public void ShouldPackNullSuccessfully()
                {
                    var mocks = new Mocks();
                    var u     = new PackStream.Packer(mocks.OutputStream, new BigEndianTargetBitConverter());

                    u.PackNull();
                    mocks.VerifyWrite(PackStream.NULL);
                }
                public void ShouldPackFloatNumbersAsDouble(object input, byte expected)
                {
                    var mocks = new Mocks();
                    var u     = new PackStream.Packer(mocks.OutputStream, new BigEndianTargetBitConverter());

                    u.Pack(input);
                    mocks.VerifyWrite(expected);
                }
                public void ShouldPackNullableAsNull(sbyte?input, byte expected)
                {
                    var mocks = new Mocks();
                    var u     = new PackStream.Packer(mocks.OutputStream, new BigEndianTargetBitConverter());

                    u.Pack(input);
                    mocks.VerifyWrite(expected);
                }
                public void ShouldPackEmptyByteSuccessfully()
                {
                    var mocks = new Mocks();
                    var u     = new PackStream.Packer(mocks.OutputStream, new BigEndianTargetBitConverter());

                    u.Pack(new byte[] {});
                    mocks.VerifyWrite(PackStream.BYTES_8, new byte[] { 0 });
                }
Exemple #11
0
                public void ShouldPackNullableAsNull(sbyte?input, byte expected)
                {
                    var mocks = new Mocks();
                    var u     = new PackStream.Packer(mocks.OutputStream);

                    u.Pack(input);
                    mocks.VerifyWrite(expected);
                }
Exemple #12
0
                public void ShouldPackNullSuccessfully()
                {
                    var mocks = new Mocks();
                    var u     = new PackStream.Packer(mocks.OutputStream);

                    u.PackNull();
                    mocks.VerifyWrite(PackStream.NULL);
                }
Exemple #13
0
                public void ShouldPackDoubleSuccessfully(double input, string expected)
                {
                    var mocks = new Mocks();
                    var u     = new PackStream.Packer(mocks.OutputStream);

                    u.Pack(input);
                    mocks.VerifyWrite(PackStream.FLOAT_64);
                    mocks.VerifyWrite(expected.ToByteArray());
                }
                public void ShouldPackListHeaderCorrectly(int size, byte marker, byte[] expected)
                {
                    var mocks = new Mocks();
                    var u     = new PackStream.Packer(mocks.OutputStream, new BigEndianTargetBitConverter());

                    u.PackMapHeader(size);

                    mocks.VerifyWrite(marker, expected);
                }
                public void ShouldPackAsNullIfDictionaryIsNull()
                {
                    var mocks = new Mocks();
                    var u     = new PackStream.Packer(mocks.OutputStream, new BigEndianTargetBitConverter());

                    u.Pack((IDictionary)null);

                    mocks.VerifyWrite(PackStream.NULL);
                }
                public void ShouldPackAsString()
                {
                    var    mocks = new Mocks();
                    var    u     = new PackStream.Packer(mocks.OutputStream, new BigEndianTargetBitConverter());
                    string input = "abc";

                    u.Pack((object)input);
                    mocks.VerifyWrite(PackStream.TINY_STRING | 3);
                }
Exemple #17
0
                public void ShouldPackAsNull()
                {
                    var mocks = new Mocks();
                    var u     = new PackStream.Packer(mocks.OutputStream);

                    u.Pack((object)null);

                    mocks.VerifyWrite(PackStream.NULL);
                }
Exemple #18
0
                public void ShouldPackStructHeaderCorrectly(int size, byte marker, byte[] expected)
                {
                    var mocks = new Mocks();
                    var u     = new PackStream.Packer(mocks.OutputStream);

                    u.PackStructHeader(size, 0x77);

                    mocks.VerifyWrite(marker, expected);
                }
Exemple #19
0
                public void ShouldPackAsNullIfDictionaryIsNull()
                {
                    var mocks = new Mocks();
                    var u     = new PackStream.Packer(mocks.OutputStream);

                    u.Pack((IDictionary)null);

                    mocks.VerifyWrite(PackStream.NULL);
                }
Exemple #20
0
                public void ShouldPackAsString()
                {
                    var    mocks = new Mocks();
                    var    u     = new PackStream.Packer(mocks.OutputStream);
                    string input = "abc";

                    u.Pack((object)input);
                    mocks.VerifyWrite(PackStream.TINY_STRING | 3);
                }
Exemple #21
0
                public void ShouldPackCharAsString()
                {
                    var  mocks = new Mocks();
                    var  u     = new PackStream.Packer(mocks.OutputStream);
                    char input = 'a';

                    u.Pack((object)input);
                    mocks.VerifyWrite(PackStream.TINY_STRING | 1);
                }
Exemple #22
0
                public void ShouldPackAsByteArray()
                {
                    var mocks = new Mocks();
                    var u     = new PackStream.Packer(mocks.OutputStream);
                    var input = new byte[] { 1, 2, 3 };

                    u.Pack((object)input);
                    mocks.VerifyWrite(PackStream.BYTES_8, 3);
                }
Exemple #23
0
                public void ShouldPackDecimalNumbersAsDouble()
                {
                    var     mocks = new Mocks();
                    var     u     = new PackStream.Packer(mocks.OutputStream);
                    decimal input = 1.34m;

                    u.Pack((object)input);
                    mocks.VerifyWrite(PackStream.FLOAT_64);
                }
Exemple #24
0
                public void ShouldPackStructHeaderStruct16Correctly()
                {
                    var mocks = new Mocks();
                    var u     = new PackStream.Packer(mocks.OutputStream);

                    u.PackStructHeader(short.MaxValue, 0x77);

                    mocks.VerifyWrite(PackStream.STRUCT_16, new byte[] { 0x7F, 0xFF });
                    mocks.VerifyWrite(0x77);
                }
Exemple #25
0
                public void ShouldPackLongSuccessfully(long input, byte marker, string expected)
                {
                    var mocks = new Mocks();
                    var u     = new PackStream.Packer(mocks.OutputStream);

                    u.Pack(input);
                    mocks.VerifyWrite(marker);
                    if (expected != null)
                    {
                        mocks.VerifyWrite(expected.ToByteArray());
                    }
                }
Exemple #26
0
                public void ShouldPackArrayAsList()
                {
                    var mocks = new Mocks();
                    var u     = new PackStream.Packer(mocks.OutputStream);

                    int[] list = new int[2];
                    list[0] = 1;
                    list[1] = 2;
                    u.Pack((object)list);

                    mocks.VerifyWrite((byte)(PackStream.TINY_LIST | list.Length));
                    mocks.VerifyWrite((byte)1);
                    mocks.VerifyWrite((byte)2);
                }
                public void ShouldPackBoolSuccessfully(bool input)
                {
                    var mocks = new Mocks();
                    var u     = new PackStream.Packer(mocks.OutputStream, new BigEndianTargetBitConverter());

                    u.Pack(input);
                    if (input)
                    {
                        mocks.VerifyWrite(PackStream.TRUE);
                    }
                    else
                    {
                        mocks.VerifyWrite(PackStream.FALSE);
                    }
                }
                public void ShouldPackAsDictionary()
                {
                    var mocks = new Mocks();
                    var u     = new PackStream.Packer(mocks.OutputStream, new BigEndianTargetBitConverter());

                    IDictionary <object, object> dic = new Dictionary <object, object>();

                    dic.Add(true, "a");
                    u.Pack(dic);

                    mocks.VerifyWrite((byte)(PackStream.TINY_MAP | dic.Count));
                    mocks.VerifyWrite(PackStream.TRUE);
                    mocks.VerifyWrite(PackStream.TINY_STRING | 1);
                    mocks.VerifyWrite(new byte[] { 97 });
                }
Exemple #29
0
                public void ShouldPackMapOfDifferentTypeCorrectly()
                {
                    var mocks = new Mocks();
                    var u     = new PackStream.Packer(mocks.OutputStream);

                    IDictionary <object, object> dic = new Dictionary <object, object>();

                    dic.Add(true, "a");
                    u.Pack((IDictionary)dic);

                    mocks.VerifyWrite((byte)(PackStream.TINY_MAP | dic.Count));
                    mocks.VerifyWrite(PackStream.TRUE);
                    mocks.VerifyWrite(PackStream.TINY_STRING | 1);
                    mocks.VerifyWrite(new byte[] { 97 });
                }
Exemple #30
0
                public void ShouldPackBoolSuccessfully(bool input)
                {
                    var mocks = new Mocks();
                    var u     = new PackStream.Packer(mocks.OutputStream);

                    u.Pack(input);
                    if (input)
                    {
                        mocks.VerifyWrite(PackStream.TRUE);
                    }
                    else
                    {
                        mocks.VerifyWrite(PackStream.FALSE);
                    }
                }