public void returns_known_algorithm(NamedGuidAlgorithm algorithm, Type expectedType, byte expectedVersion) { this.algorithm = algorithm; using (var actualAlgorithm = invoke(out byte version)) { Assert.IsAssignableFrom(expectedType, actualAlgorithm); Assert.Equal(expectedVersion, version); } }
public void returns_variant_1(NamedGuidAlgorithm algorithm) { name = $"{Guid.NewGuid()}"; this.algorithm = algorithm; var actual = invoke(); // isolate the first two bits var variant = actual.ToByteArray()[8] & 0b11000000; // ensure the first bit is on, the second bit is off Assert.Equal(0b10000000, variant); }
public void returns_deterministic(NamedGuidAlgorithm algorithm, Guid @namespace, string name, Guid expected) { this.@namespace = @namespace; this.algorithm = algorithm; this.name = name; var actual = invoke(); Assert.Equal(expected, actual); // ensure changing the text yields a different result this.name += "!"; actual = invoke(); Assert.NotEqual(expected, actual); }
public void returns_version_for_algorithm(NamedGuidAlgorithm algorithm) { name = $"{Guid.NewGuid()}"; this.algorithm = algorithm; var actual = invoke(); // isolate the first nibble var version = actual.ToByteArray()[7] & 0b11110000; switch (algorithm) { case NamedGuidAlgorithm.MD5: Assert.Equal(StandardGuidVersion.UUIDv3, version); break; case NamedGuidAlgorithm.SHA1: Assert.Equal(StandardGuidVersion.UUIDv5, version); break; default: throw new InvalidOperationException(); } }
#pragma warning restore CS0618 /// <summary> /// Computes and return a name-based GUID using the given algorithm as defined in https://tools.ietf.org/html/rfc4122#section-4.3. /// </summary> /// <param name="algorithm">Hash algorithm to use for generating the name. SHA-1 is recommended.</param> /// <param name="namespace">Name space identifier.</param> /// <param name="name">Name for which to create a GUID.</param> public static Guid Compute(NamedGuidAlgorithm algorithm, Guid @namespace, string name) => factory.Compute(algorithm, @namespace, name);
public static Guid Create(NamedGuidAlgorithm algorithm, Guid @namespace, string name) => #pragma warning disable CS0618 factory.Create(algorithm, @namespace, name);
public void requires_valid_algorithm() { algorithm = default(NamedGuidAlgorithm); Assert.Throws <NotImplementedException>(() => invoke()); }
public void when_algorithm_unknown_throws() { algorithm = default(NamedGuidAlgorithm); Assert.Throws <NotImplementedException>(() => invoke(out byte version)); }