public void Should_support_the_same_constructor() { var guid = new Guid(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); var newid = new NewIds.NewId(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); Assert.AreEqual(guid.ToString(), newid.ToString()); }
public void Should_generate_unique_identifiers_with_each_invocation() { NewIds.NewId.Next(); Stopwatch timer = Stopwatch.StartNew(); int limit = 1024 * 1024; var ids = new NewIds.NewId[limit]; for (int i = 0; i < limit; i++) { ids[i] = NewIds.NewId.Next(); } timer.Stop(); for (int i = 0; i < limit - 1; i++) { Assert.AreNotEqual(ids[i], ids[i + 1]); string end = ids[i].ToString().Substring(32, 4); if (end == "0000") { Console.WriteLine("{0}", ids[i].ToString()); } } Console.WriteLine("Generated {0} ids in {1}ms ({2}/ms)", limit, timer.ElapsedMilliseconds, limit / timer.ElapsedMilliseconds); }
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 NewIds.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_convert_using_custom_base32_formatting_characters() { var n = new NewIds.NewId("F6B27C7C-8AB8-4498-AC97-3A6107A21320"); var formatter = new Base32Formatter("0123456789ABCDEFGHIJKLMNOPQRSTUV"); string ns = n.ToString(formatter); Assert.AreEqual("UQP7OV4AN129HB4N79GGF8GJ10", ns); }
public void Should_make_the_round_trip_successfully_via_bytes() { Guid g = Guid.NewGuid(); var n = new NewIds.NewId(g.ToByteArray()); var gn = new Guid(n.ToByteArray()); Assert.AreEqual(g, gn); }
public void Should_convert_using_standard_base32_formatting_characters() { var n = new NewIds.NewId("F6B27C7C-8AB8-4498-AC97-3A6107A21320"); var formatter = new Base32Formatter(true); string ns = n.ToString(formatter); Assert.AreEqual("62ZHY7EKXBCJRLEXHJQQPIQTBA", ns); }
public void Should_convert_using_the_optimized_human_readable_formatter() { var n = new NewIds.NewId("F6B27C7C-8AB8-4498-AC97-3A6107A21320"); var formatter = new ZBase32Formatter(true); string ns = n.ToString(formatter); Assert.AreEqual("6438A9RKZBNJTMRZ8JOOXEOUBY", ns); }
public void Should_convert_from_a_guid_quickly() { Guid g = Guid.NewGuid(); NewIds.NewId n = g.ToNewId(); string ns = n.ToString(); string gs = g.ToString(); Assert.AreEqual(ns, gs); }
public void Should_convert_to_guid_quickly() { NewIds.NewId n = NewIds.NewId.Next(); Guid g = n.ToGuid(); string ns = n.ToString(); string gs = g.ToString(); Assert.AreEqual(ns, gs); }
public void Should_work_from_guid_to_newid_to_guid() { Guid g = Guid.NewGuid(); var n = new NewIds.NewId(g.ToByteArray()); string gs = g.ToString("d"); string ns = n.ToString("d"); Assert.AreEqual(gs, ns); }
public void Should_properly_handle_string_passthrough() { NewIds.NewId n = NewIds.NewId.Next(); string ns = n.ToString("D"); var g = new Guid(ns); var nn = new NewIds.NewId(g.ToString("D")); Assert.AreEqual(n, nn); }
public void Should_match_string_output_n() { var bytes = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 14, 15 }; var g = new Guid(bytes); var n = new NewIds.NewId(bytes); string gs = g.ToString("N"); string ns = n.ToString("N"); Assert.AreEqual(gs, ns); }
public void Should_work_from_newid_to_guid_to_newid() { NewIds.NewId n = NewIds.NewId.Next(); var g = new Guid(n.ToByteArray()); var ng = new NewIds.NewId(g.ToByteArray()); Console.WriteLine(g.ToString("D")); Assert.AreEqual(n, ng); }
public void Should_translate_often_transposed_characters_to_proper_values() { var n = new NewIds.NewId("F6B27C7C-8AB8-4498-AC97-3A6107A21320"); string ns = "6438A9RK2BNJTMRZ8J0OXE0UBY"; var parser = new ZBase32Parser(true); NewIds.NewId newId = parser.Parse(ns); Assert.AreEqual(n, newId); }
public void Should_convert_back_using_standard_parser() { var n = new NewIds.NewId("F6B27C7C-8AB8-4498-AC97-3A6107A21320"); var formatter = new Base32Formatter(true); string ns = n.ToString(formatter); var parser = new Base32Parser(); NewIds.NewId newId = parser.Parse(ns); Assert.AreEqual(n, newId); }
public void Should_be_able_to_extract_timestamp() { DateTime now = DateTime.UtcNow; NewIds.NewId id = NewIds.NewId.Next(); DateTime timestamp = id.Timestamp; Console.WriteLine("Now: {0}, Timestamp: {1}", now, timestamp); TimeSpan difference = (timestamp - now); if (difference < TimeSpan.Zero) { difference = difference.Negate(); } Assert.LessOrEqual(difference, TimeSpan.FromMinutes(1)); }
public void Should_generate_sequential_ids_quickly() { NewIds.NewId.SetTickProvider(new StopwatchTickProvider()); NewIds.NewId.Next(); int limit = 10; var ids = new NewIds.NewId[limit]; for (int i = 0; i < limit; i++) { ids[i] = NewIds.NewId.Next(); } for (int i = 0; i < limit - 1; i++) { Assert.AreNotEqual(ids[i], ids[i + 1]); Console.WriteLine(ids[i]); } }
public void Should_format_just_like_a_default_guid_formatter() { var newId = new NewIds.NewId(); Assert.AreEqual("00000000-0000-0000-0000-000000000000", newId.ToString()); }
public void Should_display_sequentially_for_newid() { NewIds.NewId id = NewIds.NewId.Next(); Console.WriteLine(id.ToString("DS")); }
public void Should_format_just_like_a_fancy_guid_formatter() { var newId = new NewIds.NewId(); Assert.AreEqual("{00000000-0000-0000-0000-000000000000}", newId.ToString("B")); }
public void Should_format_just_like_a_parenthesis_guid_formatter() { var newId = new NewIds.NewId(); Assert.AreEqual("(00000000-0000-0000-0000-000000000000)", newId.ToString("P")); }
public void Should_format_just_like_a_narrow_guid_formatter() { var newId = new NewIds.NewId(); Assert.AreEqual("00000000000000000000000000000000", newId.ToString("N")); }