Skip to content

Commit

Permalink
test: add unit-tests for KustoScript
Browse files Browse the repository at this point in the history
  • Loading branch information
Per Kops committed Aug 23, 2024
1 parent 2897710 commit 9b69954
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test/Atc.Kusto.Tests/Atc.Kusto.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<None Remove="KustoScriptTests.kusto" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="KustoScriptTests.kusto" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
Expand Down
14 changes: 14 additions & 0 deletions test/Atc.Kusto.Tests/KustoScriptMissingResourceTests.cs
Original file line number Diff line number Diff line change
@@ -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<FileNotFoundException>(script.GetQueryText);
}
}
37 changes: 37 additions & 0 deletions test/Atc.Kusto.Tests/KustoScriptTests.cs
Original file line number Diff line number Diff line change
@@ -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());
}
}
2 changes: 2 additions & 0 deletions test/Atc.Kusto.Tests/KustoScriptTests.kusto
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
MySampleTableForUnitTest
| project X, Y, Z

0 comments on commit 9b69954

Please sign in to comment.