Skip to content
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

Unit test coverage #23

Merged
merged 6 commits into from
Nov 11, 2023
Merged
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
6 changes: 3 additions & 3 deletions PBIXInspectorCLI/PBIXInspectorCLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
<StartupObject>Program</StartupObject>
<SignAssembly>False</SignAssembly>
<IsPublishable>True</IsPublishable>
<FileVersion>1.9.3.0</FileVersion>
<AssemblyVersion>1.9.3</AssemblyVersion>
<VersionPrefix>1.9.3</VersionPrefix>
<FileVersion>1.9.4.0</FileVersion>
<AssemblyVersion>1.9.4</AssemblyVersion>
<VersionPrefix>1.9.4</VersionPrefix>
<Version>$(VersionPrefix)</Version>
<Product>$(AssembblyName)</Product>
<ApplicationIcon>pbiinspector.ico</ApplicationIcon>
Expand Down
8 changes: 3 additions & 5 deletions PBIXInspectorCLI/Program.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
using PBIXInspectorLibrary;
using PBIXInspectorLibrary.Output;
using PBIXInspectorWinLibrary;
using PBIXInspectorWinLibrary.Drawing;
using PBIXInspectorWinLibrary.Utils;

internal partial class Program
{
private static Args _parsedArgs = null;

private static void Main(string[] args)
{
{
#if DEBUG
Console.WriteLine("Attach debugger to process? Press any key to continue.");
Console.ReadLine();
Expand All @@ -20,7 +18,7 @@ private static void Main(string[] args)
_parsedArgs = ArgsUtils.ParseArgs(args);

Welcome();

PBIXInspectorWinLibrary.Main.WinMessageIssued += Main_MessageIssued;
PBIXInspectorWinLibrary.Main.Run(_parsedArgs);

Expand Down Expand Up @@ -76,7 +74,7 @@ private static String FormatConsoleMessage(MessageTypeEnum messageType, string m
string template = _parsedArgs.ADOOutput ? Constants.ADOLogIssueTemplate : "{0}";
string msgType = _parsedArgs.ADOOutput ? messageType.ToString().ToLower() : messageType.ToString();
string msgSeparator = _parsedArgs.ADOOutput ? "" : ": ";
string messageTypeFormat = string.Format(template,msgType);
string messageTypeFormat = string.Format(template, msgType);

return string.Concat(messageTypeFormat, msgSeparator, message);
}
Expand Down
2 changes: 1 addition & 1 deletion PBIXInspectorLibrary/CustomRules/CountRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class CountRule : Json.Logic.Rule

public CountRule(Json.Logic.Rule input)
{
Input = input;
Input = input;
}

/// <summary>
Expand Down
5 changes: 2 additions & 3 deletions PBIXInspectorLibrary/CustomRules/DrillVariableRule.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using Json.Logic;
using Json.Pointer;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using Json.Pointer;
using System.Net.Http.Headers;

namespace PBIXInspectorLibrary.CustomRules;

Expand Down Expand Up @@ -67,7 +66,7 @@ internal DrillVariableRule(Json.Logic.Rule path, Json.Logic.Rule defaultValue)
{
//remove single quotes from beginning and end of string if any.
string strVal;
if (val.ToString()!.StartsWith("'") && val.ToString()!.EndsWith("'"))
if (val.ToString()!.StartsWith("'") && val.ToString()!.EndsWith("'"))
{
strVal = val.ToString()!.Substring(1, val.ToString()!.Length - 2);
}
Expand Down
2 changes: 1 addition & 1 deletion PBIXInspectorLibrary/CustomRules/RectangleOverlap.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Json.Logic;
using System.Drawing;
using System.Text.Json.Nodes;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;

namespace PBIXInspectorLibrary.CustomRules
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PBIXInspectorLibrary.Exceptions
namespace PBIXInspectorLibrary.Exceptions
{
internal class PbiFileEntryNotFoundException : Exception
{
Expand Down
40 changes: 19 additions & 21 deletions PBIXInspectorLibrary/Inspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using PBIXInspectorLibrary.Output;
using System.Linq.Expressions;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;

namespace PBIXInspectorLibrary
Expand Down Expand Up @@ -39,7 +37,7 @@ public Inspector(string pbiFilePath, InspectionRules inspectionRules) : base(pbi
this._inspectionRules = inspectionRules;
AddCustomRulesToRegistry();
}

/// <summary>
///
/// </summary>
Expand All @@ -49,7 +47,7 @@ public Inspector(string pbiFilePath, string rulesFilePath) : base(pbiFilePath, r
{
this._pbiFilePath = pbiFilePath;
this._rulesFilePath = rulesFilePath;

try
{
var inspectionRules = this.DeserialiseRules<InspectionRules>(rulesFilePath);
Expand Down Expand Up @@ -83,19 +81,19 @@ private PbiFile InitPbiFile(string pbiFilePath)
//}
//else
//{
switch (PbiFile.PBIFileType(pbiFilePath))
{
case PbiFile.PBIFileTypeEnum.PBIX:
return new PbixFile(pbiFilePath);
break;
case PbiFile.PBIFileTypeEnum.PBIP:
return new PbipFile(pbiFilePath);
break;
case PbiFile.PBIFileTypeEnum.PBIPReport:
return new PbipReportFile(pbiFilePath);
default:
throw new PBIXInspectorException(string.Format("Could not determine the extension of PBI file with path \"{0}\".", pbiFilePath));
}
switch (PbiFile.PBIFileType(pbiFilePath))
{
case PbiFile.PBIFileTypeEnum.PBIX:
return new PbixFile(pbiFilePath);
break;
case PbiFile.PBIFileTypeEnum.PBIP:
return new PbipFile(pbiFilePath);
break;
case PbiFile.PBIFileTypeEnum.PBIPReport:
return new PbipReportFile(pbiFilePath);
default:
throw new PBIXInspectorException(string.Format("Could not determine the extension of PBI file with path \"{0}\".", pbiFilePath));
}
//}
}

Expand Down Expand Up @@ -135,7 +133,7 @@ public IEnumerable<TestResult> Inspect()
{
string pbiEntryPath;

switch (pbiFile.FileType)
switch (pbiFile.FileType)
{
case PbiFile.PBIFileTypeEnum.PBIX:
pbiEntryPath = entry.PbixEntryPath;
Expand Down Expand Up @@ -211,7 +209,7 @@ public IEnumerable<TestResult> Inspect()

var forEachDisplayName = !string.IsNullOrEmpty(rule.ForEachPathDisplayName) ? ExecuteTokensPath((JObject?)forEachToken, rule.Name, rule.ForEachPathDisplayName, rule.PathErrorWhenNoMatch) : null;
var strForEachDisplayName = forEachDisplayName != null ? forEachDisplayName[0].ToString() : string.Empty;

try
{
var tokens = ExecuteTokensPath(forEachToken, rule.Name, rule.Path, rule.PathErrorWhenNoMatch);
Expand Down Expand Up @@ -289,7 +287,7 @@ public IEnumerable<TestResult> Inspect()
}
}

return testResults;
return testResults;
}

private MessageTypeEnum ConvertRuleLogType(string ruleLogType)
Expand Down Expand Up @@ -516,7 +514,7 @@ private JsonArray ConvertToJsonArray(List<JToken>? tokens)
{
if (item.Value is JsonValue)
{

var value = item.Value.AsValue().Stringify();
//TODO: enable navigation to parent path
//while (value.StartsWith("."))
Expand Down
2 changes: 1 addition & 1 deletion PBIXInspectorLibrary/MessageIssuedEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public MessageIssuedEventArgs(string message, MessageTypeEnum messageType)

public string Message { get; private set; }
public MessageTypeEnum MessageType { get; private set; }
public bool DialogOKResponse { get; set;}
public bool DialogOKResponse { get; set; }
}

public enum MessageTypeEnum
Expand Down
9 changes: 1 addition & 8 deletions PBIXInspectorLibrary/PbiFile.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO.Compression;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PBIXInspectorLibrary
namespace PBIXInspectorLibrary
{
internal abstract class PbiFile : IDisposable
{
Expand Down
9 changes: 4 additions & 5 deletions PBIXInspectorLibrary/PbixFile.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using System.Data;
using System.IO.Compression;
using System.IO.Compression;

namespace PBIXInspectorLibrary
{
internal class PbixFile : PbiFile, IDisposable
{

private ZipArchive _za = null;

Check warning on line 8 in PBIXInspectorLibrary/PbixFile.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Cannot convert null literal to non-nullable reference type.
private bool disposedValue;

public PbixFile(string pbiFilePath) : base(pbiFilePath)
Expand Down Expand Up @@ -46,7 +45,7 @@
}
}

return null;

Check warning on line 48 in PBIXInspectorLibrary/PbixFile.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Possible null reference return.
}

protected virtual void Dispose(bool disposing)
Expand All @@ -59,11 +58,11 @@
if (this._za != null)
{
this._za.Dispose();
this._za = null;

Check warning on line 61 in PBIXInspectorLibrary/PbixFile.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Cannot convert null literal to non-nullable reference type.
}
}


// TODO: set large fields to null
disposedValue = true;
}
Expand All @@ -76,6 +75,6 @@
GC.SuppressFinalize(this);
}


}
}
15 changes: 15 additions & 0 deletions PBIXInspectorTests/AppUtilsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using PBIXInspectorWinLibrary.Utils;

namespace PBIXInspectorTests
{
[TestFixture]
public class AppUtilsTests
{
[Test]
public void AboutTest()
{
var about = AppUtils.About();
Assert.That(string.IsNullOrEmpty(about), Is.False);
}
}
}
69 changes: 63 additions & 6 deletions PBIXInspectorTests/CLIArgsUtilsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ public void TestCLIArgsUtilsDefaults()

parsedArgs = ArgsUtils.ParseArgs(args);

Assert.IsTrue(parsedArgs.CONSOLEOutput
&& !parsedArgs.Verbose
&& parsedArgs.DeleteOutputDirOnExit
Assert.IsTrue(parsedArgs.CONSOLEOutput
&& !parsedArgs.Verbose
&& parsedArgs.DeleteOutputDirOnExit
&& !string.IsNullOrEmpty(parsedArgs.OutputDirPath)
&& !parsedArgs.HTMLOutput
&& !parsedArgs.JSONOutput
&& !parsedArgs.HTMLOutput
&& !parsedArgs.JSONOutput
&& !parsedArgs.PNGOutput);
}

Expand Down Expand Up @@ -207,6 +207,63 @@ public void TestCLIArgsUtilsResolvePbiFilePathInput2()
Assert.IsTrue(resolvedPath == expectedPath);
}

[Test]
public void TestCLIArgsUtilsResolvePbiFilePathInput3()
{
string inputPath = @"C:\TEMP\VisOps\Sales - custom colours.Report\report.pbix";
string expectedPath = @"C:\TEMP\VisOps\Sales - custom colours.Report\report.pbix";
string resolvedPath = ArgsUtils.ResolvePbiFilePathInput(inputPath);

Assert.IsTrue(resolvedPath == expectedPath);
}

[Test]
public void TestCLIArgsUtilsSuccess_FormatsOption()
{
string[] args = "-pbipreport pbipPath -rules rulesPath -formats CONSOLE,HTML,PNG,JSON -verbose true".Split(" ");
var parsedArgs = ArgsUtils.ParseArgs(args);

Assert.True(parsedArgs.PBIFilePath.Equals("pbipPath", StringComparison.OrdinalIgnoreCase) && parsedArgs.RulesFilePath.Equals("rulesPath", StringComparison.OrdinalIgnoreCase) && parsedArgs.CONSOLEOutput && parsedArgs.HTMLOutput && parsedArgs.PNGOutput && parsedArgs.JSONOutput && parsedArgs.Verbose);
}

[Test]
public void TestCLIArgsUtilsSuccess_FormatsOptionMissing()
{
string[] args = "-pbipreport pbipPath -rules rulesPath -verbose true".Split(" ");
var parsedArgs = ArgsUtils.ParseArgs(args);

Assert.True(parsedArgs.PBIFilePath.Equals("pbipPath", StringComparison.OrdinalIgnoreCase) && parsedArgs.RulesFilePath.Equals("rulesPath", StringComparison.OrdinalIgnoreCase) && parsedArgs.CONSOLEOutput && !parsedArgs.HTMLOutput && !parsedArgs.PNGOutput && !parsedArgs.JSONOutput && parsedArgs.Verbose);
}

[Test]
public void TestCLIArgsUtilsSuccess_FormatsOptionUnparseable()
{
string[] args = "-pbipreport pbipPath -rules rulesPath -formats XYZ -verbose true".Split(" ");
var parsedArgs = ArgsUtils.ParseArgs(args);

Assert.True(parsedArgs.PBIFilePath.Equals("pbipPath", StringComparison.OrdinalIgnoreCase) && parsedArgs.RulesFilePath.Equals("rulesPath", StringComparison.OrdinalIgnoreCase) && parsedArgs.CONSOLEOutput && !parsedArgs.HTMLOutput && !parsedArgs.PNGOutput && !parsedArgs.JSONOutput && parsedArgs.Verbose);
}

[Test]
public void TestCLIArgsUtilsSuccess_VerboseOption()
{
string[] args = "-pbipreport pbipPath -rules rulesPath -verbose true".Split(" ");
var parsedArgs = ArgsUtils.ParseArgs(args);

Assert.True(parsedArgs.PBIFilePath.Equals("pbipPath", StringComparison.OrdinalIgnoreCase) && parsedArgs.RulesFilePath.Equals("rulesPath", StringComparison.OrdinalIgnoreCase) && parsedArgs.Verbose);
}

[Test]
public void TestCLIArgsUtilsSuccess_VerboseOptionFalse2()
{
string[] args = "-pbipreport pbipPath -rules rulesPath -verbose false".Split(" ");
var parsedArgs = ArgsUtils.ParseArgs(args);

Assert.True(parsedArgs.PBIFilePath.Equals("pbipPath", StringComparison.OrdinalIgnoreCase) && parsedArgs.RulesFilePath.Equals("rulesPath", StringComparison.OrdinalIgnoreCase) && !parsedArgs.Verbose);
}


}
}
#pragma warning restore CS8602

#pragma warning restore CS8602
4 changes: 2 additions & 2 deletions PBIXInspectorTests/CustomRulesTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Text.Json.Nodes;
using PBIXInspectorLibrary.CustomRules;
using PBIXInspectorLibrary.CustomRules;
using System.Text.Json.Nodes;

namespace PBIXInspectorTests
{
Expand Down
Binary file modified PBIXInspectorTests/Files/Inventory sample - fails.pbix
Binary file not shown.
Binary file not shown.
27 changes: 27 additions & 0 deletions PBIXInspectorTests/ImageUtilsTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using PBIXInspectorLibrary.Output;
using PBIXInspectorWinLibrary.Drawing;

namespace PBIXInspectorTests
{
[TestFixture]
internal class ImageUtilsTest
{
[Test]
public void ConvertBitmapToBase64Test()
{
var bitmapPath = string.Empty;

ArgumentException ex = Assert.Throws<ArgumentException>(
() => ImageUtils.ConvertBitmapToBase64(bitmapPath));
}
[Test]
public void DrawReportPagesTest()
{
var fieldMapResults = new List<TestResult>();
var testResults = new List<TestResult>();
var outputDir = "";
ImageUtils.DrawReportPages(fieldMapResults, testResults, outputDir);
Assert.IsTrue(string.IsNullOrEmpty(outputDir));
}
}
}
2 changes: 1 addition & 1 deletion PBIXInspectorTests/JsonAssert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.

using System.Text.Json.Nodes;
using Json.More;
using System.Text.Json.Nodes;

namespace PBIXInspectorTests
{
Expand Down
Loading
Loading