public void Should_keep_them_ordered_for_ToSequentialGuid_when_using_array_call() { var generator = new NewIdGenerator(_tickProvider, _workerIdProvider); generator.Next(); int limit = 1024; var ids = new NewId[limit]; generator.Next(ids, 0, limit); for (int i = 0; i < limit - 1; i++) { Assert.AreNotEqual(ids[i], ids[i + 1]); Guid left = ids[i].ToSequentialGuid(); Guid right = ids[i + 1].ToSequentialGuid(); Assert.Less(left, right); if (i % 128 == 0) { Console.WriteLine("Sql: {0}", left); } } }
public void Should_keep_them_ordered_for_sql_server() { var generator = new NewIdGenerator(new TimeLapseTickProvider(), new NetworkAddressWorkerIdProvider()); generator.Next(); int limit = 1024; var ids = new NewId[limit]; for (int i = 0; i < limit; i++) { ids[i] = generator.Next(); } for (int i = 0; i < limit - 1; i++) { Assert.AreNotEqual(ids[i], ids[i + 1]); SqlGuid left = ids[i].ToGuid(); SqlGuid right = ids[i + 1].ToGuid(); Assert.Less(left, right); if (i % 16 == 0) { Console.WriteLine(ids[i]); } } }
public void Should_keep_them_ordered_for_sql_server() { var generator = new NewIdGenerator(new TimeLapseTickProvider(), new NetworkAddressWorkerIdProvider()); generator.Next(); int limit = 1024; var ids = new NewId[limit]; for (int i = 0; i < limit; i++) { ids[i] = generator.Next(); } for (int i = 0; i < limit - 1; i++) { Assert.AreNotEqual(ids[i], ids[i + 1]); SqlGuid left = ids[i].ToGuid(); SqlGuid right = ids[i + 1].ToGuid(); //Assert.IsTrue(left.Value < right.Value); if (i % 128 == 0) { Console.WriteLine("Normal: {0} Sql: {1}", left, ids[i].ToSequentialGuid()); } } }
public void Should_match_when_all_providers_equal_with_guid_method() { // Arrange var generator1 = new NewIdGenerator(_tickProvider, _workerIdProvider, _processIdProvider); var generator2 = new NewIdGenerator(_tickProvider, _workerIdProvider, _processIdProvider); generator1.Next().ToGuid(); generator2.NextGuid(); // Act var id1 = generator1.Next().ToGuid(); var id2 = generator2.NextGuid(); // Assert Assert.AreEqual(id1, id2); }
public void Should_keep_them_ordered_for_sql_server() { var generator = new NewIdGenerator(new TimeLapseTickProvider(), new NetworkAddressWorkerIdProvider()); generator.Next(); int limit = 1024; var ids = new NewId[limit]; for (int i = 0; i < limit; i++) { ids[i] = generator.Next(); } for (int i = 0; i < limit - 1; i++) { Assert.AreNotEqual(ids[i], ids[i + 1]); Assert.Less(ids[i], ids[i + 1]); if (i%16 == 0) Console.WriteLine(ids[i]); } }
public void Should_keep_them_ordered_for_sql_server() { var generator = new NewIdGenerator(new TimeLapseTickProvider(), new NetworkAddressWorkerIdProvider()); generator.Next(); int limit = 1024; var ids = new NewId[limit]; for (int i = 0; i < limit; i++) ids[i] = generator.Next(); for (int i = 0; i < limit - 1; i++) { Assert.AreNotEqual(ids[i], ids[i + 1]); SqlGuid left = ids[i].ToGuid(); SqlGuid right = ids[i + 1].ToGuid(); Assert.Less(left, right); if (i % 128 == 0) Console.WriteLine("Normal: {0} Sql: {1}", left, ids[i].ToSequentialGuid()); } }
public void Should_not_match_when_processor_id_provided() { // Arrange var generator1 = new NewIdGenerator(_tickProvider, _workerIdProvider); var generator2 = new NewIdGenerator(_tickProvider, _workerIdProvider, _processIdProvider); // Act var id1 = generator1.Next(); var id2 = generator2.Next(); // Assert Assert.AreNotEqual(id1, id2); }
public void Should_not_match_when_generated_from_two_processes() { // Arrange var generator1 = new NewIdGenerator(_tickProvider, _workerIdProvider, _processIdProvider); _processIdProvider = new MockProcessIdProvider(BitConverter.GetBytes(11)); var generator2 = new NewIdGenerator(_tickProvider, _workerIdProvider, _processIdProvider); // Act var id1 = generator1.Next(); var id2 = generator2.Next(); // Assert Assert.AreNotEqual(id1, id2); }
public void Should_keep_them_ordered_for_ToSequentialGuid_when_using_different_mac_addresses() { var generator1 = new NewIdGenerator(_tickProvider, new MockNetworkProvider(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, })); var generator2 = new NewIdGenerator(_tickProvider, new MockNetworkProvider(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, })); var id1 = generator1.Next(); var id2 = generator2.Next(); Assert.AreNotEqual(id1, id2); Guid left = id1.ToSequentialGuid(); Guid right = id2.ToSequentialGuid(); Assert.Less(left, right); Console.WriteLine("Sql: {0}", left); Console.WriteLine("Sql: {0}", right); }
public void Should_keep_them_ordered_for_ToSequentialGuid_when_using_different_processes() { var generator1 = new NewIdGenerator(_tickProvider, _workerIdProvider, new MockProcessIdProvider(BitConverter.GetBytes(1))); var generator2 = new NewIdGenerator(_tickProvider, _workerIdProvider, new MockProcessIdProvider(BitConverter.GetBytes(256))); var id1 = generator1.Next(); var id2 = generator2.Next(); Assert.AreNotEqual(id1, id2); Guid left = id1.ToSequentialGuid(); Guid right = id2.ToSequentialGuid(); Assert.Less(left, right); Console.WriteLine("Sql: {0}", left); Console.WriteLine("Sql: {0}", right); }
public void Should_match_sequentially() { var generator = new NewIdGenerator(_tickProvider, _workerIdProvider); var id1 = generator.Next().ToGuid(); var id2 = generator.NextGuid(); var id3 = generator.NextGuid(); Assert.AreNotEqual(id1, id2); Assert.AreNotEqual(id2, id3); Assert.Greater(id2, id1); Console.WriteLine(id1); Console.WriteLine(id2); Console.WriteLine(id3); NewId nid1 = id1.ToNewId(); NewId nid2 = id2.ToNewId(); }