Skip to content

Commit

Permalink
Move to .NET 8
Browse files Browse the repository at this point in the history
Seeing a new SID authority that I can't find the ID for in a few of the tests.
  • Loading branch information
JeremyKuhne committed Oct 4, 2024
1 parent ba4be82 commit 5c14064
Show file tree
Hide file tree
Showing 159 changed files with 814 additions and 666 deletions.
56 changes: 48 additions & 8 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ csharp_style_var_when_type_is_apparent = false:silent

# Expression-bodied members
csharp_style_expression_bodied_accessors = true:silent
csharp_style_expression_bodied_constructors =when_on_single_line:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_local_functions =true:silent
csharp_style_expression_bodied_methods =when_on_single_line:silent
csharp_style_expression_bodied_operators =when_on_single_line:silent
csharp_style_expression_bodied_properties = true:suggestion
csharp_style_expression_bodied_local_functions = false:silent
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_operators = false:silent
csharp_style_expression_bodied_properties = true:silent

# Pattern matching preferences
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
Expand Down Expand Up @@ -133,8 +133,8 @@ csharp_style_unused_value_assignment_preference = discard_variable:suggestion
csharp_style_unused_value_expression_statement_preference = discard_variable:silent

# 'using' directive preferences
csharp_using_directive_placement = outside_namespace:warning
csharp_style_namespace_declarations = file_scoped:warning
csharp_using_directive_placement = outside_namespace:silent
csharp_style_namespace_declarations = block_scoped:none

# New line preferences
csharp_new_line_before_catch = true
Expand Down Expand Up @@ -210,7 +210,7 @@ dotnet_naming_style.static_prefix_style.capitalization = camel_case
# internal and private fields should be _camelCase
dotnet_naming_rule.camel_case_for_private_internal_fields.severity = warning
dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields
dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style
dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style
dotnet_naming_symbols.private_internal_fields.applicable_kinds = field
dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal
dotnet_naming_style.camel_case_underscore_style.required_prefix = _
Expand Down Expand Up @@ -354,3 +354,43 @@ dotnet_diagnostic.SA1023.severity = silent

# SA1519: Braces should not be omitted from multi-line child statement
dotnet_diagnostic.SA1519.severity = silent
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
csharp_style_prefer_primary_constructors = true:none
csharp_prefer_system_threading_lock = true:suggestion

# SA1010: Opening square brackets should be spaced correctly
dotnet_diagnostic.SA1010.severity = none

# IDE0290: Use primary constructor
dotnet_diagnostic.IDE0290.severity = none

# xUnit1031: Do not use blocking task operations in test method
dotnet_diagnostic.xUnit1031.severity = none

# CS8981: The type name only contains lower-cased ascii characters. Such names may become reserved for the language.
dotnet_diagnostic.CS8981.severity = none

# IDE0160: Convert to block scoped namespace
dotnet_diagnostic.IDE0160.severity = none

[*.{cs,vb}]
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_operator_placement_when_wrapping = beginning_of_line
tab_width = 4
indent_size = 4
end_of_line = crlf

# IDE0130: Namespace does not match folder structure
dotnet_diagnostic.IDE0130.severity = none
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<!-- Input Directories -->
<PackagesDir Condition="'$(PackagesDir)'==''">$(RepoDir)packages\</PackagesDir>

<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net8.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>

<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down Expand Up @@ -69,7 +69,7 @@
<!-- We're generating our own assembly info in our common project -->
<GenerateAssemblyInfo Condition="'$(GenerateAssemblyInfo)' == ''">false</GenerateAssemblyInfo>

<LangVersion>10.0</LangVersion>
<LangVersion>12.0</LangVersion>

</PropertyGroup>

Expand Down
6 changes: 5 additions & 1 deletion src/AutoGenerated/AutoGenerated.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard1.6</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
<TransformOnBuild>true</TransformOnBuild>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="WInteropStrings.resx">
<Generator>ResXFileCodeGenerator</Generator>
Expand Down
4 changes: 2 additions & 2 deletions src/Performance/Performance.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.1" />
<PackageReference Include="Microsoft.Win32.SystemEvents" Version="6.0.0" />
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
<PackageReference Include="Microsoft.Win32.SystemEvents" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions src/Tests/WInterop.Tests/Compression/LzTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,13 @@ public void CreateFile_OverMaxPathLongPath()
private const string CompressedContent1 = "This is a test file that will test file compression. \r\n";

private static readonly byte[] CompressedFile1 =
{
[
0x53, 0x5A, 0x44, 0x44, 0x88, 0xF0, 0x27, 0x33, 0x41, 0x00, 0x37, 0x00, 0x00, 0x00, 0xDF, 0x54,
0x68, 0x69, 0x73, 0x20, 0xF2, 0xF0, 0x61, 0x20, 0xFF, 0x74, 0x65, 0x73, 0x74, 0x20, 0x66, 0x69,
0x6C, 0xFF, 0x65, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x77, 0xF7, 0x69, 0x6C, 0x6C, 0xF9, 0xF8,
0x63, 0x6F, 0x6D, 0x70, 0xFF, 0x72, 0x65, 0x73, 0x73, 0x69, 0x6F, 0x6E, 0x2E, 0x07, 0x20, 0x0D,
0x0A
};
];

private const string CompressedContent2 =
"Four score and seven years ago our fathers brought forth upon this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal."
Expand All @@ -249,7 +249,7 @@ public void CreateFile_OverMaxPathLongPath()
+ "It is altogether fitting and proper that we should do this.";

private static readonly byte[] CompressedFile2 =
{
[
0x53, 0x5A, 0x44, 0x44, 0x88, 0xF0, 0x27, 0x33, 0x41, 0x00, 0x33, 0x02, 0x00, 0x00, 0xFF, 0x46,
0x6F, 0x75, 0x72, 0x20, 0x73, 0x63, 0x6F, 0xFF, 0x72, 0x65, 0x20, 0x61, 0x6E, 0x64, 0x20, 0x73,
0xFF, 0x65, 0x76, 0x65, 0x6E, 0x20, 0x79, 0x65, 0x61, 0x7F, 0x72, 0x73, 0x20, 0x61, 0x67, 0x6F,
Expand Down Expand Up @@ -279,5 +279,5 @@ public void CreateFile_OverMaxPathLongPath()
0x20, 0x49, 0x74, 0x20, 0x30, 0x00, 0x61, 0x6C, 0x77, 0x74, 0x6F, 0x67, 0xD9, 0x03, 0x66, 0x69,
0x74, 0xD2, 0x02, 0xF0, 0xFB, 0xF1, 0x77, 0x01, 0xDC, 0x05, 0xAA, 0x00, 0x73, 0x68, 0x6F, 0x75,
0x3A, 0x4B, 0x10, 0x64, 0x71, 0x01, 0x69, 0x73, 0x2E
};
];
}
4 changes: 2 additions & 2 deletions src/Tests/WInterop.Tests/Cryptography/CryptographyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ public void BasicEnumerateStores()
[Fact]
public void BasicEnumerateLocations()
{
string[] knownLocations = { "CurrentUser", "LocalMachine", "CurrentService", "Services", "Users", "CurrentUserGroupPolicy", "LocalMachineGroupPolicy", "LocalMachineEnterprise" };
string[] knownLocations = ["CurrentUser", "LocalMachine", "CurrentService", "Services", "Users", "CurrentUserGroupPolicy", "LocalMachineGroupPolicy", "LocalMachineEnterprise"];
var locations = WInterop.Cryptography.Cryptography.EnumerateSystemStoreLocations();
knownLocations.Should().BeSubsetOf(locations);
}

[Fact]
public void BasicEnumeratePhysical()
{
string[] knownPhysical = { ".Default", ".AuthRoot", ".GroupPolicy", ".Enterprise" };
string[] knownPhysical = [".Default", ".AuthRoot", ".GroupPolicy", ".Enterprise"];
var physical = WInterop.Cryptography.Cryptography.EnumeratePhysicalStores(SystemStoreLocation.LocalMachine, "Root");
knownPhysical.Should().BeSubsetOf(physical.Select(p => p.PhysicalStoreName));
}
Expand Down
22 changes: 22 additions & 0 deletions src/Tests/WInterop.Tests/ModuleInitializer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) Jeremy W. Kuhne. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using FluentAssertions.Equivalency;
using System.Runtime.CompilerServices;

namespace WInterop.Tests;

internal static class ModuleInitializer
{
[ModuleInitializer]
public static void Initialize()
{
AssertionOptions.AssertEquivalencyUsing(e => e.ExcludingRefStructs());
}

public static TSelf ExcludingRefStructs<TSelf>(this SelfReferenceEquivalencyAssertionOptions<TSelf> options)
where TSelf : SelfReferenceEquivalencyAssertionOptions<TSelf>
{
return options.Excluding(e => e.Type.IsByRefLike);
}
}
12 changes: 6 additions & 6 deletions src/Tests/WInterop.Tests/Modules/Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public void StdCallViaDllImport()
[Fact]
public unsafe void AsIntArrayInvoke()
{
int[] values = { 3, 4 };
int[] values = [3, 4];

fixed (int* v = values)
{
Expand All @@ -205,7 +205,7 @@ public unsafe void AsIntArrayInvoke()
[Fact]
public unsafe void AsRefIntInvoke()
{
int[] values = { 5, 6 };
int[] values = [5, 6];

fixed (int* v = values)
{
Expand All @@ -227,7 +227,7 @@ public unsafe void AsRefIntInvoke()
[Fact]
public unsafe void EmptyArrayBehavior()
{
int[] values = new int[0];
int[] values = [];

fixed (int* v = values)
{
Expand All @@ -251,7 +251,7 @@ public unsafe void EmptyArrayBehavior()
[Fact]
public unsafe void AsArrayInvoke()
{
Point[] points = { new Point(1, 2), new Point(3, 4) };
Point[] points = [new Point(1, 2), new Point(3, 4)];

fixed (void* p = &points[0])
{
Expand All @@ -271,7 +271,7 @@ public unsafe void AsArrayInvoke()
[Fact]
public unsafe void AsInOutArrayInvoke()
{
Point[] points = { new Point(1, 2), new Point(3, 4) };
Point[] points = [new Point(1, 2), new Point(3, 4)];

fixed (void* p = &points[0])
{
Expand All @@ -291,7 +291,7 @@ public unsafe void AsInOutArrayInvoke()
[Fact]
public unsafe void AsPointerArrayInvoke()
{
Point[] points = { new Point(1, 2), new Point(3, 4) };
Point[] points = [new Point(1, 2), new Point(3, 4)];

fixed (Point* p = &points[0])
{
Expand Down
4 changes: 2 additions & 2 deletions src/Tests/WInterop.Tests/NetworkManagementTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public partial class Basic
[Fact]
public void BasicGetLocalGroupNames()
{
string[] knownLocalGroups = { "Administrators", "Guests", "Users" };
string[] knownLocalGroups = ["Administrators", "Guests", "Users"];
var localGroups = Network.EnumerateLocalGroups();
localGroups.Should().Contain(knownLocalGroups);
knownLocalGroups.Should().BeSubsetOf(localGroups);
Expand All @@ -19,7 +19,7 @@ public void BasicGetLocalGroupNames()
[Fact]
public void BasicGetLocalGroupMembers()
{
string[] knownMembers = { "Authenticated Users", "INTERACTIVE" };
string[] knownMembers = ["Authenticated Users", "INTERACTIVE"];
var members = Network.EnumerateGroupUsers("Users");
members.Select(m => m.Name).Should().Contain(knownMembers);
knownMembers.Should().BeSubsetOf(members.Select(m => m.Name));
Expand Down
2 changes: 1 addition & 1 deletion src/Tests/WInterop.Tests/Shell/AssociationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void GetTextAssociation_OpenCommandExecutable()
{
string value = ShellMethods.AssocQueryString(AssociationFlags.None, AssociationString.Executable, ".txt", "open");
// Example: C:\Program Files (x86)\Notepad++\notepad++.exe
value.Should().EndWithEquivalent(".exe");
value.Should().EndWithEquivalentOf(".exe");
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion src/Tests/WInterop.Tests/Shell/ShellTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class Basic
public void GetKnownFolderPath_Basic()
{
string windowsFolder = ShellMethods.GetKnownFolderPath(KnownFolderIds.Windows);
windowsFolder.Should().EndWithEquivalent("Windows");
windowsFolder.Should().EndWithEquivalentOf("Windows");
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion src/Tests/WInterop.Tests/Storage/FileSecurityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void GetGroupSidForCreatedFile()
using var handle = Storage.CreateFile(cleaner.GetTestPath(), CreationDisposition.CreateNew);
handle.IsInvalid.Should().BeFalse();
SecurityIdentifier sid = Storage.GetPrimaryGroup(handle);
sid.Authority.Should().Be(IdentifierAuthority.NT);
sid.Authority.Should().BeEquivalentTo(IdentifierAuthority.NT);
string sidString = sid.ConvertSidToString();
AccountSidInformation info = sid.LookupAccountSid();
info.Usage.Should().Be(SidNameUse.User);
Expand Down
20 changes: 10 additions & 10 deletions src/Tests/WInterop.Tests/Storage/StorageBehaviors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public unsafe void FindFirstFileBehaviors()
WIN32_FIND_DATAW findData;
fixed (char* p = cleaner.TempFolder)
{
handle = TerraFXWindows.FindFirstFileW((ushort*)p, &findData);
handle = TerraFXWindows.FindFirstFileW(p, &findData);
}

try
Expand All @@ -194,7 +194,7 @@ public unsafe void FindFirstFileBehaviors()

fixed (char* p = cleaner.GetTestPath())
{
handle = TerraFXWindows.FindFirstFileW((ushort*)p, &findData);
handle = TerraFXWindows.FindFirstFileW(p, &findData);
}
WindowsError error = Error.GetLastError();

Expand All @@ -212,7 +212,7 @@ public unsafe void FindFirstFileBehaviors()
}

fixed (char* p = Path.Join(cleaner.GetTestPath(), "NotHere"))
handle = TerraFXWindows.FindFirstFileW((ushort*)p, &findData);
handle = TerraFXWindows.FindFirstFileW(p, &findData);
error = Error.GetLastError();

try
Expand Down Expand Up @@ -245,7 +245,7 @@ public unsafe void GetFileAttributesBehavior_Basic()
{

bool success = TerraFXWindows.GetFileAttributesExW(
(ushort*)p,
p,
GET_FILEEX_INFO_LEVELS.GetFileExInfoStandard,
&attributeData);
success.Should().BeTrue("root location exists");
Expand All @@ -254,7 +254,7 @@ public unsafe void GetFileAttributesBehavior_Basic()
fixed (char* p = cleaner.GetTestPath())
{
bool success = TerraFXWindows.GetFileAttributesExW(
(ushort*)p,
p,
GET_FILEEX_INFO_LEVELS.GetFileExInfoStandard,
&attributeData);
WindowsError error = Error.GetLastError();
Expand All @@ -265,7 +265,7 @@ public unsafe void GetFileAttributesBehavior_Basic()
fixed (char* p = Path.Join(cleaner.GetTestPath(), "NotHere"))
{
bool success = TerraFXWindows.GetFileAttributesExW(
(ushort*)p,
p,
GET_FILEEX_INFO_LEVELS.GetFileExInfoStandard,
&attributeData);

Expand All @@ -285,7 +285,7 @@ public unsafe void GetFileAttributesBehavior_BadCharactersOnNonExistantPath()
fixed (char* p = tempPath)
{
success = TerraFXWindows.GetFileAttributesExW(
(ushort*)p,
p,
GET_FILEEX_INFO_LEVELS.GetFileExInfoStandard,
&attributeData);
}
Expand All @@ -296,7 +296,7 @@ public unsafe void GetFileAttributesBehavior_BadCharactersOnNonExistantPath()
fixed (char* p = Path.Join(tempPath, @"""*"""))
{
success = TerraFXWindows.GetFileAttributesExW(
(ushort*)p,
p,
GET_FILEEX_INFO_LEVELS.GetFileExInfoStandard,
&attributeData);
}
Expand All @@ -309,7 +309,7 @@ public unsafe void GetFileAttributesBehavior_BadCharactersOnNonExistantPath()
fixed (char* p = Path.Join(tempPath, Path.GetRandomFileName(), @"""*"""))
{
success = TerraFXWindows.GetFileAttributesExW(
(ushort*)p,
p,
GET_FILEEX_INFO_LEVELS.GetFileExInfoStandard,
&attributeData);
}
Expand Down Expand Up @@ -344,7 +344,7 @@ public unsafe void GetFileAttributesBehavior_DeletedFile()
fixed (char* p = path)
{
// Find file will work at this point.
findHandle = TerraFXWindows.FindFirstFileW((ushort*)p, (WIN32_FIND_DATAW*)&findData);
findHandle = TerraFXWindows.FindFirstFileW(p, (WIN32_FIND_DATAW*)&findData);
findHandle.Should().NotBe(HANDLE.NULL);
}

Expand Down
Loading

0 comments on commit 5c14064

Please sign in to comment.