Skip to content
Draft
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
113 changes: 113 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
root = true

[*.cs]
csharp_using_directive_placement = outside_namespace:error
dotnet_sort_system_directives_first = false
dotnet_separate_import_directive_groups = false
file_header_template = Copyright (c). All rights reserved.\n\nLicensed under the MIT license.
csharp_prefer_simple_using_statement = true:error
csharp_prefer_braces = true:silent
csharp_style_namespace_declarations = block_scoped:silent
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
csharp_style_prefer_primary_constructors = true:suggestion
csharp_prefer_system_threading_lock = true:suggestion
csharp_style_prefer_simple_property_accessors = true:suggestion
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_operators = false:silent
csharp_style_expression_bodied_properties = true:silent
csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_accessors = true:silent
csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_local_functions = false:silent
csharp_style_throw_expression = true:suggestion
csharp_style_prefer_null_check_over_type_check = true:suggestion
csharp_prefer_simple_default_expression = true:suggestion
csharp_style_prefer_local_over_anonymous_function = true:suggestion
csharp_style_prefer_index_operator = true:suggestion
csharp_style_prefer_range_operator = true:suggestion
csharp_style_implicit_object_creation_when_type_is_apparent = true:error
csharp_style_prefer_implicitly_typed_lambda_expression = true:suggestion
csharp_style_prefer_tuple_swap = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion
csharp_style_deconstructed_variable_declaration = true:suggestion
csharp_style_var_for_built_in_types = false:error
csharp_style_var_when_type_is_apparent = false:error
csharp_style_var_elsewhere = false:error
csharp_style_allow_embedded_statements_on_same_line_experimental = true:silent
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true:silent
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true:silent
csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = true:silent
csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = true:silent
csharp_style_prefer_unbound_generic_type_in_nameof = true:suggestion
csharp_style_prefer_utf8_string_literals = true:suggestion
[*.{cs,vb}]
#### Naming styles ####

# Naming rules

dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i

dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case

dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case

# Symbol specifications

dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.required_modifiers =

dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types.required_modifiers =

dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers =

# Naming styles

dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
dotnet_style_prefer_auto_properties = true:silent
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
dotnet_style_prefer_conditional_expression_over_return = true:silent
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_compound_assignment = true:suggestion
dotnet_style_prefer_simplified_interpolation = true:suggestion
dotnet_style_prefer_collection_expression = when_types_loosely_match:suggestion
dotnet_style_namespace_match_folder = true:suggestion
dotnet_style_operator_placement_when_wrapping = beginning_of_line
tab_width = 4
indent_size = 4
end_of_line = crlf
dotnet_style_allow_multiple_blank_lines_experimental = true:silent
dotnet_style_allow_statement_immediately_after_block_experimental = true:silent
7 changes: 6 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ env:
BuildConfiguration: 'Debug'
BuildPlatform: 'Any CPU'
ContinuousIntegrationBuild: 'true'
DotNet8Version: '8.x'
DotNet10Version: '10.x'

jobs:
Expand All @@ -29,10 +30,11 @@ jobs:
with:
fetch-depth: 0

- name: Install .NET ${{ env.DotNet10Version }}
- name: Install .NET ${{ env.DotNet8Version }} and ${{ env.DotNet10Version }}
uses: actions/setup-dotnet@v5
with:
dotnet-version: |
${{ env.DotNet8Version }}
${{ env.DotNet10Version }}

- name: Build Solution
Expand All @@ -41,6 +43,9 @@ jobs:
- name: Run Unit Tests (.NET Framework)
run: dotnet test --no-restore --no-build --framework net472 "/Property:Platform=${{ env.BuildPlatform }};Configuration=${{ env.BuildConfiguration }}" "/BinaryLogger:${{ env.ArtifactsDirectoryName }}/test-net472.binlog"

- name: Run Unit Tests (.NET 8)
run: dotnet test --no-restore --no-build --framework net8.0 "/Property:Platform=${{ env.BuildPlatform }};Configuration=${{ env.BuildConfiguration }}" "/BinaryLogger:${{ env.ArtifactsDirectoryName }}/test-net8.0.binlog"

- name: Run Unit Tests (.NET 10)
run: dotnet test --no-restore --no-build --framework net10.0 "/Property:Platform=${{ env.BuildPlatform }};Configuration=${{ env.BuildConfiguration }}" "/BinaryLogger:${{ env.ArtifactsDirectoryName }}/test-net10.0.binlog"

Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ bld/

# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/

# Copilot directory
.copilot

# MSTest test Results
[Tt]est[Rr]esult*/
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<RepositoryType>Git</RepositoryType>
<EmbedUntrackedSources>true</EmbedUntrackedSources>

<DebugType Condition="'$(TargetFramework)' == 'net40'">Full</DebugType>
<DebugType Condition="'$(TargetFramework)' == 'net472'">Full</DebugType>
<NuGetAudit>true</NuGetAudit>
<NuGetAuditMode>All</NuGetAuditMode>
<NuGetAuditLevel>Low</NuGetAuditLevel>
Expand Down
8 changes: 3 additions & 5 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.3.0" />
<PackageVersion Include="Microsoft.Wim" Version="2.0.0" />
<PackageVersion Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageVersion Include="Shouldly" Version="4.3.0" />
<PackageVersion Include="xunit.v3" Version="3.2.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.5" />
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4" />
<PackageVersion Include="xunit.v3" Version="3.2.2" />
</ItemGroup>
<ItemGroup>
<GlobalPackageReference Include="Microsoft.Build.Artifacts" Version="6.1.63" />
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="10.0.103" />
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="10.0.201" />
<GlobalPackageReference Include="Nerdbank.GitVersioning" Version="3.9.50" />
<GlobalPackageReference Include="StyleCop.Analyzers" Version="1.1.118" />
<Compile Include="$(MSBuildThisFileDirectory)src\GlobalSuppressions.cs" Link="%(Filename)%(Extension)" />
<AdditionalFiles Include="$(MSBuildThisFileDirectory)stylecop.json" Visible="False" />
</ItemGroup>
</Project>
5 changes: 3 additions & 2 deletions Microsoft.Dism.sln
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 18
VisualStudioVersion = 18.3.11214.30 main
VisualStudioVersion = 18.3.11214.30
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Dism", "src\Microsoft.Dism\Microsoft.Dism.csproj", "{E6831090-F1C2-4619-9AB2-01D29272357A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Dism.Tests", "src\Microsoft.Dism.Tests\Microsoft.Dism.Tests.csproj", "{B117C151-941D-4158-AAA2-0B058380988E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2173DC1F-7069-4707-963D-04DCF86C4976}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.gitignore = .gitignore
CONTRIBUTING.md = CONTRIBUTING.md
.github\dependabot.yml = .github\dependabot.yml
Directory.Build.props = Directory.Build.props
Expand All @@ -20,7 +22,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
LICENSE = LICENSE
NuGet.config = NuGet.config
README.md = README.md
stylecop.json = stylecop.json
version.json = version.json
EndProjectSection
EndProject
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Dism.Tests/ApplyUnattendTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void ApplyUnattendSimple()
</settings>
</unattend>";

FileInfo unattendXmlFile = new FileInfo(Path.Combine(TestDirectory.FullName, "unattend.xml"));
FileInfo unattendXmlFile = new(Path.Combine(TestDirectory.FullName, "unattend.xml"));

unattendXmlFile.WriteAllText(unattendXml);

Expand Down
67 changes: 66 additions & 1 deletion src/Microsoft.Dism.Tests/CheckImageHealthTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
// Licensed under the MIT license.

using Shouldly;

using System;
using System.Threading;
using System.Threading.Tasks;

using Xunit;

namespace Microsoft.Dism.Tests
Expand All @@ -15,6 +19,67 @@ public CheckImageHealthTest(TestWimTemplate template, ITestOutputHelper testOutp
{
}

[Fact]
public async Task CheckImageHealthAsyncCancellation()
{
using DismSession session = DismApi.OpenOnlineSession();
using CancellationTokenSource cts = new();

cts.Cancel();

bool canceled = false;

try
{
await DismApi.CheckImageHealthAsync(session, scanImage: false, cancellationToken: cts.Token);
}
catch (OperationCanceledException)
{
canceled = true;
}

canceled.ShouldBeTrue();
}

[Fact]
public async Task CheckImageHealthAsyncOnlineSession()
{
using DismSession session = DismApi.OpenOnlineSession();

DismImageHealthState imageHealthState = await DismApi.CheckImageHealthAsync(session, scanImage: false, cancellationToken: TestContext.Current.CancellationToken);

imageHealthState.ShouldBe(DismImageHealthState.Healthy);
}

[Fact]
public async Task CheckImageHealthAsyncWithProgress()
{
int current = -1;
int total = -1;

using DismSession session = DismApi.OpenOnlineSession();
using CancellationTokenSource cts = new();

Progress<DismProgress> progress = new(dismProgress =>
{
current = dismProgress.Current;
total = dismProgress.Total;

dismProgress.Cancel = true; // Cancel the operation, otherwise it takes a few minutes
});

try
{
await DismApi.CheckImageHealthAsync(session, scanImage: true, progress: progress, cancellationToken: cts.Token);
}
catch (OperationCanceledException)
{
}

current.ShouldBeGreaterThan(-1);
total.ShouldBeGreaterThan(-1);
}

[Fact]
public void CheckImageHealthOnlineSession()
{
Expand Down Expand Up @@ -60,4 +125,4 @@ public void CheckImageHealthOnlineSessionWithCallback()
total.ShouldBeGreaterThanOrEqualTo(1000);
}
}
}
}
2 changes: 1 addition & 1 deletion src/Microsoft.Dism.Tests/DismAppxPackageTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Microsoft.Dism.Tests
{
public class DismAppxPackageCollectionTest : DismCollectionTest<DismAppxPackageCollection, DismAppxPackage>
{
private static readonly List<DismApi.DismAppxPackage_> Items = new List<DismApi.DismAppxPackage_>
private static readonly List<DismApi.DismAppxPackage_> Items = new()
{
new DismApi.DismAppxPackage_
{
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.Dism.Tests/DismCapabilityInfoTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Microsoft.Dism.Tests
{
public class DismCapabilityInfoTest : DismStructTest<DismCapabilityInfo>
{
private readonly DismApi.DismCapabilityInfo_ _capabilityInfo = new DismApi.DismCapabilityInfo_
private readonly DismApi.DismCapabilityInfo_ _capabilityInfo = new()
{
Name = "6CDAF47E-B7D8-4A46-9B83-E13CDA1706A7",
DisplayName = "6411A803-B0CB-4570-9BE7-19644412B3C4",
Expand All @@ -24,20 +24,20 @@ public DismCapabilityInfoTest(TestWimTemplate template)
{
}

protected override DismCapabilityInfo Item => new DismCapabilityInfo(ItemPtr);
protected override DismCapabilityInfo Item => new(ItemPtr);

protected override object Struct => _capabilityInfo;

[Fact]
public void DownloadAndInstallSizeDoNotOverflow()
{
DismApi.DismCapabilityInfo_ dismCapabilityInfo = new DismApi.DismCapabilityInfo_
DismApi.DismCapabilityInfo_ dismCapabilityInfo = new()
{
DownloadSize = (uint)int.MaxValue + 1,
InstallSize = (uint)int.MaxValue + 10,
};

DismCapabilityInfo capabilityInfo = new DismCapabilityInfo(dismCapabilityInfo);
DismCapabilityInfo capabilityInfo = new(dismCapabilityInfo);

capabilityInfo.DownloadSize.ShouldBe((uint)int.MaxValue + 1);
capabilityInfo.InstallSize.ShouldBe((uint)int.MaxValue + 10);
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Dism.Tests/DismCapabilityTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Microsoft.Dism.Tests
{
public class DismCapabilityCollectionTest : DismCollectionTest<DismCapabilityCollection, DismCapability>
{
private static readonly List<DismApi.DismCapability_> Items = new List<DismApi.DismCapability_>
private static readonly List<DismApi.DismCapability_> Items = new()
{
new DismApi.DismCapability_
{
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Dism.Tests/DismCollectionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void CollectionTest()
public void CollectionTest_Empty()
{
TCollection actual = GetActual(IntPtr.Zero);
ReadOnlyCollection<TItem> expected = new ReadOnlyCollection<TItem>(new List<TItem>(0));
ReadOnlyCollection<TItem> expected = new(new List<TItem>(0));
actual.ShouldBe(expected);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Dism.Tests/DismCustomPropertyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Microsoft.Dism.Tests
{
public class DismCustomPropertyCollectionTest : DismCollectionTest<DismCustomPropertyCollection, DismCustomProperty>
{
private static readonly List<DismApi.DismCustomProperty_> Items = new List<DismApi.DismCustomProperty_>
private static readonly List<DismApi.DismCustomProperty_> Items = new()
{
new DismApi.DismCustomProperty_
{
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Dism.Tests/DismDriverPackageTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Microsoft.Dism.Tests
{
public class DismDriverPackageCollectionTest : DismCollectionTest<DismDriverPackageCollection, DismDriverPackage>
{
private static readonly List<DismApi.DismDriverPackage_> Items = new List<DismApi.DismDriverPackage_>
private static readonly List<DismApi.DismDriverPackage_> Items = new()
{
new DismApi.DismDriverPackage_
{
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Dism.Tests/DismDriverTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Microsoft.Dism.Tests
{
public class DismDriverCollectionTest : DismCollectionTest<DismDriverCollection, DismDriver>
{
private static readonly List<DismApi.DismDriver_> Items = new List<DismApi.DismDriver_>
private static readonly List<DismApi.DismDriver_> Items = new()
{
new DismApi.DismDriver_
{
Expand Down
Loading