예제 #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>();
                }
예제 #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);
                }
예제 #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 });
                }
예제 #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);
                }
예제 #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);
                }
예제 #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);
                }
예제 #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);
                }
예제 #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 });
                }
예제 #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);
                }
예제 #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);
                }
예제 #11
0
                public void ShouldPackNullBytesSuccessfully()
                {
                    var mocks = new Mocks();
                    var u     = new PackStream.Packer(mocks.OutputStream);

                    u.Pack((byte[])null);
                    mocks.VerifyWrite(PackStream.NULL);
                }
예제 #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);
                }
예제 #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);
                }
예제 #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);
                }
예제 #15
0
                public void ShouldPackAsNullIfDictionaryIsNull()
                {
                    var mocks = new Mocks();
                    var u     = new PackStream.Packer(mocks.OutputStream);

                    u.Pack((IDictionary)null);

                    mocks.VerifyWrite(PackStream.NULL);
                }
예제 #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);
                }
예제 #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());
                }
예제 #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);
                }
예제 #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);
                }
예제 #20
0
                public void ShouldPackAsNull()
                {
                    var mocks = new Mocks();
                    var u     = new PackStream.Packer(mocks.OutputStream);

                    u.Pack((object)null);

                    mocks.VerifyWrite(PackStream.NULL);
                }
예제 #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());
                    }
                }
예제 #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);
                }
예제 #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 });
                }
예제 #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);
                    }
                }
예제 #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 });
                }
예제 #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);
                    }
                }
예제 #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);
                }
예제 #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);
                }
예제 #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 });
                }
예제 #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 });
                }