public void standard_returns_version_one() { layout = TimeGuidLayout.Standard; var actual = invoke().ToByteArray(); Assert.Equal(0x10, actual[7] & 0xF0); }
public void standard_returns_node_with_multicast_bit() { layout = TimeGuidLayout.Standard; var actual = invoke().ToByteArray(); Assert.Equal(1, actual[10] & 0x01); }
public void sqlServer_returns_variant_zero() { layout = TimeGuidLayout.SqlServer; var actual = invoke().ToByteArray(); // first bit of byte 8 should be zero Assert.Equal(0, actual[8] & 0x80); }
public void sqlServer_returns_node_with_multicast_bit() { layout = TimeGuidLayout.SqlServer; var guid = invoke(); var actual = guid.ToByteArray(); Assert.Equal(1, actual[0] & 0x01); }
public void sqlServer_returns_original_variant_one() { layout = TimeGuidLayout.SqlServer; var actual = invoke().ToByteArray(); Assert.NotEqual(0, actual[6] & 0x80); Assert.Equal(0, actual[6] & 0x40); }
public void sqlServer_returns_version_one() { layout = TimeGuidLayout.SqlServer; var actual = invoke().ToByteArray(); // first nibble of byte 8 should be one Assert.Equal(1, actual[8] >> 4); }
public void standard_returns_variant_one() { layout = TimeGuidLayout.Standard; var actual = invoke().ToByteArray(); // first bit of byte 8 should be set Assert.NotEqual(0, actual[8] & 0x80); // second bit of byte 8 should not be set Assert.Equal(0, actual[8] & 0x40); }
/// <summary> /// Creates and returns a time-based GUID in the given layout. /// </summary> /// <param name="layout">Layout of the identifier.</param> public Guid Create(TimeGuidLayout layout) { if (!formatters.TryGetValue(layout, out ITimeGuidFormatter formatter)) { throw new NotImplementedException(); } var time = DateTime.UtcNow.Ticks - Epoch; var clockBytes = new byte[2]; var node = new byte[6]; using (var rng = RandomNumberGenerator.Create()) { rng.GetBytes(clockBytes); rng.GetBytes(node); } // set multicast bit on random nodes node[0] |= 0x01; var clock = BitConverter.ToInt16(clockBytes, 0); return(formatter.Create(time, clock, node)); }
/// <summary> /// Creates and returns a time-based GUID in the given layout. /// </summary> /// <param name="layout">Layout of the identifier.</param> public static Guid Create(TimeGuidLayout layout) => Factories.TimeGuidFactory.Instance.Create(layout);
public void requires_valid_layout() { layout = default(TimeGuidLayout); Assert.Throws <NotImplementedException>(() => invoke()); }