public void StringRoundtrip() { var v1 = ReadOnlyFixedBytes.Random(); var serialized = v1.Serialize(); var v2 = ReadOnlyFixedBytes.Parse(serialized); Assert.Equal(v1, v2); }
public void BufferRoundtrip() { var buffer = new byte[ReadOnlyFixedBytes.MaxLength]; var v1 = ReadOnlyFixedBytes.Random(); v1.Serialize(buffer); var v2 = new ReadOnlyFixedBytes(buffer); Assert.Equal(v1, v2); }
public void BufferPositiveOffsetRoundtrip() { const int offset = 3; var buffer = new byte[ReadOnlyFixedBytes.MaxLength + offset]; var v1 = ReadOnlyFixedBytes.Random(); v1.Serialize(buffer, ReadOnlyFixedBytes.MaxLength, offset); var v2 = new ReadOnlyFixedBytes(buffer, ReadOnlyFixedBytes.MaxLength, offset); Assert.Equal(v1, v2); }
public void BinaryRoundtrip() { using (var ms = new MemoryStream()) { using (var writer = new BinaryWriter(ms)) { var v1 = ReadOnlyFixedBytes.Random(); v1.Serialize(writer); ms.Position = 0; using (var reader = new BinaryReader(ms)) { var v2 = ReadOnlyFixedBytes.ReadFrom(reader); Assert.Equal(v1, v2); } } } }
/// <summary> /// Create a random value. /// </summary> public static Fingerprint Random(int length = MaxLength) { return(new Fingerprint(ReadOnlyFixedBytes.Random(length), length)); }