diff --git a/src/WebExpress.WebUI.Test/WebHtml/UnitTestDeterministicId.cs b/src/WebExpress.WebUI.Test/WebHtml/UnitTestDeterministicId.cs new file mode 100644 index 0000000..64d8e1d --- /dev/null +++ b/src/WebExpress.WebUI.Test/WebHtml/UnitTestDeterministicId.cs @@ -0,0 +1,80 @@ +using WebExpress.WebCore.WebHtml; + +namespace WebExpress.WebUI.Test.WebHtml +{ + /// + /// Unit tests for the DeterministicId class. + /// + [Collection("NonParallelTests")] + public class UnitTestDeterministicId + { + /// + /// Tests that two calls to Create from the same callsite produce different identifiers. + /// + [Fact] + public void CreateSameCallsite() + { + // act + var id1 = CallCreate(); + var id2 = CallCreate(); + + // validation + Assert.NotEqual(id1, id2); + } + + /// + /// Tests that Create with different context values produces different identifiers. + /// + [Fact] + public void CreateIndexes() + { + // act + var id1 = CallCreate(0); + var id2 = CallCreate(1); + + // validation + Assert.NotEqual(id1, id2); + } + + /// + /// Tests that calls from different call sites produce different identifiers. + /// + [Fact] + public void CreateDifferentCallsites() + { + // arrange + var callsiteA = new Func(() => DeterministicId.Create()); + var callsiteB = new Func(() => DeterministicId.Create()); + + // act + var id1 = callsiteA(); + var id2 = callsiteB(); + + // validation + Assert.NotEqual(id1, id2); + } + + /// + /// Generates a deterministic identifier. + /// + /// A string that represents the generated deterministic identifier. + private string CallCreate() + { + return DeterministicId.Create(); + } + + /// + /// Generates a deterministic identifier based on the specified context. + /// + /// + /// The context used to influence the generated identifier. + /// + /// + /// A string that represents the generated deterministic identifier. + /// + private string CallCreate(object context) + { + return DeterministicId.Create(context); + } + } +}