From 07b3daf38019952bbf49830175d3d5bd0dd5246b Mon Sep 17 00:00:00 2001 From: John McPherson Date: Mon, 3 Feb 2025 13:44:40 -0800 Subject: [PATCH] Complete config PS module and unit tests --- .../Fixtures/UnitTestFixture.cs | 2 +- .../Helpers/ConfigurationProcessorTestBase.cs | 16 ++++++++-------- .../Helpers/DiagnosticsEventSink.cs | 4 ++-- ...oft.Management.Configuration.UnitTests.csproj | 12 ++---------- .../Tests/ConfigurationSetProcessorTests.cs | 4 ++-- .../Tests/ConfigurationUnitProcessorTests.cs | 12 ++++++------ .../Tests/OpenConfigurationSetTests.cs | 4 ++-- ...Microsoft.WinGet.Configuration.Cmdlets.csproj | 13 +++++++++---- .../Microsoft.WinGet.Configuration.Engine.csproj | 9 +++++++-- 9 files changed, 39 insertions(+), 37 deletions(-) diff --git a/src/Microsoft.Management.Configuration.UnitTests/Fixtures/UnitTestFixture.cs b/src/Microsoft.Management.Configuration.UnitTests/Fixtures/UnitTestFixture.cs index 8bb92a41c0..973afffebc 100644 --- a/src/Microsoft.Management.Configuration.UnitTests/Fixtures/UnitTestFixture.cs +++ b/src/Microsoft.Management.Configuration.UnitTests/Fixtures/UnitTestFixture.cs @@ -93,7 +93,7 @@ public UnitTestFixture(IMessageSink messageSink) /// /// Gets the configuration statics object to use. /// - public IConfigurationStatics2 ConfigurationStatics { get; private init; } + internal IConfigurationStatics2 ConfigurationStatics { get; private init; } /// /// Creates a runspace adding the test module path. diff --git a/src/Microsoft.Management.Configuration.UnitTests/Helpers/ConfigurationProcessorTestBase.cs b/src/Microsoft.Management.Configuration.UnitTests/Helpers/ConfigurationProcessorTestBase.cs index 800eac1303..c1dd3a9daa 100644 --- a/src/Microsoft.Management.Configuration.UnitTests/Helpers/ConfigurationProcessorTestBase.cs +++ b/src/Microsoft.Management.Configuration.UnitTests/Helpers/ConfigurationProcessorTestBase.cs @@ -49,7 +49,7 @@ protected ConfigurationProcessorTestBase(UnitTestFixture fixture, ITestOutputHel /// /// The factory to use. /// The new object. - protected ConfigurationProcessor CreateConfigurationProcessorWithDiagnostics(IConfigurationSetProcessorFactory? factory = null) + internal ConfigurationProcessor CreateConfigurationProcessorWithDiagnostics(IConfigurationSetProcessorFactory? factory = null) { ConfigurationProcessor result = this.Fixture.ConfigurationStatics.CreateConfigurationProcessor(factory); result.Diagnostics += this.EventSink.DiagnosticsHandler; @@ -62,7 +62,7 @@ protected ConfigurationProcessor CreateConfigurationProcessorWithDiagnostics(ICo /// /// The contents that the stream should contain. /// The created stream. - protected IInputStream CreateStream(string contents) + internal IInputStream CreateStream(string contents) { InMemoryRandomAccessStream result = new InMemoryRandomAccessStream(); @@ -83,7 +83,7 @@ protected IInputStream CreateStream(string contents) /// /// The output stream. /// The created string. - protected string ReadStream(InMemoryRandomAccessStream stream) + internal string ReadStream(InMemoryRandomAccessStream stream) { string result = string.Empty; using (DataReader reader = new DataReader(stream.GetInputStreamAt(0))) @@ -105,7 +105,7 @@ protected string ReadStream(InMemoryRandomAccessStream stream) /// Creates a configuration unit via the configuration statics object. /// /// A new configuration unit. - protected ConfigurationUnit ConfigurationUnit() + internal ConfigurationUnit ConfigurationUnit() { return this.Fixture.ConfigurationStatics.CreateConfigurationUnit(); } @@ -114,7 +114,7 @@ protected ConfigurationUnit ConfigurationUnit() /// Creates a configuration parameter via the configuration statics object. /// /// A new configuration parameter. - protected ConfigurationParameter ConfigurationParameter() + internal ConfigurationParameter ConfigurationParameter() { return this.Fixture.ConfigurationStatics.CreateConfigurationParameter(); } @@ -123,7 +123,7 @@ protected ConfigurationParameter ConfigurationParameter() /// Creates a configuration set via the configuration statics object. /// /// A new configuration set. - protected ConfigurationSet ConfigurationSet() + internal ConfigurationSet ConfigurationSet() { return this.Fixture.ConfigurationStatics.CreateConfigurationSet(); } @@ -134,7 +134,7 @@ protected ConfigurationSet ConfigurationSet() /// The configuration set. /// The set result. /// The result source. - protected void VerifySummaryEvent(ConfigurationSet configurationSet, ApplyConfigurationSetResult setResult, ConfigurationUnitResultSource resultSource) + internal void VerifySummaryEvent(ConfigurationSet configurationSet, ApplyConfigurationSetResult setResult, ConfigurationUnitResultSource resultSource) { TelemetryEvent summary = this.VerifySummaryEventShared(configurationSet, ConfigurationUnitIntent.Apply, resultSource == ConfigurationUnitResultSource.None ? 0 : setResult.ResultCode.HResult, resultSource); @@ -159,7 +159,7 @@ protected void VerifySummaryEvent(ConfigurationSet configurationSet, ApplyConfig /// The set result. /// The result code. /// The result source. - protected void VerifySummaryEvent(ConfigurationSet configurationSet, TestConfigurationSetResult setResult, int resultCode, ConfigurationUnitResultSource resultSource) + internal void VerifySummaryEvent(ConfigurationSet configurationSet, TestConfigurationSetResult setResult, int resultCode, ConfigurationUnitResultSource resultSource) { TelemetryEvent summary = this.VerifySummaryEventShared(configurationSet, ConfigurationUnitIntent.Assert, resultCode, resultSource); diff --git a/src/Microsoft.Management.Configuration.UnitTests/Helpers/DiagnosticsEventSink.cs b/src/Microsoft.Management.Configuration.UnitTests/Helpers/DiagnosticsEventSink.cs index 710145d81d..8ef30705a0 100644 --- a/src/Microsoft.Management.Configuration.UnitTests/Helpers/DiagnosticsEventSink.cs +++ b/src/Microsoft.Management.Configuration.UnitTests/Helpers/DiagnosticsEventSink.cs @@ -1,4 +1,4 @@ -// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. Licensed under the MIT License. // @@ -40,7 +40,7 @@ public DiagnosticsEventSink(UnitTestFixture fixture, ITestOutputHelper log) /// /// The object sending the information. /// The diagnostic information. - public void DiagnosticsHandler(object? sender, IDiagnosticInformation e) + internal void DiagnosticsHandler(object? sender, IDiagnosticInformation e) { if (e.Message.Contains(TelemetryEvent.Preamble)) { diff --git a/src/Microsoft.Management.Configuration.UnitTests/Microsoft.Management.Configuration.UnitTests.csproj b/src/Microsoft.Management.Configuration.UnitTests/Microsoft.Management.Configuration.UnitTests.csproj index 4cab06265a..c0dd378f7c 100644 --- a/src/Microsoft.Management.Configuration.UnitTests/Microsoft.Management.Configuration.UnitTests.csproj +++ b/src/Microsoft.Management.Configuration.UnitTests/Microsoft.Management.Configuration.UnitTests.csproj @@ -7,10 +7,6 @@ x64;x86;arm64 $(SolutionDir)$(Platform)\$(Configuration)\$(MSBuildProjectName)\ win-x64;win-x86;win-arm64 - - 10.0.22000.53 @@ -23,7 +19,6 @@ - @@ -46,11 +41,6 @@ - - Content - PreserveNewest - True - True @@ -60,6 +50,8 @@ + + diff --git a/src/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationSetProcessorTests.cs b/src/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationSetProcessorTests.cs index 815967b223..65c0c99831 100644 --- a/src/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationSetProcessorTests.cs +++ b/src/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationSetProcessorTests.cs @@ -468,7 +468,7 @@ public void GetUnitProcessorDetails_Local_NotInstalledByPowerShellGet() [InlineData(ConfigurationUnitDetailFlags.Local)] [InlineData(ConfigurationUnitDetailFlags.ReadOnly)] [InlineData(ConfigurationUnitDetailFlags.Download)] - public void GetUnitProcessorDetails_Local(ConfigurationUnitDetailFlags detailFlags) + public void GetUnitProcessorDetails_Local(object detailFlags) { var unit = this.CreateConfigurationUnit(); var (dscResourceInfo, psModuleInfo) = this.GetResourceAndModuleInfo(unit); @@ -498,7 +498,7 @@ public void GetUnitProcessorDetails_Local(ConfigurationUnitDetailFlags detailFla var configurationUnitProcessorDetails = configurationSetProcessor.GetUnitProcessorDetails( unit, - detailFlags); + Assert.IsType(detailFlags)); Assert.NotNull(configurationUnitProcessorDetails); Assert.Equal(dscResourceInfo.Name, configurationUnitProcessorDetails.UnitType); diff --git a/src/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationUnitProcessorTests.cs b/src/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationUnitProcessorTests.cs index 683a026dc7..85543fae26 100644 --- a/src/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationUnitProcessorTests.cs +++ b/src/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationUnitProcessorTests.cs @@ -52,7 +52,7 @@ public ConfigurationUnitProcessorTests(UnitTestFixture fixture, ITestOutputHelpe [InlineData(ConfigurationUnitIntent.Inform)] [InlineData(ConfigurationUnitIntent.Assert)] [InlineData(ConfigurationUnitIntent.Apply)] - public void GetSettings_Test(ConfigurationUnitIntent intent) + public void GetSettings_Test(object intent) { string theKey = "key"; string theValue = "value"; @@ -69,7 +69,7 @@ public void GetSettings_Test(ConfigurationUnitIntent intent) .Returns(valueGetResult) .Verifiable(); - var unitResource = this.CreateUnitResource(intent); + var unitResource = this.CreateUnitResource(Assert.IsType(intent)); var unitProcessor = new ConfigurationUnitProcessor(processorEnvMock.Object, unitResource); @@ -165,7 +165,7 @@ public void TestSettings_InformIntent() [InlineData(ConfigurationUnitIntent.Apply, false)] [InlineData(ConfigurationUnitIntent.Assert, true)] [InlineData(ConfigurationUnitIntent.Apply, true)] - public void TestSettings_TestSucceeded(ConfigurationUnitIntent intent, bool invokeTestResult) + public void TestSettings_TestSucceeded(object intent, bool invokeTestResult) { var processorEnvMock = new Mock(); processorEnvMock.Setup(m => m.InvokeTestResource( @@ -175,7 +175,7 @@ public void TestSettings_TestSucceeded(ConfigurationUnitIntent intent, bool invo .Returns(invokeTestResult) .Verifiable(); - var unitResource = this.CreateUnitResource(intent); + var unitResource = this.CreateUnitResource(Assert.IsType(intent)); var unitProcessor = new ConfigurationUnitProcessor(processorEnvMock.Object, unitResource); @@ -261,10 +261,10 @@ public void TestSettings_Throws_Pwsh_WriteErrorException() [Theory] [InlineData(ConfigurationUnitIntent.Inform)] [InlineData(ConfigurationUnitIntent.Assert)] - public void ApplySettings_InvalidIntent(ConfigurationUnitIntent intent) + public void ApplySettings_InvalidIntent(object intent) { var processorEnvMock = new Mock(); - var unitResource = this.CreateUnitResource(intent); + var unitResource = this.CreateUnitResource(Assert.IsType(intent)); var unitProcessor = new ConfigurationUnitProcessor(processorEnvMock.Object, unitResource); diff --git a/src/Microsoft.Management.Configuration.UnitTests/Tests/OpenConfigurationSetTests.cs b/src/Microsoft.Management.Configuration.UnitTests/Tests/OpenConfigurationSetTests.cs index a2819bd93e..5acf061a1e 100644 --- a/src/Microsoft.Management.Configuration.UnitTests/Tests/OpenConfigurationSetTests.cs +++ b/src/Microsoft.Management.Configuration.UnitTests/Tests/OpenConfigurationSetTests.cs @@ -717,9 +717,9 @@ public void BasicVersion_0_3() [InlineData("object", "42", 42, Windows.Foundation.PropertyType.Inspectable)] [InlineData("secureobject", "string", "string", Windows.Foundation.PropertyType.Inspectable, true)] [InlineData("secureobject", "42", 42, Windows.Foundation.PropertyType.Inspectable, true)] - public void Parameters_DefaultValue_Success(string type, string defaultValue, object expectedValue, Windows.Foundation.PropertyType expectedType, bool secure = false) + public void Parameters_DefaultValue_Success(string type, string defaultValue, object expectedValue, object expectedType, bool secure = false) { - this.TestParameterDefaultValue(type, defaultValue, expectedValue, expectedType, secure); + this.TestParameterDefaultValue(type, defaultValue, expectedValue, Assert.IsType(expectedType), secure); } /// diff --git a/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Microsoft.WinGet.Configuration.Cmdlets.csproj b/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Microsoft.WinGet.Configuration.Cmdlets.csproj index 5badbfe17c..d8536de3c4 100644 --- a/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Microsoft.WinGet.Configuration.Cmdlets.csproj +++ b/src/PowerShell/Microsoft.WinGet.Configuration.Cmdlets/Microsoft.WinGet.Configuration.Cmdlets.csproj @@ -16,6 +16,7 @@ !!! Remove or update this on the next Microsoft.Windows.CsWinRT package version update. !!! --> 10.0.22000.53 + true @@ -24,6 +25,8 @@ true + + false @@ -46,11 +49,13 @@ None - - + + + + @@ -95,8 +100,8 @@ - - + + diff --git a/src/PowerShell/Microsoft.WinGet.Configuration.Engine/Microsoft.WinGet.Configuration.Engine.csproj b/src/PowerShell/Microsoft.WinGet.Configuration.Engine/Microsoft.WinGet.Configuration.Engine.csproj index 93b1fdb179..d3162ca5e4 100644 --- a/src/PowerShell/Microsoft.WinGet.Configuration.Engine/Microsoft.WinGet.Configuration.Engine.csproj +++ b/src/PowerShell/Microsoft.WinGet.Configuration.Engine/Microsoft.WinGet.Configuration.Engine.csproj @@ -15,6 +15,7 @@ !!! Remove or update this on the next Microsoft.Windows.CsWinRT package version update. !!! --> 10.0.22000.53 + true @@ -23,6 +24,8 @@ true + + false @@ -46,11 +49,13 @@ None - - + + + +