Example #1
0
        private void TestSequence(DbGuid small, DbGuid big)
        {
            Assert.IsTrue(small != big);
            Assert.IsTrue(big != small);

            Assert.IsTrue(small < big);
            Assert.IsTrue(big > small);

            Assert.IsTrue(small <= big);
            Assert.IsTrue(big >= small);

            Assert.IsFalse(small == big);
            Assert.IsFalse(big == small);

            Assert.IsFalse(big < small);
            Assert.IsFalse(small > big);

            Assert.IsFalse(big <= small);
            Assert.IsFalse(small >= big);

            Assert.IsTrue(small.CompareTo(big) < 0);
            Assert.IsTrue(big.CompareTo(small) > 0);

            Assert.IsTrue(DbGuid.Comparer.Compare(small, big) < 0);
            Assert.IsTrue(DbGuid.Comparer.Compare(big, small) > 0);

            Assert.IsTrue(small.ToString().CompareTo(big.ToString()) < 0);
        }
Example #2
0
 public void TestRoundTripBytes()
 {
     DbGuid testA = DbGuid.NewGuid();
     byte[] bytes = testA.ToByteArray();
     DbGuid testB = new DbGuid(bytes);
     Assert.AreEqual(testA, testB);
 }
Example #3
0
        public void TestRoundTrip64Bit()
        {
            DbGuid testA = DbGuid.NewGuid();
            DbGuid testB = new DbGuid(testA.High64, testA.Low64);

            Assert.AreEqual(testA, testB);
        }
Example #4
0
        private void TestEquality(DbGuid testA, DbGuid testB, bool expect)
        {
            for (int i = 0; i < 2; i++)
            {
                Assert.AreEqual(expect, testA.GetHashCode() == testB.GetHashCode());
                Assert.AreEqual(expect, DbGuid.Comparer.GetHashCode(testA) == DbGuid.Comparer.GetHashCode(testB));

                Assert.AreEqual(expect, testA == testB);
                Assert.AreEqual(!expect, testA != testB);

                Assert.AreEqual(expect, ((object)testA).Equals(testB));
                Assert.AreEqual(expect, ((IEquatable <DbGuid>)testA).Equals(testB));

                Assert.AreEqual(expect, ((IComparable)testA).CompareTo(testB) == 0);
                Assert.AreEqual(expect, ((IComparable <DbGuid>)testA).CompareTo(testB) == 0);

                Assert.AreEqual(expect, DbGuid.Comparer.Equals(testA, testB));
                Assert.AreEqual(expect, DbGuid.Comparer.Compare(testA, testB) == 0);

                Assert.AreEqual(expect, testA.ToString() == testB.ToString());
                Assert.AreEqual(expect, testA.ToString("N") == testB.ToString("N"));
                Assert.AreEqual(expect, testA.ToString("N", null) == testB.ToString("N", null));

                //swap and try again
                DbGuid tmp = testA;
                testA = testB;
                testB = tmp;
            }
        }
Example #5
0
        public void TestDiscreteCtor()
        {
            DbGuid testA = new DbGuid(0x01020304, 0x0506, 0x0708, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80);
            Guid   testB = new Guid(0x01020304, 0x0506, 0x0708, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80);

            Assert.AreEqual(testB, testA.ToGuid());
        }
Example #6
0
        public void GuidCompare()
        {
            DbGuid a = DbGuid.NewGuid();
            DbGuid b = DbGuid.NewGuid();

            Assert.AreEqual(-1, a.CompareTo(b));
            Assert.AreEqual(-1, a.ToGuid().CompareTo(b.ToGuid()));
        }
Example #7
0
        public void TestRoundTripGuidToDbGuid()
        {
            Guid   testA  = Guid.NewGuid();
            DbGuid dbtest = (DbGuid)testA;
            Guid   testB  = dbtest.ToGuid();

            Assert.AreEqual(testA, testB);
        }
Example #8
0
        public void TestRoundTripDbGuidToGuid()
        {
            DbGuid testA  = DbGuid.NewGuid();
            Guid   dbtest = testA;
            DbGuid testB  = (DbGuid)dbtest;

            Assert.AreEqual(testA, testB);
        }
Example #9
0
 public void TestRoundTripByteOffset()
 {
     DbGuid testA = DbGuid.NewGuid();
     byte[] bytes = new byte[1024];
     testA.ToByteArray(bytes, 512);
     DbGuid testB = new DbGuid(bytes, 512);
     Assert.AreEqual(testA, testB);
 }
Example #10
0
        public void TestRoundTripBytes()
        {
            DbGuid testA = DbGuid.NewGuid();

            byte[] bytes = testA.ToByteArray();
            DbGuid testB = new DbGuid(bytes);

            Assert.AreEqual(testA, testB);
        }
Example #11
0
        public void TestEquality()
        {
            DbGuid testA = DbGuid.NewGuid();

            TestEquality(testA, testA, true);
            TestEquality(testA, DbGuid.NewGuid(), false);
            TestEquality(testA, new DbGuid(Guid.NewGuid()), false);
            TestEquality(testA, testA.ToSqlGuid(), true);
            TestEquality(testA, testA.ToSqlGuid().ToSequenceGuid(), true);
        }
Example #12
0
        public void TestRoundTripByteOffset()
        {
            DbGuid testA = DbGuid.NewGuid();

            byte[] bytes = new byte[1024];
            testA.ToByteArray(bytes, 512);
            DbGuid testB = new DbGuid(bytes, 512);

            Assert.AreEqual(testA, testB);
        }
Example #13
0
        public void TestDateTime()
        {
            // Note: DateTime precision is +/- 1ms
            DateTime start = DateTime.UtcNow.AddMilliseconds(-1);
            DbGuid   test  = DbGuid.NewGuid();

            Assert.IsTrue(test.ToDateTimeUtc() > start, "expected {0} > {1}", test.ToDateTimeUtc(), start);
            DateTime now = DateTime.UtcNow.AddMilliseconds(1);

            Assert.IsTrue(test.ToDateTimeUtc() <= now, "expected {0} <= {1}", test.ToDateTimeUtc(), now);
        }
Example #14
0
        public void TestRoundTripSqlGuid()
        {
            DbGuid testA  = DbGuid.NewGuid();
            DbGuid dbtest = testA.ToSqlGuid();

            Assert.AreEqual(dbtest, testA);
            Assert.AreEqual(dbtest.GetHashCode(), testA.GetHashCode());
            Assert.AreEqual(0, dbtest.CompareTo(testA));
            DbGuid testB = dbtest.ToSequenceGuid();

            Assert.AreEqual(testA, testB);
        }
Example #15
0
        public void TestSequence()
        {
            DbGuid last = DbGuid.NewGuid();

            for (int i = 0; i < 10000; i++)
            {
                DbGuid test = DbGuid.NewGuid();
                TestSequence(last, test);
                TestSequence(last, test.ToSqlGuid());
                TestSequence(last.ToSqlGuid(), test);
                TestSequence(last.ToSqlGuid(), test.ToSqlGuid());
                Assert.IsTrue(last.CompareTo(test) < 0);
                last = test;
            }
        }
Example #16
0
        public void TestGenerationPerf()
        {
            var timer = Stopwatch.StartNew();
            int total = 0, target = 0;

            while (timer.ElapsedMilliseconds < 1000)
            {
                for (target += 1000000; total < target; total++)
                {
                    DbGuid.NewGuid();
                }
            }
            timer.Stop();
            Console.WriteLine("Generated {0:n0} guids in {1:n2} seconds, averaging {2:n2} per second.",
                              total, timer.Elapsed.TotalSeconds, total / timer.Elapsed.TotalSeconds);
        }
Example #17
0
        public void TestSerializer()
        {
            DbGuid[]     ids    = new DbGuid[16];
            MemoryStream stream = new MemoryStream();

            for (int i = 0; i < ids.Length; i++)
            {
                ids[i] = DbGuid.NewGuid();
                DbGuid.Serializer.WriteTo(ids[i], stream);
            }
            stream.Position = 0;
            for (int i = 0; i < ids.Length; i++)
            {
                DbGuid test = DbGuid.Serializer.ReadFrom(stream);
                Assert.AreEqual(ids[i], test);
            }
            Assert.AreEqual(-1, stream.ReadByte());
        }
 public static DbGuid Coalesce(this DbFunctions dbFunctions, DbGuid value, params IDbFragment[] other)
 {
     return(new DbGuidFunctionValue("coalesce", new[] { value }.Concat(other)));
 }
Example #19
0
        private void TestSequence(DbGuid small, DbGuid big)
        {
            Assert.IsTrue(small != big);
            Assert.IsTrue(big != small);

            Assert.IsTrue(small < big);
            Assert.IsTrue(big > small);

            Assert.IsTrue(small <= big);
            Assert.IsTrue(big >= small);

            Assert.IsFalse(small == big);
            Assert.IsFalse(big == small);

            Assert.IsFalse(big < small);
            Assert.IsFalse(small > big);
            
            Assert.IsFalse(big <= small);
            Assert.IsFalse(small >= big);
            
            Assert.IsTrue(small.CompareTo(big) < 0);
            Assert.IsTrue(big.CompareTo(small) > 0);

            Assert.IsTrue(DbGuid.Comparer.Compare(small, big) < 0);
            Assert.IsTrue(DbGuid.Comparer.Compare(big, small) > 0);
            
            Assert.IsTrue(small.ToString().CompareTo(big.ToString()) < 0);
        }
Example #20
0
        private void TestEquality(DbGuid testA, DbGuid testB, bool expect)
        {
            for (int i = 0; i < 2; i++)
            {
                Assert.AreEqual(expect, testA.GetHashCode() == testB.GetHashCode());
                Assert.AreEqual(expect, DbGuid.Comparer.GetHashCode(testA) == DbGuid.Comparer.GetHashCode(testB));

                Assert.AreEqual(expect, testA == testB);
                Assert.AreEqual(!expect, testA != testB);

                Assert.AreEqual(expect, ((object) testA).Equals(testB));
                Assert.AreEqual(expect, ((IEquatable<DbGuid>) testA).Equals(testB));

                Assert.AreEqual(expect, ((IComparable)testA).CompareTo(testB) == 0);
                Assert.AreEqual(expect, ((IComparable<DbGuid>)testA).CompareTo(testB) == 0);

                Assert.AreEqual(expect, DbGuid.Comparer.Equals(testA, testB));
                Assert.AreEqual(expect, DbGuid.Comparer.Compare(testA, testB) == 0);

                Assert.AreEqual(expect, testA.ToString() == testB.ToString());
                Assert.AreEqual(expect, testA.ToString("N") == testB.ToString("N"));
                Assert.AreEqual(expect, testA.ToString("N", null) == testB.ToString("N", null));

                //swap and try again
                DbGuid tmp = testA;
                testA = testB;
                testB = tmp;
            }
        }
Example #21
0
 public void TestRoundTrip64Bit()
 {
     DbGuid testA = DbGuid.NewGuid();
     DbGuid testB = new DbGuid(testA.High64, testA.Low64);
     Assert.AreEqual(testA, testB);
 }
Example #22
0
 public void TestDiscreteCtor()
 {
     DbGuid testA = new DbGuid(0x01020304, 0x0506, 0x0708, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80);
     Guid testB = new Guid(0x01020304, 0x0506, 0x0708, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80);
     Assert.AreEqual(testB, testA.ToGuid());
 }
Example #23
0
 public void TestSerializer()
 {
     DbGuid[] ids = new DbGuid[16];
     MemoryStream stream = new MemoryStream();
     for (int i = 0; i < ids.Length; i++)
     {
         ids[i] = DbGuid.NewGuid();
         DbGuid.Serializer.WriteTo(ids[i], stream);
     }
     stream.Position = 0;
     for (int i = 0; i < ids.Length; i++)
     {
         DbGuid test = DbGuid.Serializer.ReadFrom(stream);
         Assert.AreEqual(ids[i], test);
     }
     Assert.AreEqual(-1, stream.ReadByte());
 }