public void WriteSimpleObjectWithFields() { SimpleObjectWithFields obj = new SimpleObjectWithFields { Boolean = true, Byte = 12, SByte = 13, Int16 = 14, UInt16 = 15, Int32 = 16, UInt32 = 17u, Int64 = 18, UInt64 = 19ul, Single = 20.21f, Double = 22.23, Decimal = 2.71828m, String = "string", DateTime = new DateTime(2014, 02, 21, 19, 0, 0, DateTimeKind.Utc), Enum = EnumTest.Value1 }; const string hexBuffer = "AF67426F6F6C65616EF56553427974650D64427974650C65496E7431360E6655496E7431360F65496E743332106655496E7433321165496E743634126655496E7436341366537472696E6766737472696E676653696E676C65FA41A1AE1466446F75626C65FB40363AE147AE147B67446563696D616CFC00000000000425D40000000000050000684461746554696D6574323031342D30322D32315431393A30303A30305A64456E756D6656616C756531"; Helper.TestWrite(obj, hexBuffer, null, new CborOptions { EnumFormat = ValueFormat.WriteToString }); }
public void ReadSimpleObjectWithFields() { const string hexBuffer = "AF67426F6F6C65616EF56553427974650D64427974650C65496E7431360E6655496E7431360F65496E743332106655496E7433321165496E743634126655496E7436341366537472696E6766737472696E676653696E676C65FA41A1AE1466446F75626C65FB40363AE147AE147B67446563696D616CFC00000000000425D40000000000050000684461746554696D6574323031342D30322D32315431393A30303A30305A64456E756D6656616C756531"; SimpleObjectWithFields obj = Helper.Read <SimpleObjectWithFields>(hexBuffer); Assert.NotNull(obj); Assert.True(obj.Boolean); Assert.Equal(12, obj.Byte); Assert.Equal(13, obj.SByte); Assert.Equal(14, obj.Int16); Assert.Equal(15, obj.UInt16); Assert.Equal(16, obj.Int32); Assert.Equal(17u, obj.UInt32); Assert.Equal(18, obj.Int64); Assert.Equal(19ul, obj.UInt64); Assert.Equal(20.21f, obj.Single); Assert.Equal(22.23, obj.Double); Assert.Equal(2.71828m, obj.Decimal); Assert.Equal("string", obj.String); Assert.Equal(new DateTime(2014, 02, 21, 19, 0, 0, DateTimeKind.Utc), obj.DateTime); Assert.Equal(EnumTest.Value1, obj.Enum); }