diff --git a/tests/PSRule.Tests/BaselineTests.cs b/tests/PSRule.Tests/BaselineTests.cs index 6c25569eeb..8d35c5f4d5 100644 --- a/tests/PSRule.Tests/BaselineTests.cs +++ b/tests/PSRule.Tests/BaselineTests.cs @@ -50,7 +50,8 @@ public void ReadBaselineYaml() // TestBaseline4 Assert.Equal("TestBaseline4", baseline[3].Name); Assert.Null(baseline[3].Info.Synopsis.Text); - Assert.Equal(SeverityLevel.Warning, baseline[3].Spec.Override.Level["rule1"]); + Assert.NotNull(baseline[3].Spec); + Assert.Equal(SeverityLevel.Warning, baseline[3].Spec.Override?.Level?["rule1"]); // TestBaseline5 Assert.Equal("TestBaseline5", baseline[4].Name); @@ -92,7 +93,9 @@ public void ReadBaselineJson() // TestBaseline4 Assert.Equal("TestBaseline4", baseline[3].Name); Assert.Null(baseline[3].Info.Synopsis.Text); - Assert.Equal(SeverityLevel.Warning, baseline[3].Spec.Override.Level["rule1"]); + Assert.NotNull(baseline[3].Spec.Override.Level); + Assert.True(baseline[3].Spec.Override.Level!.TryGetValue("rule1", out var level)); + Assert.Equal(SeverityLevel.Warning, level); // TestBaseline5 Assert.Equal("TestBaseline5", baseline[4].Name); @@ -136,6 +139,7 @@ public void FilterBaseline(string path) var filter = new BaselineFilter(["TestBaseline5"]); var actual = baseline.FirstOrDefault(b => filter.Match(b)); + Assert.NotNull(actual); Assert.Equal("TestBaseline5", actual.Name); } @@ -170,7 +174,9 @@ public void BaselineAsJson() { var expected = new object[] { GetBaselines(GetSource(BaselineJsonFileName)) }; var json = JsonOutputWriter.ToJson(expected, null); - var actual = (JArray)JsonConvert.DeserializeObject(json); + + Assert.NotNull(json); + var actual = (JArray)JsonConvert.DeserializeObject(json)!; // TestBaseline1 Assert.Equal("github.com/microsoft/PSRule/v1", actual?[0]["apiVersion"]); diff --git a/tests/PSRule.Tests/ConventionTests.cs b/tests/PSRule.Tests/ConventionTests.cs index acd296bdce..568c355583 100644 --- a/tests/PSRule.Tests/ConventionTests.cs +++ b/tests/PSRule.Tests/ConventionTests.cs @@ -4,7 +4,6 @@ using System.Management.Automation; using PSRule.Configuration; using PSRule.Pipeline; -using static PSRule.PipelineTests; namespace PSRule; diff --git a/tests/PSRule.Tests/PipelineTests.cs b/tests/PSRule.Tests/Pipeline/PipelineTests.cs similarity index 94% rename from tests/PSRule.Tests/PipelineTests.cs rename to tests/PSRule.Tests/Pipeline/PipelineTests.cs index 2e557208b4..a9be1aed20 100644 --- a/tests/PSRule.Tests/PipelineTests.cs +++ b/tests/PSRule.Tests/Pipeline/PipelineTests.cs @@ -10,27 +10,13 @@ using PSRule.Configuration; using PSRule.Definitions.Rules; using PSRule.Options; -using PSRule.Pipeline; using PSRule.Resources; using PSRule.Rules; -namespace PSRule; +namespace PSRule.Pipeline; -public sealed class PipelineTests : ContextBaseTests +public sealed partial class PipelineTests : ContextBaseTests { - internal class TestObject - { - public string Name { get; set; } - } - - [Fact] - public void BuildInvokePipeline() - { - var option = GetOption(); - var builder = PipelineBuilder.Invoke(GetSource(), option, null); - Assert.NotNull(builder.Build()); - } - [Fact] public void InvokePipeline() { @@ -49,7 +35,7 @@ public void InvokePipeline() } [Fact] - public void InvokePipelineWithJObject() + public void InvokePipeline_WithJObject_ShouldRunSuccessfully() { var parent = new JObject { @@ -94,7 +80,7 @@ public void InvokePipelineWithJObject() } [Fact] - public void InvokePipelineWithPathPrefix() + public void InvokePipeline_WithPathPrefix_ShouldRunSuccessfully() { var parent = new JObject { @@ -132,7 +118,7 @@ public void InvokePipelineWithPathPrefix() } [Fact] - public void InvokePipelineWithExclude() + public void InvokePipeline_WithExclude() { var option = GetOption(ruleExcludedAction: ExecutionActionPreference.Warn); option.Rule.Include = ["FromFile1"]; @@ -148,13 +134,6 @@ public void InvokePipelineWithExclude() Assert.Contains(writer.Warnings, (string s) => { return s == string.Format(Thread.CurrentThread.CurrentCulture, PSRuleResources.RuleExcluded, ".\\FromFile2"); }); } - [Fact] - public void BuildGetPipeline() - { - var builder = PipelineBuilder.Get(GetSource(), GetOption(), null); - Assert.NotNull(builder.Build()); - } - [Fact] public void GetRuleWithBaseline() { diff --git a/tests/PSRule.Tests/TestObject.cs b/tests/PSRule.Tests/TestObject.cs new file mode 100644 index 0000000000..03379da3b5 --- /dev/null +++ b/tests/PSRule.Tests/TestObject.cs @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +namespace PSRule.Pipeline; + +internal sealed class TestObject +{ + public string Name { get; set; } +}