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 }); }
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); }
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()); }
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); }
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 }); }
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); }
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()); } }
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 }); }
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 }); }
public void ShouldWriteAsNullIfDictionaryIsNull() { var mocks = new WriterTests.Mocks(); var writer = new PackStreamWriter(mocks.OutputStream); writer.Write((IDictionary)null); mocks.VerifyWrite(PackStream.Null); }
public void ShouldWriteFloatNumbersAsDouble(object input, byte expected) { var mocks = new WriterTests.Mocks(); var writer = new PackStreamWriter(mocks.OutputStream); writer.Write(input); mocks.VerifyWrite(expected); }
public void ShouldWriteNullableAsNull(sbyte?input, byte expected) { var mocks = new WriterTests.Mocks(); var writer = new PackStreamWriter(mocks.OutputStream); writer.Write(input); mocks.VerifyWrite(expected); }
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); }
public void ShouldWriteNullSuccessfully() { var mocks = new WriterTests.Mocks(); var writer = new PackStreamWriter(mocks.OutputStream); writer.WriteNull(); mocks.VerifyWrite(PackStream.Null); }
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); }
public void ShouldWriteEmptyStringSuccessfully() { var mocks = new WriterTests.Mocks(); var writer = new PackStreamWriter(mocks.OutputStream); writer.Write(string.Empty); mocks.VerifyWrite(PackStream.TinyString | 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); }
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); }
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); }
public void ShouldWriteUnicodeStringSuccessfully(int size, byte marker, byte[] sizeByte) { var mocks = new WriterTests.Mocks(); var writer = new PackStreamWriter(mocks.OutputStream); var input = new string('å', size); var expected = new byte[size * 2]; for (var i = 0; i < size * 2; i += 2) { expected[i] = 0xC3; expected[i + 1] = 0xA5; } writer.Write(input); mocks.VerifyWrite(marker); mocks.VerifyWrite(sizeByte); mocks.VerifyWrite(expected); }