コード例 #1
0
        public void ID_DoesNotEqual_RandomObject()
        {
            var g = new IdGenerator(0);
            var i = g.FromId(0);

            Assert.IsFalse(i.Equals(new object()));
            Assert.IsTrue(i.Equals((object)g.FromId(0)));
            Assert.IsTrue(i != g.FromId(1));
            Assert.IsTrue(i == g.FromId(0));
            Assert.AreEqual(i.GetHashCode(), g.FromId(0).GetHashCode());
        }
コード例 #2
0
        public void FromId_Returns_CorrectValue()
        {
            var s     = new IdStructure(42, 8, 13);
            var epoch = new DateTimeOffset(2018, 7, 31, 14, 48, 2, TimeSpan.FromHours(2));  // Just some "random" epoch...
            var ts    = new MockTimeSource(5, TimeSpan.FromSeconds(7), epoch);              // Set clock at 5 ticks; each tick being 7 seconds...
                                                                                            // Set generator ID to 234
            var g = new IdGenerator(234, new IdGeneratorOptions(s, ts));

            // Generate a bunch of id's
            long id = 0;

            for (var i = 0; i < 35; i++)
            {
                id = g.CreateId();
            }

            var target = g.FromId(id);


            Assert.AreEqual(34, target.SequenceNumber);                                     // We generated 35 id's in the same tick, so sequence should be at 34.
            Assert.AreEqual(234, target.GeneratorId);                                       // With generator id 234
            Assert.AreEqual(epoch.Add(TimeSpan.FromSeconds(5 * 7)), target.DateTimeOffset); // And the clock was at 5 ticks, with each tick being
                                                                                            // 7 seconds (so 35 seconds from epoch)
                                                                                            // And epoch was 2018-7-31 14:48:02 +02:00...
        }
コード例 #3
0
        public void X()
        {
            var g = new IdGenerator(0);
            var i = g.FromId(1);

            Assert.AreEqual(1, i.SequenceNumber);
            Assert.AreEqual(0, i.GeneratorId);
            Assert.AreEqual(g.Options.TimeSource.Epoch, i.DateTimeOffset);
        }
コード例 #4
0
        public void ID_Equals_OtherId()
        {
            var g = new IdGenerator(0);
            var i = g.FromId(1234567890);

            Assert.IsTrue(i.Equals(g.FromId(1234567890)));
            Assert.IsTrue(i.Equals((object)g.FromId(1234567890)));
            Assert.IsTrue(i != g.FromId(0));
            Assert.IsTrue(i == g.FromId(1234567890));
            Assert.AreEqual(i.GetHashCode(), g.FromId(1234567890).GetHashCode());
        }
コード例 #5
0
ファイル: IdGen.cs プロジェクト: jpdante/Where2Watch
 public static Id FromId(long id) => IdGenerator.FromId(id);