Ejemplo n.º 1
0
                public void ShouldThrowExceptionIfTypeUnknown()
                {
                    var packer = new PackStream.Packer(null);
                    var ex     = Xunit.Record.Exception(() => packer.Pack(new { Name = "Test" }));

                    ex.Should().BeOfType <ProtocolException>();
                }
Ejemplo n.º 2
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);
                }
Ejemplo n.º 3
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 });
                }
Ejemplo n.º 4
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);
                }
Ejemplo n.º 5
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);
                }
Ejemplo n.º 6
0
                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);
                }
Ejemplo n.º 7
0
                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);
                }
Ejemplo n.º 8
0
                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 });
                }
Ejemplo n.º 9
0
                public void ShouldPackNullBytesSuccessfully()
                {
                    var mocks = new Mocks();
                    var u     = new PackStream.Packer(mocks.OutputStream, new BigEndianTargetBitConverter());

                    u.Pack((byte[])null);
                    mocks.VerifyWrite(PackStream.NULL);
                }
Ejemplo n.º 10
0
                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);
                }
Ejemplo n.º 11
0
                public void ShouldPackNullBytesSuccessfully()
                {
                    var mocks = new Mocks();
                    var u     = new PackStream.Packer(mocks.OutputStream);

                    u.Pack((byte[])null);
                    mocks.VerifyWrite(PackStream.NULL);
                }
Ejemplo n.º 12
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);
                }
Ejemplo n.º 13
0
                public void ShouldPackAsNullIfDictionaryIsNull()
                {
                    var mocks = new Mocks();
                    var u     = new PackStream.Packer(mocks.OutputStream, new BigEndianTargetBitConverter());

                    u.Pack((IDictionary)null);

                    mocks.VerifyWrite(PackStream.NULL);
                }
Ejemplo n.º 14
0
                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);
                }
Ejemplo n.º 15
0
                public void ShouldPackAsNullIfDictionaryIsNull()
                {
                    var mocks = new Mocks();
                    var u     = new PackStream.Packer(mocks.OutputStream);

                    u.Pack((IDictionary)null);

                    mocks.VerifyWrite(PackStream.NULL);
                }
Ejemplo n.º 16
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);
                }
Ejemplo n.º 17
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());
                }
Ejemplo n.º 18
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);
                }
Ejemplo n.º 19
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);
                }
Ejemplo n.º 20
0
                public void ShouldPackAsNull()
                {
                    var mocks = new Mocks();
                    var u     = new PackStream.Packer(mocks.OutputStream);

                    u.Pack((object)null);

                    mocks.VerifyWrite(PackStream.NULL);
                }
Ejemplo n.º 21
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());
                    }
                }
Ejemplo n.º 22
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);
                }
Ejemplo n.º 23
0
                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 });
                }
Ejemplo n.º 24
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);
                    }
                }
Ejemplo n.º 25
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 });
                }
Ejemplo n.º 26
0
                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);
                    }
                }
Ejemplo n.º 27
0
                public void ShouldPackStringSuccessfully(int size, byte marker, byte[] sizeByte)
                {
                    var mocks = new Mocks();
                    var u     = new PackStream.Packer(mocks.OutputStream);

                    var expected = new byte[size];

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

                    u.Pack(expected);

                    mocks.VerifyWrite(marker, sizeByte);
                    mocks.VerifyWrite(expected);
                }
Ejemplo n.º 28
0
                public void ShouldPackStringSuccessfully(int size, byte marker, byte[] sizeByte)
                {
                    var mocks = new Mocks();
                    var u     = new PackStream.Packer(mocks.OutputStream, new BigEndianTargetBitConverter());

                    var input    = new string('a', size);
                    var expected = new byte[size];

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

                    u.Pack(input);

                    mocks.VerifyWrite(marker, sizeByte);
                    mocks.VerifyWrite(expected);
                }
Ejemplo n.º 29
0
                public void ShouldPackListOfDifferentTypeCorrectly()
                {
                    var mocks = new Mocks();
                    var u     = new PackStream.Packer(mocks.OutputStream);

                    var list = new List <object>();

                    list.Add(1);
                    list.Add(true);
                    list.Add("a");
                    u.Pack((IList)list);

                    mocks.VerifyWrite((byte)(PackStream.TINY_LIST | list.Count));
                    mocks.VerifyWrite((byte)1);
                    mocks.VerifyWrite(PackStream.TRUE);
                    mocks.VerifyWrite(PackStream.TINY_STRING | 1);
                    mocks.VerifyWrite(new byte[] { 97 });
                }
Ejemplo n.º 30
0
                public void ShouldPackAsList()
                {
                    var mocks = new Mocks();
                    var u     = new PackStream.Packer(mocks.OutputStream, new BigEndianTargetBitConverter());

                    IList <object> list = new List <object>();

                    list.Add(1);
                    list.Add(true);
                    list.Add("a");
                    u.Pack((object)list);

                    mocks.VerifyWrite((byte)(PackStream.TINY_LIST | list.Count));
                    mocks.VerifyWrite((byte)1);
                    mocks.VerifyWrite(PackStream.TRUE);
                    mocks.VerifyWrite(PackStream.TINY_STRING | 1);
                    mocks.VerifyWrite(new byte[] { 97 });
                }