Skip to content

Adds model unit tests and Update Policy schema validation #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions KustoSchemaTools.Tests/KustoSchemaTools.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.0" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="xunit" Version="2.9.3" />
Expand Down
47 changes: 47 additions & 0 deletions KustoSchemaTools.Tests/Model/AADObjectModelTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using FluentAssertions;
using KustoSchemaTools.Model;

namespace KustoSchemaTools.Tests.Model
{
public class AADObjectModelTests
{
[Fact]
public void AADObject_Should_Initialize_With_Default_Values()
{
// Act
var aadObject = new AADObject();

// Assert
aadObject.Name.Should().BeNull();
aadObject.Id.Should().BeNull();
}

[Fact]
public void AADObject_Should_Allow_Property_Assignment()
{
// Arrange
var aadObject = new AADObject();

// Act
aadObject.Name = "[email protected]";
aadObject.Id = "12345678-1234-1234-1234-123456789012";

// Assert
aadObject.Name.Should().Be("[email protected]");
aadObject.Id.Should().Be("12345678-1234-1234-1234-123456789012");
}

[Fact]
public void AADObject_Should_Support_Equality_Comparison()
{
// Arrange
var aadObject1 = new AADObject { Name = "[email protected]", Id = "12345" };
var aadObject2 = new AADObject { Name = "[email protected]", Id = "12345" };
var aadObject3 = new AADObject { Name = "[email protected]", Id = "12345" };

// Act & Assert
aadObject1.Should().BeEquivalentTo(aadObject2);
aadObject1.Should().NotBeEquivalentTo(aadObject3);
}
}
}
38 changes: 38 additions & 0 deletions KustoSchemaTools.Tests/Model/ClusterModelTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using FluentAssertions;
using KustoSchemaTools.Model;

namespace KustoSchemaTools.Tests.Model
{
public class ClusterModelTests
{
[Fact]
public void Cluster_Should_Initialize_With_Default_Values()
{
// Act
var cluster = new Cluster();

// Assert
cluster.Name.Should().BeNull();
cluster.Url.Should().BeNull();
cluster.Scripts.Should().NotBeNull().And.BeEmpty();
}

[Fact]
public void Cluster_Should_Allow_Property_Assignment()
{
// Arrange
var cluster = new Cluster();
var script = new DatabaseScript("show cluster", 10);

// Act
cluster.Name = "TestCluster";
cluster.Url = "https://test.kusto.windows.net";
cluster.Scripts.Add(script);

// Assert
cluster.Name.Should().Be("TestCluster");
cluster.Url.Should().Be("https://test.kusto.windows.net");
cluster.Scripts.Should().ContainSingle().Which.Should().Be(script);
}
}
}
76 changes: 76 additions & 0 deletions KustoSchemaTools.Tests/Model/ContinuousExportModelTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using FluentAssertions;
using KustoSchemaTools.Model;

namespace KustoSchemaTools.Tests.Model
{
public class ContinuousExportModelTests
{
[Fact]
public void ContinuousExport_Should_Initialize_With_Default_Values()
{
// Act
var continuousExport = new ContinuousExport();

// Assert
continuousExport.ExternalTable.Should().BeNull();
continuousExport.Query.Should().BeNull();
continuousExport.ManagedIdentity.Should().BeNull();
continuousExport.IntervalBetweenRuns.Should().Be(0);
continuousExport.ForcedLatencyInMinutes.Should().Be(0);
continuousExport.SizeLimit.Should().Be(0);
continuousExport.Distributed.Should().BeFalse();
}

[Fact]
public void ContinuousExport_Should_Allow_Property_Assignment()
{
// Arrange
var continuousExport = new ContinuousExport();

// Act
continuousExport.ExternalTable = "ExternalEvents";
continuousExport.Query = "Events | where timestamp > ago(1h)";
continuousExport.ManagedIdentity = "system";
continuousExport.IntervalBetweenRuns = 30;
continuousExport.ForcedLatencyInMinutes = 5;
continuousExport.SizeLimit = 1000000;
continuousExport.Distributed = true;

// Assert
continuousExport.ExternalTable.Should().Be("ExternalEvents");
continuousExport.Query.Should().Be("Events | where timestamp > ago(1h)");
continuousExport.ManagedIdentity.Should().Be("system");
continuousExport.IntervalBetweenRuns.Should().Be(30);
continuousExport.ForcedLatencyInMinutes.Should().Be(5);
continuousExport.SizeLimit.Should().Be(1000000);
continuousExport.Distributed.Should().BeTrue();
}

[Fact]
public void ContinuousExport_Should_Generate_Creation_Script()
{
// Arrange
var continuousExport = new ContinuousExport
{
ExternalTable = "ExternalEvents",
Query = "Events | where timestamp > ago(1h)",
ManagedIdentity = "system",
IntervalBetweenRuns = 30,
ForcedLatencyInMinutes = 5
};

// Act
var scripts = continuousExport.CreateScripts("HourlyEvents", true);

// Assert
scripts.Should().NotBeEmpty();
var script = scripts.First();
script.Kind.Should().Be("ContinuousExport");
script.Text.Should().Contain(".create-or-alter continuous-export HourlyEvents");
script.Text.Should().Contain("to table ExternalEvents");
script.Text.Should().Contain("Events | where timestamp > ago(1h)");
script.Text.Should().Contain("intervalBetweenRuns=5m");
script.Text.Should().Contain("managedIdentity='system'");
}
}
}
58 changes: 58 additions & 0 deletions KustoSchemaTools.Tests/Model/DatabaseModelTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using FluentAssertions;
using KustoSchemaTools.Model;
using KustoSchemaTools.Changes;

namespace KustoSchemaTools.Tests.Model
{
public class DatabaseModelTests
{
[Fact]
public void Database_Should_Initialize_With_Default_Values()
{
// Act
var database = new Database();

// Assert
database.Name.Should().BeNull();
database.Team.Should().Be("");
database.Monitors.Should().NotBeNull().And.BeEmpty();
database.Viewers.Should().NotBeNull().And.BeEmpty();
database.UnrestrictedViewers.Should().NotBeNull().And.BeEmpty();
database.Users.Should().NotBeNull().And.BeEmpty();
database.Ingestors.Should().NotBeNull().And.BeEmpty();
database.Admins.Should().NotBeNull().And.BeEmpty();
database.Tables.Should().NotBeNull().And.BeEmpty();
database.MaterializedViews.Should().NotBeNull().And.BeEmpty();
database.Functions.Should().NotBeNull().And.BeEmpty();
database.ContinuousExports.Should().NotBeNull().And.BeEmpty();
database.Scripts.Should().NotBeNull().And.BeEmpty();
database.EntityGroups.Should().NotBeNull().And.BeEmpty();
database.ExternalTables.Should().NotBeNull().And.BeEmpty();
database.Metadata.Should().NotBeNull().And.BeEmpty();
database.Deletions.Should().NotBeNull();
database.Followers.Should().NotBeNull().And.BeEmpty();
}

[Fact]
public void Database_Should_Allow_Property_Assignment()
{
// Arrange
var database = new Database();
var admin = new AADObject { Name = "[email protected]", Id = "admin-id" };
var table = new Table();

// Act
database.Name = "TestDatabase";
database.Team = "TestTeam";
database.Admins.Add(admin);
database.Tables.Add("TestTable", table);

// Assert
database.Name.Should().Be("TestDatabase");
database.Team.Should().Be("TestTeam");
database.Admins.Should().ContainSingle().Which.Should().Be(admin);
database.Tables.Should().ContainKey("TestTable");
database.Tables["TestTable"].Should().Be(table);
}
}
}
Empty file.
74 changes: 74 additions & 0 deletions KustoSchemaTools.Tests/Model/FunctionModelTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using FluentAssertions;
using KustoSchemaTools.Model;

namespace KustoSchemaTools.Tests.Model
{
public class FunctionModelTests
{
[Fact]
public void Function_Should_Initialize_With_Default_Values()
{
// Act
var function = new Function();

// Assert
function.Body.Should().BeNull();
function.Folder.Should().Be("");
function.DocString.Should().Be("");
function.Parameters.Should().Be("");
function.SkipValidation.Should().BeFalse();
function.View.Should().BeFalse();
function.Preformatted.Should().BeFalse();
}

[Fact]
public void Function_Should_Allow_Property_Assignment()
{
// Arrange
var function = new Function();

// Act
function.Body = "T | count";
function.Folder = "Analytics";
function.DocString = "Counts rows in table T";
function.Parameters = "(T: (*)";
function.SkipValidation = true;
function.View = true;

// Assert
function.Body.Should().Be("T | count");
function.Folder.Should().Be("Analytics");
function.DocString.Should().Be("Counts rows in table T");
function.Parameters.Should().Be("(T: (*)");
function.SkipValidation.Should().BeTrue();
function.View.Should().BeTrue();
}

[Fact]
public void Function_Should_Generate_Creation_Script()
{
// Arrange
var function = new Function
{
Body = "StormEvents | count\n",
Folder = "Weather",
DocString = "Count storm events",
Parameters = "tableName: string" // Provide valid parameters
};

// Act
var scripts = function.CreateScripts("CountStormEvents", true);

// Assert
scripts.Should().NotBeEmpty();
scripts.Should().HaveCount(1);
var script = scripts.First();
script.Kind.Should().Be("CreateOrAlterFunction");
script.Script.Text.Should().Contain(".create-or-alter function");
script.Script.Text.Should().Contain("CountStormEvents");
script.Script.Text.Should().Contain("StormEvents | count");
script.Script.Text.Should().Contain("Folder=```Weather```");
script.Script.Text.Should().Contain("DocString=```Count storm events```");
}
}
}
Loading
Loading