コード例 #1
0
        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)));
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }