public static void Test_UShort_Serializer_Produces_Same_Values_As_Other_Methods(ushort data) { //arrange ITypeSerializerStrategy <ushort> strategy = new GenericTypePrimitiveSharedBufferSerializerStrategy <ushort>(); TestStorageWriterMock writer = new TestStorageWriterMock(); TestStorageReaderMock reader = new TestStorageReaderMock(writer.WriterStream); //act strategy.Write((ushort)data, writer); byte[] stratBytes = writer.GetBytes(); byte[] bitConverted = BitConverter.GetBytes(data); byte[] bitConvertedFromInt = BitConverter.GetBytes((uint)data); byte[] typeStratConverter = strategy.GetBytes((ushort)data); byte[] reversedData = (new EndianReverseDecorator <ushort>(strategy)).GetBytes(data); ushort data2 = (new EndianReverseDecorator <ushort>(strategy)).FromBytes(reversedData); //assert Assert.True(BitConverter.IsLittleEndian); Assert.AreEqual(data, data2); for (int i = 0; i < stratBytes.Length; i++) { Assert.AreEqual(stratBytes[i], bitConverted[i]); Assert.AreEqual(stratBytes[i], bitConvertedFromInt[i]); Assert.AreEqual(stratBytes[i], typeStratConverter[i]); } Assert.AreEqual(stratBytes.First(), reversedData.Last()); Assert.AreEqual(stratBytes.Last(), reversedData.First()); }
public void Test_SByte_Serializer_Writes_And_Reads_Same_Byte(sbyte data) { //arrange ITypeSerializerStrategy strategy = new GenericTypePrimitiveSharedBufferSerializerStrategy <sbyte>(); TestStorageWriterMock writer = new TestStorageWriterMock(); TestStorageReaderMock reader = new TestStorageReaderMock(writer.WriterStream); //act strategy.Write(data, writer); writer.WriterStream.Position = 0; //assert Assert.AreEqual(data, strategy.Read(reader)); }
public void Test_Byte_Serializer_Writes_And_Reads_Same_Byte(UInt16 data) { //arrange ITypeSerializerStrategy strategy = new GenericTypePrimitiveSharedBufferSerializerStrategy <ushort>(); TestStorageWriterMock writer = new TestStorageWriterMock(); TestStorageReaderMock reader = new TestStorageReaderMock(writer.WriterStream); //act strategy.Write(data, writer); writer.WriterStream.Position = 0; UInt16 Int16value = (ushort)strategy.Read(reader); //assert Assert.AreEqual(data, Int16value); }
public void Test_float_Serializer_Writes_And_Reads_Same_float(float data) { //arrange ITypeSerializerStrategy strategy = new GenericTypePrimitiveSharedBufferSerializerStrategy<float>(); TestStorageWriterMock writer = new TestStorageWriterMock(); TestStorageReaderMock reader = new TestStorageReaderMock(writer.WriterStream); //act strategy.Write(data, writer); writer.WriterStream.Position = 0; float b = BitConverter.ToSingle(reader.ReadBytes(4), 0); //assert Assert.AreEqual(data, b); }