diff --git a/AzureLiquid.Preview/PreviewProcess.cs b/AzureLiquid.Preview/PreviewProcess.cs
index 6bfc0b3..f20e47a 100644
--- a/AzureLiquid.Preview/PreviewProcess.cs
+++ b/AzureLiquid.Preview/PreviewProcess.cs
@@ -162,7 +162,7 @@ private static void LogMissingFiles(PreviewProcess preview)
/// The instance of to handle the output.
private static void HandleNoArgumentsPassed(string[] args, PreviewProcess preview)
{
- if (args.Length == 0)
+ if (args == null || args.Length == 0)
{
preview.WriteHelpOutput();
}
diff --git a/AzureLiquid.Preview/PreviewProcessArguments.cs b/AzureLiquid.Preview/PreviewProcessArguments.cs
index 955202b..812a0d3 100644
--- a/AzureLiquid.Preview/PreviewProcessArguments.cs
+++ b/AzureLiquid.Preview/PreviewProcessArguments.cs
@@ -53,7 +53,7 @@ internal static bool IsArgMatch(string arg, string key)
/// The passed arguments.
/// The key.
/// true if the argument was found, otherwise false.
- public static bool HasArgument(string[] args, string key) => args.Any(arg => IsArgMatch(arg, key));
+ public static bool HasArgument(string[] args, string key) => args?.Length > 0 && args.Any(arg => IsArgMatch(arg, key));
///
/// Parses the argument value.
@@ -63,6 +63,11 @@ internal static bool IsArgMatch(string arg, string key)
/// The argument value.
public string ParsePath(string[] args, string key)
{
+ if (args == null || args.Length == 0)
+ {
+ return string.Empty;
+ }
+
var index = GetArgumentIndex(args, key);
return
index == -1 || index - 1 >= args.Length
diff --git a/AzureLiquid.Tests/PreviewProcessTests.cs b/AzureLiquid.Tests/PreviewProcessTests.cs
index ad2ebc5..c898c9b 100644
--- a/AzureLiquid.Tests/PreviewProcessTests.cs
+++ b/AzureLiquid.Tests/PreviewProcessTests.cs
@@ -161,6 +161,23 @@ public void EnsureFileReadExceptionHandling()
instance.Log.Should().NotBeEmpty("A log should not have been created");
}
+ ///
+ /// Ensure the preview process can handle missing arguments.
+ ///
+ [Fact]
+ public void EnsureHelpMessageShown()
+ {
+ // Arrange
+ var instance = PreviewProcess.Create(null!);
+
+ // Act
+ var result = instance.Render();
+
+ // Assert
+ result.Should().BeEmpty("A result should not have been created");
+ instance.Log.Should().NotBeEmpty("A log should not have been created");
+ }
+
///
/// Contains arranged values used for testing, containing mock instances and expected return values.
///