Skip to content

Commit

Permalink
test: Test PreviewProcessArguments
Browse files Browse the repository at this point in the history
Make GetArgumentIndex and IsArgMatch methods internal and add unit tests for argument processing
  • Loading branch information
github-actions[bot] committed Dec 2, 2024
1 parent 88acfa0 commit 775b289
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 4 deletions.
4 changes: 2 additions & 2 deletions AzureLiquid.Preview/PreviewProcessArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class PreviewProcessArguments
/// <param name="args">The arguments.</param>
/// <param name="key">The key.</param>
/// <returns>The index of the argument.</returns>
private static int GetArgumentIndex(string[] args, string key)
internal static int GetArgumentIndex(string[] args, string key)
{
for (int i = 0; i < args.Length; i++)
{
Expand All @@ -42,7 +42,7 @@ private static int GetArgumentIndex(string[] args, string key)
/// <returns>
/// <c>true</c> if argument found; otherwise, <c>false</c>.
/// </returns>
private static bool IsArgMatch(string arg, string key)
internal static bool IsArgMatch(string arg, string key)
{
return string.CompareOrdinal(arg, "--" + key) == 0;
}
Expand Down
5 changes: 3 additions & 2 deletions AzureLiquid.Preview/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
// Licensed under the open source Apache License, Version 2.0.
// </copyright>

// deepcode ignore XXE: All input is returned to original source and is not used internally

using System.Runtime.CompilerServices;
using AzureLiquid.Preview;

[assembly: InternalsVisibleTo("AzureLiquid.Tests")]

PreviewProcess.Create(args);
70 changes: 70 additions & 0 deletions AzureLiquid.Tests/PreviewProcessArgumentsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System.IO;

Check warning on line 1 in AzureLiquid.Tests/PreviewProcessArgumentsTests.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant using directive

Using directive is not required by the code and can be safely removed
using Xunit;

Check warning on line 2 in AzureLiquid.Tests/PreviewProcessArgumentsTests.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Using directives should be ordered alphabetically by the namespaces. (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1210.md)

Check warning on line 2 in AzureLiquid.Tests/PreviewProcessArgumentsTests.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Using directives should be ordered alphabetically by the namespaces. (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1210.md)

Check warning on line 2 in AzureLiquid.Tests/PreviewProcessArgumentsTests.cs

View workflow job for this annotation

GitHub Actions / Unit Tests / Build and Test

Using directives should be ordered alphabetically by the namespaces. (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1210.md)

Check warning on line 2 in AzureLiquid.Tests/PreviewProcessArgumentsTests.cs

View workflow job for this annotation

GitHub Actions / Unit Tests / Build and Test

Using directives should be ordered alphabetically by the namespaces. (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1210.md)

Check warning on line 2 in AzureLiquid.Tests/PreviewProcessArgumentsTests.cs

View workflow job for this annotation

GitHub Actions / Unit Tests / Build and Test

Using directives should be ordered alphabetically by the namespaces. (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1210.md)

Check warning on line 2 in AzureLiquid.Tests/PreviewProcessArgumentsTests.cs

View workflow job for this annotation

GitHub Actions / Unit Tests / Build and Test

Using directives should be ordered alphabetically by the namespaces. (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1210.md)

Check warning on line 2 in AzureLiquid.Tests/PreviewProcessArgumentsTests.cs

View workflow job for this annotation

GitHub Actions / Unit Tests / Build and Test

Using directives should be ordered alphabetically by the namespaces. (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1210.md)

Check warning on line 2 in AzureLiquid.Tests/PreviewProcessArgumentsTests.cs

View workflow job for this annotation

GitHub Actions / Unit Tests / Build and Test

Using directives should be ordered alphabetically by the namespaces. (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1210.md)
using FluentAssertions;

namespace AzureLiquid.Preview.Tests

Check warning on line 5 in AzureLiquid.Tests/PreviewProcessArgumentsTests.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Namespace does not correspond to file location

Namespace does not correspond to file location, must be: 'AzureLiquid.Tests'
{

Check notice on line 6 in AzureLiquid.Tests/PreviewProcessArgumentsTests.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Use preferred namespace body style

Convert to file-scoped namespace
public class PreviewProcessArgumentsTests
{
[Theory]
[InlineData(new string[] { "--template", "template.liquid" }, "template", 0)]

Check warning on line 10 in AzureLiquid.Tests/PreviewProcessArgumentsTests.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant explicit type in array creation

Redundant explicit array type specification
[InlineData(new string[] { "--content", "content.json" }, "content", 0)]

Check warning on line 11 in AzureLiquid.Tests/PreviewProcessArgumentsTests.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant explicit type in array creation

Redundant explicit array type specification
[InlineData(new string[] { "--output", "output.txt" }, "output", 0)]

Check warning on line 12 in AzureLiquid.Tests/PreviewProcessArgumentsTests.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant explicit type in array creation

Redundant explicit array type specification
[InlineData(new string[] { "--watch" }, "watch", 0)]

Check warning on line 13 in AzureLiquid.Tests/PreviewProcessArgumentsTests.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant explicit type in array creation

Redundant explicit array type specification
[InlineData(new string[] { "--template", "template.liquid" }, "content", -1)]

Check warning on line 14 in AzureLiquid.Tests/PreviewProcessArgumentsTests.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant explicit type in array creation

Redundant explicit array type specification
public void GetArgumentIndex_ShouldReturnCorrectIndex(string[] args, string key, int expectedIndex)
{
// Act
var index = PreviewProcessArguments.GetArgumentIndex(args, key);

// Assert
index.Should().Be(expectedIndex);
}

[Theory]
[InlineData("--template", "template", true)]
[InlineData("--content", "content", true)]
[InlineData("--output", "output", true)]
[InlineData("--watch", "watch", true)]
[InlineData("--template", "content", false)]
public void IsArgMatch_ShouldReturnCorrectResult(string arg, string key, bool expectedResult)
{
// Act
var result = PreviewProcessArguments.IsArgMatch(arg, key);

// Assert
result.Should().Be(expectedResult);
}

[Theory]
[InlineData(new string[] { "--template", "template.liquid" }, "template", true)]

Check warning on line 40 in AzureLiquid.Tests/PreviewProcessArgumentsTests.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant explicit type in array creation

Redundant explicit array type specification
[InlineData(new string[] { "--content", "content.json" }, "content", true)]

Check warning on line 41 in AzureLiquid.Tests/PreviewProcessArgumentsTests.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant explicit type in array creation

Redundant explicit array type specification
[InlineData(new string[] { "--output", "output.txt" }, "output", true)]

Check warning on line 42 in AzureLiquid.Tests/PreviewProcessArgumentsTests.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant explicit type in array creation

Redundant explicit array type specification
[InlineData(new string[] { "--watch" }, "watch", true)]

Check warning on line 43 in AzureLiquid.Tests/PreviewProcessArgumentsTests.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant explicit type in array creation

Redundant explicit array type specification
[InlineData(new string[] { "--template", "template.liquid" }, "content", false)]

Check warning on line 44 in AzureLiquid.Tests/PreviewProcessArgumentsTests.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant explicit type in array creation

Redundant explicit array type specification
public void HasArgument_ShouldReturnCorrectResult(string[] args, string key, bool expectedResult)
{
// Act
var result = PreviewProcessArguments.HasArgument(args, key);

// Assert
result.Should().Be(expectedResult);
}

[Theory]
[InlineData(new string[] { "--template", "template.liquid" }, "template", "template.liquid")]

Check warning on line 55 in AzureLiquid.Tests/PreviewProcessArgumentsTests.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant explicit type in array creation

Redundant explicit array type specification
[InlineData(new string[] { "--content", "content.json" }, "content", "content.json")]

Check warning on line 56 in AzureLiquid.Tests/PreviewProcessArgumentsTests.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant explicit type in array creation

Redundant explicit array type specification
[InlineData(new string[] { "--output", "output.txt" }, "output", "output.txt")]

Check warning on line 57 in AzureLiquid.Tests/PreviewProcessArgumentsTests.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant explicit type in array creation

Redundant explicit array type specification
public void ParsePath_ShouldReturnCorrectPath(string[] args, string key, string expectedPath)
{
// Arrange
var previewArgs = new PreviewProcessArguments();

// Act
var path = previewArgs.ParsePath(args, key);

// Assert
path.Should().Contain(expectedPath);
}
}
}

0 comments on commit 775b289

Please sign in to comment.