public void InvalidRandomness() { var d = DateTimeOffset.Now; // short length Assert.Throws <ArgumentOutOfRangeException>(() => CliUtil.CreateUlid(d, "A")); // invalid character Assert.Throws <InvalidOperationException>(() => CliUtil.CreateUlid(d, new string('+', 16))); }
public void SameTime() { var d = new DateTimeOffset(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)); var first = CliUtil.CreateUlid(d, null); var second = CliUtil.CreateUlid(d, null); first.Time.Should().Be(d); second.Time.Should().Be(d); first.Random.Should().NotBeEquivalentTo(second.Random); }
public void SameRandomness(char c) { var r1 = new string(c, 16).ToLower(); var r2 = new string(c, 16).ToUpper(); var d = DateTimeOffset.Parse("1970-1-1T00:00:00Z"); var first = CliUtil.CreateUlid(DateTimeOffset.Now, r1); var second = CliUtil.CreateUlid(DateTimeOffset.Now, r2); first.Random.Should().BeEquivalentTo(second.Random); }
public async Task Default() { var first = CliUtil.CreateUlid(DateTimeOffset.Now, null); await Task.Delay(1).ConfigureAwait(false); // empty string is treated same as null var second = CliUtil.CreateUlid(DateTimeOffset.Now, ""); first.Time.Should().NotBe(second.Time); first.Random.Should().NotBeEquivalentTo(second.Random); }