public void BigEndianBinaryWriterConstructorEncodingTest()
 {
     Stream output = new MemoryStream();
     Encoding encoding = Encoding.UTF7;
     BigEndianBinaryWriter target = new BigEndianBinaryWriter(new StreamAdapter(output), encoding);
     PrivateObject po = new PrivateObject(target);
     BigEndianBinaryWriter_Accessor accessor = new BigEndianBinaryWriter_Accessor(po);
     Assert.AreSame(accessor.Encoding, encoding);
 }
 public void BigEndianBinaryWriterConstructorEncodingUtf16Test()
 {
     byte[] expected = new byte[] { 0, 0, 0, 6, 97, 00, 98, 00, 99, 00 }; // "abc" string in utf16 + int string length in bytes
     MemoryStream output = new MemoryStream();
     Encoding encoding = Encoding.Unicode;
     BigEndianBinaryWriter target = new BigEndianBinaryWriter(new StreamAdapter(output), encoding);
     string input = "abc";
     target.Write(input);
     byte[] actual = output.ToArray();
     MyAssert.AreEqual(expected, actual);
 }
 public void WriteDoubleTest()
 {
     MemoryStream output = new MemoryStream();
     BigEndianBinaryWriter target = new BigEndianBinaryWriter(new StreamAdapter(output));
     double data = 1.23123456789000002231659891549E2;
     target.Write(data);
     byte[] expected = new byte[] { 0x40, 0x5E, 0xC7, 0xE6, 0xB7, 0x4D, 0xCE, 0x59 }; // 1.23123456789000002231659891549E2 in IEEE Double in Big endian representation with double precision (64 bit)
     byte[] actual = output.ToArray();
     MyAssert.AreEqual(expected, actual);
 }
 public void WriteLongTest()
 {
     MemoryStream output = new MemoryStream();
     BigEndianBinaryWriter target = new BigEndianBinaryWriter(new StreamAdapter(output));
     long data = 1234567890123456789;
     target.Write(data);
     byte[] expected = new byte[] { 0x11, 0x22, 0x10, 0xF4, 0x7D, 0xE9, 0x81, 0x15 };
     byte[] actual = output.ToArray();
     MyAssert.AreEqual(expected, actual);
 }
 public void WriteFloatTest()
 {
     MemoryStream output = new MemoryStream();
     BigEndianBinaryWriter target = new BigEndianBinaryWriter(new StreamAdapter(output));
     float data = 1.23f; 
     target.Write(data);
     byte[] expected = new byte[] { 0x3F, 0x9D, 0x70, 0xA4 }; // 1.23 in IEEE Float in Big endian representation with single precision (32 bit)
     byte[] actual = output.ToArray();
     MyAssert.AreEqual(expected, actual);
 }
 public void WriteBooleanTest()
 {
     MemoryStream output = new MemoryStream();
     BigEndianBinaryWriter target = new BigEndianBinaryWriter(new StreamAdapter(output));
     // false
     bool data = false; 
     target.Write(data);
     byte[] expected = new byte[] { 0, 0, 0, 0 }; // 0  = false
     byte[] actual = output.ToArray();
     MyAssert.AreEqual(expected, actual);
     // true
     output.Position = 0;
     data = true;
     target.Write(data);
     expected = new byte[] { 0, 0, 0, 1 }; // otherwise true
     actual = output.ToArray();
     MyAssert.AreEqual(expected, actual);
 }
 public void WriteDateTimeTest()
 {
     MemoryStream output = new MemoryStream();
     BigEndianBinaryWriter target = new BigEndianBinaryWriter(new StreamAdapter(output));
     DateTime data = new DateTime(1970, 1, 1, 0, 0, 1, DateTimeKind.Utc).ToLocalTime(); // 01.01.1970 00:00:01 UTC
     target.Write(data);
     byte[] expected = new byte[] { 0, 0, 0, 1 }; // 1 sec from Unix epoch
     byte[] actual = output.ToArray();
     MyAssert.AreEqual(expected, actual);
 }
 public void WriteStringTest()
 {
     MemoryStream output = new MemoryStream();
     BigEndianBinaryWriter target = new BigEndianBinaryWriter(new StreamAdapter(output));
     string data = "abc"; 
     target.Write(data);
     byte[] expected = new byte[] { 0, 0, 0, 3, 97, 98, 99 }; // 'abc' string in utf-8 + prefix int with string length
     byte[] actual = output.ToArray();
     MyAssert.AreEqual(expected, actual);
 }
 public void WriteByteArrayTest()
 {
     MemoryStream output = new MemoryStream();
     BigEndianBinaryWriter target = new BigEndianBinaryWriter(new StreamAdapter(output));
     byte[] expected = new byte[] { 1, 2, 3 };
     target.Write(expected);
     byte[] actual = output.ToArray();
     MyAssert.AreEqual(expected, actual);
 }
 public void WriteIntTest()
 {
     MemoryStream output = new MemoryStream();
     BigEndianBinaryWriter target = new BigEndianBinaryWriter(new StreamAdapter(output));
     int data = 16776960;
     byte[] expected = new byte[] { 0x00, 0xFF, 0xFF, 0x00 }; // 16776960 in Big endian representation
     target.Write(data);
     byte[] actual = output.ToArray();
     MyAssert.AreEqual(expected, actual);
 }
        public void WriteShortTest()
        {
            MemoryStream output = new MemoryStream();
            BigEndianBinaryWriter target = new BigEndianBinaryWriter(new StreamAdapter(output));
            short data = 12345;
            byte[] expected = new byte[] { 0x30, 0x39 }; // 12345 in Big endian representation
            target.Write(data);
		    byte[] actual = output.ToArray();
            MyAssert.AreEqual(expected, actual);
        }
 public void WriteByteTest()
 {
     MemoryStream output = new MemoryStream();
     BigEndianBinaryWriter target = new BigEndianBinaryWriter(new StreamAdapter(output));
     byte expected = 255;
     target.Write(expected);
     byte actual = output.ToArray()[0];
     Assert.AreEqual(expected, actual);
 }