From 9b699545d3eaa3e103bcb52bbdcfcf82101f006a Mon Sep 17 00:00:00 2001 From: Per Kops Date: Fri, 23 Aug 2024 09:22:54 +0200 Subject: [PATCH] test: add unit-tests for KustoScript --- test/Atc.Kusto.Tests/Atc.Kusto.Tests.csproj | 8 ++++ .../KustoScriptMissingResourceTests.cs | 14 +++++++ test/Atc.Kusto.Tests/KustoScriptTests.cs | 37 +++++++++++++++++++ test/Atc.Kusto.Tests/KustoScriptTests.kusto | 2 + 4 files changed, 61 insertions(+) create mode 100644 test/Atc.Kusto.Tests/KustoScriptMissingResourceTests.cs create mode 100644 test/Atc.Kusto.Tests/KustoScriptTests.cs create mode 100644 test/Atc.Kusto.Tests/KustoScriptTests.kusto diff --git a/test/Atc.Kusto.Tests/Atc.Kusto.Tests.csproj b/test/Atc.Kusto.Tests/Atc.Kusto.Tests.csproj index 29a64bf..a71b387 100644 --- a/test/Atc.Kusto.Tests/Atc.Kusto.Tests.csproj +++ b/test/Atc.Kusto.Tests/Atc.Kusto.Tests.csproj @@ -6,6 +6,14 @@ true + + + + + + + + all diff --git a/test/Atc.Kusto.Tests/KustoScriptMissingResourceTests.cs b/test/Atc.Kusto.Tests/KustoScriptMissingResourceTests.cs new file mode 100644 index 0000000..2e9b929 --- /dev/null +++ b/test/Atc.Kusto.Tests/KustoScriptMissingResourceTests.cs @@ -0,0 +1,14 @@ +namespace Atc.Kusto.Tests; + +public sealed record KustoScriptMissingResourceTests : KustoScript +{ + [Fact] + public void GetQueryText_ShouldThrowFileNotFoundException_WhenResourceDoesNotExist() + { + // Arrange + var script = new KustoScriptMissingResourceTests(); + + // Act & Assert + Assert.Throws(script.GetQueryText); + } +} \ No newline at end of file diff --git a/test/Atc.Kusto.Tests/KustoScriptTests.cs b/test/Atc.Kusto.Tests/KustoScriptTests.cs new file mode 100644 index 0000000..729731f --- /dev/null +++ b/test/Atc.Kusto.Tests/KustoScriptTests.cs @@ -0,0 +1,37 @@ +namespace Atc.Kusto.Tests; + +public sealed record KustoScriptTests : KustoScript +{ + public string SampleProperty { get; set; } = string.Empty; + + [Fact] + public void GetQueryText_ShouldReturnQueryText_WhenResourceExists() + { + // Arrange + var resourceName = $"{GetType().FullName}.kusto"; + using var stream = GetType().Assembly.GetManifestResourceStream(resourceName)!; + using var reader = new StreamReader(stream); + var expectedResult = reader.ReadToEnd(); + + // Act + var queryText = GetQueryText(); + + // Assert + Assert.Equal(expectedResult, queryText); + } + + [Fact] + public void GetParameters_ShouldReturnCorrectParameters_WhenPropertiesArePresent() + { + // Arrange + SampleProperty = "SampleValue"; + + // Act + var parameters = GetParameters(); + + // Assert + Assert.Single(parameters); + Assert.Equal("sampleProperty", parameters.Keys.First()); + Assert.Equal("SampleValue", parameters.Values.First()); + } +} \ No newline at end of file diff --git a/test/Atc.Kusto.Tests/KustoScriptTests.kusto b/test/Atc.Kusto.Tests/KustoScriptTests.kusto new file mode 100644 index 0000000..8323292 --- /dev/null +++ b/test/Atc.Kusto.Tests/KustoScriptTests.kusto @@ -0,0 +1,2 @@ +MySampleTableForUnitTest +| project X, Y, Z \ No newline at end of file