Skip to content

Commit

Permalink
Complete config PS module and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnMcPMS committed Feb 3, 2025
1 parent f8cd4ac commit 07b3daf
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public UnitTestFixture(IMessageSink messageSink)
/// <summary>
/// Gets the configuration statics object to use.
/// </summary>
public IConfigurationStatics2 ConfigurationStatics { get; private init; }
internal IConfigurationStatics2 ConfigurationStatics { get; private init; }

/// <summary>
/// Creates a runspace adding the test module path.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected ConfigurationProcessorTestBase(UnitTestFixture fixture, ITestOutputHel
/// </summary>
/// <param name="factory">The factory to use.</param>
/// <returns>The new <see cref="ConfigurationProcessor"/> object.</returns>
protected ConfigurationProcessor CreateConfigurationProcessorWithDiagnostics(IConfigurationSetProcessorFactory? factory = null)
internal ConfigurationProcessor CreateConfigurationProcessorWithDiagnostics(IConfigurationSetProcessorFactory? factory = null)
{
ConfigurationProcessor result = this.Fixture.ConfigurationStatics.CreateConfigurationProcessor(factory);
result.Diagnostics += this.EventSink.DiagnosticsHandler;
Expand All @@ -62,7 +62,7 @@ protected ConfigurationProcessor CreateConfigurationProcessorWithDiagnostics(ICo
/// </summary>
/// <param name="contents">The contents that the stream should contain.</param>
/// <returns>The created stream.</returns>
protected IInputStream CreateStream(string contents)
internal IInputStream CreateStream(string contents)
{
InMemoryRandomAccessStream result = new InMemoryRandomAccessStream();

Expand All @@ -83,7 +83,7 @@ protected IInputStream CreateStream(string contents)
/// </summary>
/// <param name="stream">The output stream.</param>
/// <returns>The created string.</returns>
protected string ReadStream(InMemoryRandomAccessStream stream)
internal string ReadStream(InMemoryRandomAccessStream stream)
{
string result = string.Empty;
using (DataReader reader = new DataReader(stream.GetInputStreamAt(0)))
Expand All @@ -105,7 +105,7 @@ protected string ReadStream(InMemoryRandomAccessStream stream)
/// Creates a configuration unit via the configuration statics object.
/// </summary>
/// <returns>A new configuration unit.</returns>
protected ConfigurationUnit ConfigurationUnit()
internal ConfigurationUnit ConfigurationUnit()
{
return this.Fixture.ConfigurationStatics.CreateConfigurationUnit();
}
Expand All @@ -114,7 +114,7 @@ protected ConfigurationUnit ConfigurationUnit()
/// Creates a configuration parameter via the configuration statics object.
/// </summary>
/// <returns>A new configuration parameter.</returns>
protected ConfigurationParameter ConfigurationParameter()
internal ConfigurationParameter ConfigurationParameter()
{
return this.Fixture.ConfigurationStatics.CreateConfigurationParameter();
}
Expand All @@ -123,7 +123,7 @@ protected ConfigurationParameter ConfigurationParameter()
/// Creates a configuration set via the configuration statics object.
/// </summary>
/// <returns>A new configuration set.</returns>
protected ConfigurationSet ConfigurationSet()
internal ConfigurationSet ConfigurationSet()
{
return this.Fixture.ConfigurationStatics.CreateConfigurationSet();
}
Expand All @@ -134,7 +134,7 @@ protected ConfigurationSet ConfigurationSet()
/// <param name="configurationSet">The configuration set.</param>
/// <param name="setResult">The set result.</param>
/// <param name="resultSource">The result source.</param>
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);

Expand All @@ -159,7 +159,7 @@ protected void VerifySummaryEvent(ConfigurationSet configurationSet, ApplyConfig
/// <param name="setResult">The set result.</param>
/// <param name="resultCode">The result code.</param>
/// <param name="resultSource">The result source.</param>
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);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// <copyright file="DiagnosticsEventSink.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. Licensed under the MIT License.
// </copyright>
Expand Down Expand Up @@ -40,7 +40,7 @@ public DiagnosticsEventSink(UnitTestFixture fixture, ITestOutputHelper log)
/// </summary>
/// <param name="sender">The object sending the information.</param>
/// <param name="e">The diagnostic information.</param>
public void DiagnosticsHandler(object? sender, IDiagnosticInformation e)
internal void DiagnosticsHandler(object? sender, IDiagnosticInformation e)
{
if (e.Message.Contains(TelemetryEvent.Preamble))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
<Platforms>x64;x86;arm64</Platforms>
<OutputPath>$(SolutionDir)$(Platform)\$(Configuration)\$(MSBuildProjectName)\</OutputPath>
<RuntimeIdentifiers>win-x64;win-x86;win-arm64</RuntimeIdentifiers>
<!--
!!! Remove or update this on the next Microsoft.Windows.CsWinRT package version update. !!!
-->
<WindowsSdkPackageVersion>10.0.22000.53</WindowsSdkPackageVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Release'">
Expand All @@ -23,7 +19,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.1.6" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Private.Uri" Version="4.3.2" />
Expand All @@ -46,11 +41,6 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Microsoft.Management.Configuration.Projection\Microsoft.Management.Configuration.Projection.csproj">
<OutputItemType>Content</OutputItemType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ReferenceOutputAssembly>True</ReferenceOutputAssembly>
</ProjectReference>
<ProjectReference Include="..\Microsoft.Management.Configuration\Microsoft.Management.Configuration.vcxproj">
<Private>True</Private>
</ProjectReference>
Expand All @@ -60,6 +50,8 @@
</ProjectReference>
</ItemGroup>

<Import Project="..\targets\ReferenceEmbeddedCsWinRTProject.targets" />

<Target Name="PwshFiles" AfterTargets="AfterBuild">
<ItemGroup>
<RefFiles Include="$(OutputPath)..\..\..\..\..\AnyCPU\$(Configuration)\Microsoft.Management.Configuration.Processor\$(TargetFramework)\win\ref\**\*.*" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -498,7 +498,7 @@ public void GetUnitProcessorDetails_Local(ConfigurationUnitDetailFlags detailFla

var configurationUnitProcessorDetails = configurationSetProcessor.GetUnitProcessorDetails(
unit,
detailFlags);
Assert.IsType<ConfigurationUnitDetailFlags>(detailFlags));

Assert.NotNull(configurationUnitProcessorDetails);
Assert.Equal(dscResourceInfo.Name, configurationUnitProcessorDetails.UnitType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -69,7 +69,7 @@ public void GetSettings_Test(ConfigurationUnitIntent intent)
.Returns(valueGetResult)
.Verifiable();

var unitResource = this.CreateUnitResource(intent);
var unitResource = this.CreateUnitResource(Assert.IsType<ConfigurationUnitIntent>(intent));

var unitProcessor = new ConfigurationUnitProcessor(processorEnvMock.Object, unitResource);

Expand Down Expand Up @@ -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<IProcessorEnvironment>();
processorEnvMock.Setup(m => m.InvokeTestResource(
Expand All @@ -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<ConfigurationUnitIntent>(intent));

var unitProcessor = new ConfigurationUnitProcessor(processorEnvMock.Object, unitResource);

Expand Down Expand Up @@ -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<IProcessorEnvironment>();
var unitResource = this.CreateUnitResource(intent);
var unitResource = this.CreateUnitResource(Assert.IsType<ConfigurationUnitIntent>(intent));

var unitProcessor = new ConfigurationUnitProcessor(processorEnvMock.Object, unitResource);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Windows.Foundation.PropertyType>(expectedType), secure);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
!!! Remove or update this on the next Microsoft.Windows.CsWinRT package version update. !!!
-->
<WindowsSdkPackageVersion>10.0.22000.53</WindowsSdkPackageVersion>
<WinGetCsWinRTEmbedded>true</WinGetCsWinRTEmbedded>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Release'">
Expand All @@ -24,6 +25,8 @@

<PropertyGroup Condition="'$(Configuration)'=='ReleaseStatic'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<!-- From the name, ReleaseStatic would be a better fit for embedded. However, we will use embedded at all times except the inproc nuget package release, so it is better if it is in this configuration. -->
<WinGetCsWinRTEmbedded>false</WinGetCsWinRTEmbedded>
</PropertyGroup>

<ItemGroup>
Expand All @@ -46,11 +49,13 @@
<PropertyGroup>
<ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
</PropertyGroup>
<ItemGroup>

<ItemGroup Condition="'$(WinGetCsWinRTEmbedded)'!='true'">
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.1.6" />
</ItemGroup>

<Import Project="..\..\targets\ReferenceEmbeddedCsWinRTProject.targets" Condition="'$(WinGetCsWinRTEmbedded)'=='true'" />

<ItemGroup>
<ProjectReference Include="..\Microsoft.WinGet.Configuration.Engine\Microsoft.WinGet.Configuration.Engine.csproj" />
</ItemGroup>
Expand Down Expand Up @@ -95,8 +100,8 @@
<Target Name="CopySharedDependencies" AfterTargets="AfterBuild" Condition="'$(Platform)' != 'ARM'">
<ItemGroup>
<ModuleSharedDependency Include="$(OutputPath)Microsoft.Management.Configuration.Processor.dll" />
<ModuleSharedDependency Include="$(OutputPath)Microsoft.Windows.SDK.NET.dll" />
<ModuleSharedDependency Include="$(OutputPath)WinRT.Runtime.dll" />
<ModuleSharedDependency Include="$(OutputPath)Microsoft.Windows.SDK.NET.dll" Condition="'$(WinGetCsWinRTEmbedded)'!='true'" />
<ModuleSharedDependency Include="$(OutputPath)WinRT.Runtime.dll" Condition="'$(WinGetCsWinRTEmbedded)'!='true'" />
<ModuleSharedDependency Include="$(OutputPath)Microsoft.WinGet.SharedLib.dll" />
</ItemGroup>
<Message Importance="high" Text="Copying shared dependencies: '@(ModuleSharedDependency)'" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
!!! Remove or update this on the next Microsoft.Windows.CsWinRT package version update. !!!
-->
<WindowsSdkPackageVersion>10.0.22000.53</WindowsSdkPackageVersion>
<WinGetCsWinRTEmbedded>true</WinGetCsWinRTEmbedded>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Release'">
Expand All @@ -23,6 +24,8 @@

<PropertyGroup Condition="'$(Configuration)'=='ReleaseStatic'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<!-- From the name, ReleaseStatic would be a better fit for embedded. However, we will use embedded at all times except the inproc nuget package release, so it is better if it is in this configuration. -->
<WinGetCsWinRTEmbedded>false</WinGetCsWinRTEmbedded>
</PropertyGroup>

<ItemGroup>
Expand All @@ -46,11 +49,13 @@
<PropertyGroup>
<ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
</PropertyGroup>
<ItemGroup>

<ItemGroup Condition="'$(WinGetCsWinRTEmbedded)'!='true'">
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.1.6" />
</ItemGroup>

<Import Project="..\..\targets\ReferenceEmbeddedCsWinRTProject.targets" Condition="'$(WinGetCsWinRTEmbedded)'=='true'" />

<ItemGroup>
<ProjectReference Include="..\..\Microsoft.Management.Configuration.Processor\Microsoft.Management.Configuration.Processor.csproj" />
<ProjectReference Include="..\Microsoft.WinGet.SharedLib\Microsoft.WinGet.SharedLib.csproj" />
Expand Down

0 comments on commit 07b3daf

Please sign in to comment.