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); u.Pack(string.Empty); mocks.VerifyWrite(PackStream.TINY_STRING | 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 }); }
public void ShouldPackNullableAsNull(sbyte?input, byte expected) { var mocks = new Mocks(); var u = new PackStream.Packer(mocks.OutputStream); u.Pack(input); mocks.VerifyWrite(expected); }
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 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 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 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 }); }
public void ShouldPackNullBytesSuccessfully() { var mocks = new Mocks(); var u = new PackStream.Packer(mocks.OutputStream, new BigEndianTargetBitConverter()); u.Pack((byte[])null); mocks.VerifyWrite(PackStream.NULL); }
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); }
public void ShouldPackNullBytesSuccessfully() { var mocks = new Mocks(); var u = new PackStream.Packer(mocks.OutputStream); u.Pack((byte[])null); mocks.VerifyWrite(PackStream.NULL); }
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); }
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); }
public void ShouldPackAsNullIfDictionaryIsNull() { var mocks = new Mocks(); var u = new PackStream.Packer(mocks.OutputStream); u.Pack((IDictionary)null); mocks.VerifyWrite(PackStream.NULL); }
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); }
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 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); }
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); }
public void ShouldPackAsNull() { var mocks = new Mocks(); var u = new PackStream.Packer(mocks.OutputStream); u.Pack((object)null); mocks.VerifyWrite(PackStream.NULL); }
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()); } }
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 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 }); }
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); } }
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 }); }
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 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); }
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); }
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 }); }
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 }); }