-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nat Van Gulck
authored and
Nat Van Gulck
committed
Oct 16, 2023
1 parent
1e3e6db
commit f77660d
Showing
10 changed files
with
190 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using System.Text.Json.Nodes; | ||
using PBIXInspectorLibrary.CustomRules; | ||
|
||
namespace PBIXInspectorTests | ||
{ | ||
[TestFixture] | ||
public class CustomRulesTests | ||
{ | ||
#pragma warning disable CS8602 | ||
[Test] | ||
public void IsNullOrEmptyRuleTest() | ||
{ | ||
var json = ""; | ||
var rule = new IsNullOrEmptyRule(json); | ||
var result = rule.Apply(null); | ||
Assert.That((bool)result.AsValue(), Is.True); | ||
} | ||
|
||
[Test] | ||
public void IsNullOrEmptyRuleTest2() | ||
{ | ||
string json = null; | ||
var rule = new IsNullOrEmptyRule(json); | ||
var result = rule.Apply(null); | ||
Assert.That((bool)result.AsValue(), Is.True); | ||
} | ||
|
||
[Test] | ||
public void IsNullOrEmptyRuleTest3() | ||
{ | ||
string json = "Hello"; | ||
var rule = new IsNullOrEmptyRule(json); | ||
var result = rule.Apply(null); | ||
Assert.That((bool)result.AsValue(), Is.False); | ||
} | ||
|
||
[Test] | ||
public void ToStringTest() | ||
{ | ||
var json = "{\"message\":\"Hello, world!\"}"; | ||
|
||
var rule = new ToString(JsonNode.Parse(json)); | ||
var result = rule.Apply(null); | ||
Assert.That(result?.ToString(), Is.EqualTo(json)); | ||
} | ||
|
||
[Test] | ||
public void CountRuleTest() | ||
{ | ||
var json = "[\"a\",\"b\",\"c\"]"; | ||
|
||
var rule = new CountRule(JsonNode.Parse(json)); | ||
var result = rule.Apply(null); | ||
JsonAssert.AreEquivalent(result, 3); | ||
} | ||
|
||
[Test] | ||
public void StringContainsMatchTest() | ||
{ | ||
var searchString = "Hello, world! More text"; | ||
var patternString = "^[a-zA-Z]+, world!"; | ||
|
||
var rule = new StringContains(searchString, patternString); | ||
var result = rule.Apply(null); | ||
Assert.That((int)result.AsValue(), Is.GreaterThan(0)); | ||
} | ||
|
||
[Test] | ||
public void StringContainsNoMatchTest() | ||
{ | ||
var searchString = "Hello, world! More text"; | ||
var patternString = "^[a-zA-Z]+, world!$"; | ||
|
||
var rule = new StringContains(searchString, patternString); | ||
var result = rule.Apply(null); | ||
Assert.That((int)result.AsValue(), Is.EqualTo(0)); | ||
} | ||
#pragma warning restore CS8602 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//MIT License | ||
|
||
//Copyright (c) 2022 Greg Dennis | ||
|
||
//Permission is hereby granted, free of charge, to any person obtaining a copy | ||
//of this software and associated documentation files (the "Software"), to deal | ||
//in the Software without restriction, including without limitation the rights | ||
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
//copies of the Software, and to permit persons to whom the Software is | ||
//furnished to do so, subject to the following conditions: | ||
|
||
//The above copyright notice and this permission notice shall be included in all | ||
//copies or substantial portions of the Software. | ||
|
||
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
//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; | ||
|
||
namespace PBIXInspectorTests | ||
{ | ||
public static class JsonAssert | ||
{ | ||
public static void AreEquivalent(JsonNode? expected, JsonNode? actual) | ||
{ | ||
if (!expected.IsEquivalentTo(actual)) | ||
Assert.Fail($"Expected: {expected.AsJsonString()}\nActual: {actual.AsJsonString()}"); | ||
} | ||
|
||
public static void IsNull(JsonNode? actual) | ||
{ | ||
if (actual != null) | ||
Assert.Fail($"Expected: null\nActual: {actual.AsJsonString()}"); | ||
} | ||
|
||
public static void IsTrue(JsonNode? actual) | ||
{ | ||
if (actual is not JsonValue value || !value.TryGetValue(out bool b) || !b) | ||
Assert.Fail($"Expected: true\nActual: {actual.AsJsonString()}"); | ||
} | ||
|
||
public static void IsFalse(JsonNode? actual) | ||
{ | ||
if (actual is not JsonValue value || !value.TryGetValue(out bool b) || b) | ||
Assert.Fail($"Expected: true\nActual: {actual.AsJsonString()}"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters