From 7b7ccde4ad17af69a2fd373433abdcc175ac242e Mon Sep 17 00:00:00 2001 From: Per Kops Date: Tue, 20 Aug 2024 19:39:44 +0200 Subject: [PATCH] test: add unit-tests for QueryIdProvider --- test/Atc.Kusto.Tests/GlobalUsings.cs | 3 +- .../Internal/QueryIdProviderTests.cs | 33 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 test/Atc.Kusto.Tests/Providers/Internal/QueryIdProviderTests.cs diff --git a/test/Atc.Kusto.Tests/GlobalUsings.cs b/test/Atc.Kusto.Tests/GlobalUsings.cs index 729aee5..18c9f51 100644 --- a/test/Atc.Kusto.Tests/GlobalUsings.cs +++ b/test/Atc.Kusto.Tests/GlobalUsings.cs @@ -1 +1,2 @@ -global using Atc.Kusto.Extensions.Internal; \ No newline at end of file +global using Atc.Kusto.Extensions.Internal; +global using Atc.Kusto.Providers.Internal; \ No newline at end of file diff --git a/test/Atc.Kusto.Tests/Providers/Internal/QueryIdProviderTests.cs b/test/Atc.Kusto.Tests/Providers/Internal/QueryIdProviderTests.cs new file mode 100644 index 0000000..3b5444a --- /dev/null +++ b/test/Atc.Kusto.Tests/Providers/Internal/QueryIdProviderTests.cs @@ -0,0 +1,33 @@ +namespace Atc.Kusto.Tests.Providers.Internal; + +public sealed class QueryIdProviderTests +{ + private readonly QueryIdProvider sut = new(); + + [Theory, AutoNSubstituteData] + public void Create_WithValidSessionId_ReturnsExpectedQueryId( + Type queryType, + string sessionId) + { + // Arrange & Act + var actual = sut.Create(queryType, sessionId); + + // Assert + actual + .Should() + .Be($"{queryType.Name}{sessionId.ToAlphaNumeric()}"); + } + + [Theory, AutoNSubstituteData] + public void Create_WithNullSessionId_ReturnsQueryIdWithNewGuid( + Type queryType) + { + // Arrange & Act + var actual = sut.Create(queryType, sessionId: null); + + // Assert + actual + .Should().StartWith(queryType.Name) + .And.HaveLength(queryType.Name.Length + Guid.NewGuid().ToString("N").Length); + } +} \ No newline at end of file