diff --git a/Community.Wsl.Sdk.Tests/CommandExecutionOptionsTests.cs b/Community.Wsl.Sdk.Tests/CommandExecutionOptionsTests.cs index 5dc1689..e832730 100644 --- a/Community.Wsl.Sdk.Tests/CommandExecutionOptionsTests.cs +++ b/Community.Wsl.Sdk.Tests/CommandExecutionOptionsTests.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Text; using FluentAssertions; using NUnit.Framework; diff --git a/Community.Wsl.Sdk.Tests/CommandResultTests.cs b/Community.Wsl.Sdk.Tests/CommandResultTests.cs index dcdc5c7..0204cfe 100644 --- a/Community.Wsl.Sdk.Tests/CommandResultTests.cs +++ b/Community.Wsl.Sdk.Tests/CommandResultTests.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using FluentAssertions; +using FluentAssertions; using NUnit.Framework; namespace Community.Wsl.Sdk.Tests; diff --git a/Community.Wsl.Sdk.Tests/CommandTests.cs b/Community.Wsl.Sdk.Tests/CommandTests.cs index 7ba67f9..13c01b1 100644 --- a/Community.Wsl.Sdk.Tests/CommandTests.cs +++ b/Community.Wsl.Sdk.Tests/CommandTests.cs @@ -2,8 +2,8 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; -using Community.Wsl.Sdk.Strategies.Api; using Community.Wsl.Sdk.Strategies.Commands; +using Community.Wsx.Shared; using FakeItEasy; using FluentAssertions; using NUnit.Framework; diff --git a/Community.Wsl.Sdk.Tests/Community.Wsl.Sdk.Tests.csproj b/Community.Wsl.Sdk.Tests/Community.Wsl.Sdk.Tests.csproj index bfd24ca..cf98734 100644 --- a/Community.Wsl.Sdk.Tests/Community.Wsl.Sdk.Tests.csproj +++ b/Community.Wsl.Sdk.Tests/Community.Wsl.Sdk.Tests.csproj @@ -1,7 +1,7 @@ - net6.0-windows + net6.0-windows7.0 enable false True diff --git a/Community.Wsl.Sdk.Tests/StreamDataReaderTests.cs b/Community.Wsl.Sdk.Tests/StreamDataReaderTests.cs index 565a19b..97ce8e6 100644 --- a/Community.Wsl.Sdk.Tests/StreamDataReaderTests.cs +++ b/Community.Wsl.Sdk.Tests/StreamDataReaderTests.cs @@ -2,7 +2,6 @@ using System.IO; using System.Threading.Tasks; using Community.Wsl.Sdk.Strategies.Commands; -using FakeItEasy; using FluentAssertions; using NUnit.Framework; diff --git a/Community.Wsl.Sdk.Tests/StreamNullReaderTests.cs b/Community.Wsl.Sdk.Tests/StreamNullReaderTests.cs index 41dd479..05e41a0 100644 --- a/Community.Wsl.Sdk.Tests/StreamNullReaderTests.cs +++ b/Community.Wsl.Sdk.Tests/StreamNullReaderTests.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Threading.Tasks; using Community.Wsl.Sdk.Strategies.Commands; using FluentAssertions; using NUnit.Framework; diff --git a/Community.Wsl.Sdk.Tests/StreamStringReaderTests.cs b/Community.Wsl.Sdk.Tests/StreamStringReaderTests.cs index 6884c1d..6502424 100644 --- a/Community.Wsl.Sdk.Tests/StreamStringReaderTests.cs +++ b/Community.Wsl.Sdk.Tests/StreamStringReaderTests.cs @@ -1,6 +1,4 @@ -using System; -using System.IO; -using System.Threading.Tasks; +using System.IO; using Community.Wsl.Sdk.Strategies.Commands; using FluentAssertions; using NUnit.Framework; diff --git a/Community.Wsl.Sdk.Tests/Win32EnvironmentTests.cs b/Community.Wsl.Sdk.Tests/Win32EnvironmentTests.cs deleted file mode 100644 index abf9d65..0000000 --- a/Community.Wsl.Sdk.Tests/Win32EnvironmentTests.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using Community.Wsl.Sdk.Strategies.Api; -using FluentAssertions; -using NUnit.Framework; - -namespace Community.Wsl.Sdk.Tests; - -public class Win32EnvironmentTests -{ - [Test] - public void Test_Is64BitOperatingSystem() - { - var env = new Win32Environment(); - - env.Is64BitOperatingSystem.Should().Be(Environment.Is64BitOperatingSystem); - } - - [Test] - public void Test_Is64BitProcess() - { - var env = new Win32Environment(); - - env.Is64BitProcess.Should().Be(Environment.Is64BitProcess); - } - - [Test] - public void Test_OSVersion() - { - var env = new Win32Environment(); - - env.OSVersion.Should().BeEquivalentTo(Environment.OSVersion); - } - - public static readonly Environment.SpecialFolder[] FolderNames = - Enum.GetValues(); - - [Test] - [TestCaseSource(nameof(FolderNames))] - public void Test_GetFolderPath(Environment.SpecialFolder folder) - { - var env = new Win32Environment(); - - env.GetFolderPath(folder).Should().BeEquivalentTo(Environment.GetFolderPath(folder)); - } -} diff --git a/Community.Wsl.Sdk.Tests/Win32RegistryKeyTests.cs b/Community.Wsl.Sdk.Tests/Win32RegistryKeyTests.cs deleted file mode 100644 index 8d67d58..0000000 --- a/Community.Wsl.Sdk.Tests/Win32RegistryKeyTests.cs +++ /dev/null @@ -1,94 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.Versioning; -using Community.Wsl.Sdk.Strategies.Api; -using FluentAssertions; -using Microsoft.Win32; -using NUnit.Framework; - -namespace Community.Wsl.Sdk.Tests; - -/// -/// NOTE: Actually these are integration tests because they rely on the actual windows registry. -/// The used hives and keys are well-known and should be stable on all (valid) windows-based test runner. -/// -[SupportedOSPlatform("windows")] -public class Win32RegistryKeyTests -{ - [Test] - public void Test_GetSubKeyNames() - { - var reg = new Win32RegistryKey(Registry.LocalMachine); - - var pubs = reg.OpenSubKey( - "Software\\Microsoft\\Windows\\CurrentVersion\\WINEVT\\Publishers" - ); - - var values = pubs.GetSubKeyNames(); - - Guid dummy; - values.Should().NotBeEmpty().And.OnlyContain((key) => Guid.TryParse(key, out dummy)); - } - - [Test] - public void Test_GetValue_string() - { - var reg = new Win32RegistryKey(Registry.CurrentUser); - - var console = reg.OpenSubKey("Console"); - - console.GetValue("FaceName").Should().NotBeNull(); - } - - [Test] - public void Test_GetValue_int() - { - var reg = new Win32RegistryKey(Registry.CurrentUser); - - var console = reg.OpenSubKey("Console"); - - console.GetValue("CursorSize").Should().BeGreaterThan(0); - } - - [Test] - public void Test_GetValue_guid() - { - var reg = new Win32RegistryKey(Registry.LocalMachine); - - var crypt = reg.OpenSubKey("SOFTWARE\\Microsoft\\Cryptography"); - - crypt.GetValue("MachineGuid").Should().NotBe(Guid.Empty); - } - - [Test] - public void Test_GetValue_not_existing_key() - { - var reg = new Win32RegistryKey(Registry.CurrentUser); - - var call = () => reg.GetValue("IDoNotExist"); - - call.Should().Throw(); - } - - [Test] - public void Test_GetValue_default_value() - { - var reg = new Win32RegistryKey(Registry.CurrentUser); - - var value = reg.GetValue("IDoNotExist", "foobar"); - - value.Should().BeEquivalentTo("foobar"); - } - - [Test] - public void Test_GetValue_unsupported_type() - { - var reg = new Win32RegistryKey(Registry.CurrentUser); - - var console = reg.OpenSubKey("Console"); - - var call = () => console.GetValue("CursorSize"); - - call.Should().Throw(); - } -} diff --git a/Community.Wsl.Sdk/Community.Wsl.Sdk.csproj b/Community.Wsl.Sdk/Community.Wsl.Sdk.csproj index e113d5a..f35b313 100644 --- a/Community.Wsl.Sdk/Community.Wsl.Sdk.csproj +++ b/Community.Wsl.Sdk/Community.Wsl.Sdk.csproj @@ -4,7 +4,7 @@ net6.0-windows windows SDK for Windows Subsystem for Linux for .NET 6 - (c) 2021 Gitii + (c) 2022 Gitii https://github.com/Gitii/community.wsl.sdk True true @@ -55,7 +55,9 @@ - + + 1.0.3 + diff --git a/Community.Wsl.Sdk/IsExternalInit.cs b/Community.Wsl.Sdk/IsExternalInit.cs deleted file mode 100644 index ec5ba38..0000000 --- a/Community.Wsl.Sdk/IsExternalInit.cs +++ /dev/null @@ -1,16 +0,0 @@ -#if NETSTANDARD2_1_OR_GREATER -// ReSharper disable once CheckNamespace -namespace System.Runtime.CompilerServices; - -using System.ComponentModel; - -/// -/// Reserved to be used by the compiler for tracking metadata. -/// This class should not be used by developers in source code. -/// -[EditorBrowsable(EditorBrowsableState.Never)] -internal static class IsExternalInit -{ -} - -#endif diff --git a/Community.Wsl.Sdk/Strategies/Api/IEnvironment.cs b/Community.Wsl.Sdk/Strategies/Api/IEnvironment.cs deleted file mode 100644 index 3c1fe39..0000000 --- a/Community.Wsl.Sdk/Strategies/Api/IEnvironment.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Community.Wsl.Sdk.Strategies.Api; - -public interface IEnvironment -{ - public abstract bool Is64BitOperatingSystem { get; } - public abstract bool Is64BitProcess { get; } - public abstract System.OperatingSystem OSVersion { get; } - public abstract string GetFolderPath(System.Environment.SpecialFolder folder); -} diff --git a/Community.Wsl.Sdk/Strategies/Api/IIo.cs b/Community.Wsl.Sdk/Strategies/Api/IIo.cs deleted file mode 100644 index d881333..0000000 --- a/Community.Wsl.Sdk/Strategies/Api/IIo.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Community.Wsl.Sdk.Strategies.Api; - -public interface IIo -{ - public abstract bool Exists(string path); - public abstract string Combine(params string[] paths); - public abstract string GetFullPath(string path); -} diff --git a/Community.Wsl.Sdk/Strategies/Api/IProcess.cs b/Community.Wsl.Sdk/Strategies/Api/IProcess.cs deleted file mode 100644 index d5b673f..0000000 --- a/Community.Wsl.Sdk/Strategies/Api/IProcess.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using System.Diagnostics; -using System.IO; - -namespace Community.Wsl.Sdk.Strategies.Api; - -/// -/// Wrapper for a . -/// -/// -public interface IProcess : IDisposable -{ - /// - /// - /// - public bool HasExited { get; } - - /// - /// - /// - public StreamReader StandardOutput { get; } - - /// - /// - /// - public StreamReader StandardError { get; } - - /// - /// - /// - public StreamWriter StandardInput { get; } - - /// - /// - /// - public bool EnableRaisingEvents { get; set; } - - /// - /// - /// - public event EventHandler Exited; - - /// - /// - /// - public int ExitCode { get; } - - /// - /// - /// - public void WaitForExit(); -} diff --git a/Community.Wsl.Sdk/Strategies/Api/IProcessManager.cs b/Community.Wsl.Sdk/Strategies/Api/IProcessManager.cs deleted file mode 100644 index d40be18..0000000 --- a/Community.Wsl.Sdk/Strategies/Api/IProcessManager.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Diagnostics; - -namespace Community.Wsl.Sdk.Strategies.Api; - -/// -/// Wrapper for . -/// Returns an wrapped in a . -/// -public interface IProcessManager -{ - /// - /// - /// - /// - /// - public abstract IProcess? Start(ProcessStartInfo startInfo); -} diff --git a/Community.Wsl.Sdk/Strategies/Api/IRegistry.cs b/Community.Wsl.Sdk/Strategies/Api/IRegistry.cs deleted file mode 100644 index dca05f3..0000000 --- a/Community.Wsl.Sdk/Strategies/Api/IRegistry.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Community.Wsl.Sdk.Strategies.Api; - -public interface IRegistry -{ - IRegistryKey GetCurrentUser(); -} diff --git a/Community.Wsl.Sdk/Strategies/Api/IRegistryKey.cs b/Community.Wsl.Sdk/Strategies/Api/IRegistryKey.cs deleted file mode 100644 index 81b0858..0000000 --- a/Community.Wsl.Sdk/Strategies/Api/IRegistryKey.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using Microsoft.Win32; - -namespace Community.Wsl.Sdk.Strategies.Api; - -public interface IRegistryKey : IDisposable -{ - public T GetValue(string name); - public T GetValue(string name, T defaultValue); - public string[] GetSubKeyNames(); - - /// - /// - /// - public IRegistryKey OpenSubKey(string subKey); -} diff --git a/Community.Wsl.Sdk/Strategies/Api/Win32Environment.cs b/Community.Wsl.Sdk/Strategies/Api/Win32Environment.cs deleted file mode 100644 index d256ca8..0000000 --- a/Community.Wsl.Sdk/Strategies/Api/Win32Environment.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; - -namespace Community.Wsl.Sdk.Strategies.Api; - -internal class Win32Environment : IEnvironment -{ - public bool Is64BitOperatingSystem => Environment.Is64BitOperatingSystem; - - public bool Is64BitProcess => Environment.Is64BitProcess; - - public OperatingSystem OSVersion => Environment.OSVersion; - - public string GetFolderPath(Environment.SpecialFolder folder) - { - return Environment.GetFolderPath(folder); - } -} diff --git a/Community.Wsl.Sdk/Strategies/Api/Win32IO.cs b/Community.Wsl.Sdk/Strategies/Api/Win32IO.cs deleted file mode 100644 index 887a4b1..0000000 --- a/Community.Wsl.Sdk/Strategies/Api/Win32IO.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.IO; - -namespace Community.Wsl.Sdk.Strategies.Api; - -internal class Win32IO : IIo -{ - public bool Exists(string path) - { - return File.Exists(path); - } - - public string Combine(params string[] paths) - { - return Path.Combine(paths); - } - - public string GetFullPath(string path) - { - return Path.GetFullPath(path); - } -} diff --git a/Community.Wsl.Sdk/Strategies/Api/Win32Process.cs b/Community.Wsl.Sdk/Strategies/Api/Win32Process.cs deleted file mode 100644 index 70d21c4..0000000 --- a/Community.Wsl.Sdk/Strategies/Api/Win32Process.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Diagnostics; -using System.IO; - -namespace Community.Wsl.Sdk.Strategies.Api; - -internal class Win32Process : IProcess -{ - private readonly Process _process; - - public Win32Process(Process process) - { - _process = process; - } - - public void Dispose() - { - _process.Dispose(); - } - - public bool HasExited => _process.HasExited; - - public StreamReader StandardOutput => _process.StandardOutput; - - public StreamReader StandardError => _process.StandardError; - - public StreamWriter StandardInput => _process.StandardInput; - - public bool EnableRaisingEvents - { - get => _process.EnableRaisingEvents; - set => _process.EnableRaisingEvents = value; - } - - public event EventHandler? Exited - { - add => _process.Exited += value; - remove => _process.Exited -= value; - } - - public int ExitCode => _process.ExitCode; - - public void WaitForExit() - { - _process.WaitForExit(); - } -} diff --git a/Community.Wsl.Sdk/Strategies/Api/Win32ProcessManager.cs b/Community.Wsl.Sdk/Strategies/Api/Win32ProcessManager.cs deleted file mode 100644 index ba10033..0000000 --- a/Community.Wsl.Sdk/Strategies/Api/Win32ProcessManager.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Diagnostics; - -namespace Community.Wsl.Sdk.Strategies.Api; - -internal class Win32ProcessManager : IProcessManager -{ - public IProcess? Start(ProcessStartInfo startInfo) - { - var process = Process.Start(startInfo); - if (process == null) - { - return null; - } - - return new Win32Process(process); - } -} diff --git a/Community.Wsl.Sdk/Strategies/Api/Win32Registry.cs b/Community.Wsl.Sdk/Strategies/Api/Win32Registry.cs deleted file mode 100644 index a9eb072..0000000 --- a/Community.Wsl.Sdk/Strategies/Api/Win32Registry.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Microsoft.Win32; - -namespace Community.Wsl.Sdk.Strategies.Api; - -internal class Win32Registry : IRegistry -{ - public IRegistryKey GetCurrentUser() - { - return new Win32RegistryKey(Registry.CurrentUser); - } -} diff --git a/Community.Wsl.Sdk/Strategies/Api/Win32RegistryKey.cs b/Community.Wsl.Sdk/Strategies/Api/Win32RegistryKey.cs deleted file mode 100644 index 53fa4cc..0000000 --- a/Community.Wsl.Sdk/Strategies/Api/Win32RegistryKey.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System; -using System.Collections.Generic; -using Microsoft.Win32; - -namespace Community.Wsl.Sdk.Strategies.Api; - -internal class Win32RegistryKey : IRegistryKey -{ - private readonly RegistryKey _registryKey; - - public Win32RegistryKey(RegistryKey registryKey) - { - _registryKey = registryKey; - } - - public T GetValue(string name) - { - var value = GetValue(name, default(T)!); - if (value == null || value.Equals(default(T))) - { - throw new KeyNotFoundException($"The registry key {name} doesn't exist!"); - } - - return value; - } - - public T GetValue(string name, T defaultValue) - { - object? value = _registryKey.GetValue(name); - - if (value == null) - { - return defaultValue; - } - else if (typeof(T) == value.GetType()) - { - return (T)value; - } - else if (typeof(T) == typeof(Guid)) - { - string strValue = GetValue(name); - - return (T)(object)Guid.Parse(strValue); - } - else - { - throw new Exception("Unsupported type " + typeof(T).FullName); - } - } - - public string[] GetSubKeyNames() - { - return _registryKey.GetSubKeyNames(); - } - - public IRegistryKey OpenSubKey(string subKey) - { - return new Win32RegistryKey( - _registryKey.OpenSubKey(subKey, false) - ?? throw new Exception("There is no sub key " + subKey) - ); - } - - public void Dispose() - { - _registryKey.Dispose(); - } -} diff --git a/Community.Wsl.Sdk/Strategies/Api/WslApi.cs b/Community.Wsl.Sdk/Strategies/Api/WslApi.cs index c62256d..169f926 100644 --- a/Community.Wsl.Sdk/Strategies/Api/WslApi.cs +++ b/Community.Wsl.Sdk/Strategies/Api/WslApi.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using Community.Wsx.Shared; namespace Community.Wsl.Sdk.Strategies.Api; @@ -58,13 +59,13 @@ public bool IsWslSupported(out string? missingCapabilities) var systemDirectory = _environment.GetFolderPath(Environment.SpecialFolder.System); - if (!_io.Exists(_io.Combine(systemDirectory, "wslapi.dll"))) + if (!_io.FileExists(_io.Combine(systemDirectory, "wslapi.dll"))) { missingCapabilities = "This system does not have WSL enabled."; return false; } - if (!_io.Exists(_io.Combine(systemDirectory, "wsl.exe"))) + if (!_io.FileExists(_io.Combine(systemDirectory, "wsl.exe"))) { missingCapabilities = "This system does not have wsl.exe CLI."; return false; diff --git a/Community.Wsl.Sdk/Strategies/Commands/Command.cs b/Community.Wsl.Sdk/Strategies/Commands/Command.cs index a0b249f..68440c3 100644 --- a/Community.Wsl.Sdk/Strategies/Commands/Command.cs +++ b/Community.Wsl.Sdk/Strategies/Commands/Command.cs @@ -2,7 +2,7 @@ using System.Diagnostics; using System.IO; using System.Threading.Tasks; -using Community.Wsl.Sdk.Strategies.Api; +using Community.Wsx.Shared; namespace Community.Wsl.Sdk.Strategies.Commands; diff --git a/README.md b/README.md index 7b1112d..6b1b296 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ Breaking changes: * Support for Net. 5 has been removed. Net. 5 is [out of support since May 10, 2022](https://dotnet.microsoft.com/en-us/platform/support/policy/dotnet-core). * Support for .NET Core 3.1 has been removed. .NET Core 3.1 will be [out of support after December 13, 2022](https://dotnet.microsoft.com/en-us/platform/support/policy/dotnet-core). - +* Migrated to `Community.Wsx.Shared` (replaces most interfaces and implementations for ) Please upgrade to a newer .NET and .NET Core runtime version. The minimum supported Net. version is Net. 6. diff --git a/generate-coverage.cmd b/generate-coverage.cmd index 1437d25..4f839c7 100644 --- a/generate-coverage.cmd +++ b/generate-coverage.cmd @@ -1,2 +1,2 @@ -dotnet test /p:TargetFramework=net6.0-windows /p:CollectCoverage=true /p:Exclude=\"[Community.Wsl.Sdk.Tests]*\" /p:CoverletOutput=../CoverageResults/ /p:MergeWith="../CoverageResults/coverage.net6.0.json" /p:CoverletOutputFormat=\"cobertura,json\" /p:ThresholdType=\"line,branch,method\" -m:1 +dotnet test /p:TargetFramework=net6.0-windows7.0 /p:CollectCoverage=true /p:Exclude=\"[Community.Wsl.Sdk.Tests]*\" /p:CoverletOutput=../CoverageResults/ /p:MergeWith="../CoverageResults/coverage.net6.0.json" /p:CoverletOutputFormat=\"cobertura,json\" /p:ThresholdType=\"line,branch,method\" -m:1 diff --git a/generate-coverage.sh b/generate-coverage.sh index 8306093..94bf26f 100644 --- a/generate-coverage.sh +++ b/generate-coverage.sh @@ -2,5 +2,5 @@ set -e -dotnet test /p:TargetFramework=net6.0-windows /p:CollectCoverage=true /p:Exclude=\"[Community.Wsl.Sdk.Tests]*\" /p:CoverletOutput=../CoverageResults/ /p:MergeWith="../CoverageResults/coverage.net6.0.json" /p:CoverletOutputFormat=\"cobertura,json\" /p:ThresholdType=\"line,branch,method\" -m:1 +dotnet test /p:TargetFramework=net6.0-windows7.0 /p:CollectCoverage=true /p:Exclude=\"[Community.Wsl.Sdk.Tests]*\" /p:CoverletOutput=../CoverageResults/ /p:MergeWith="../CoverageResults/coverage.net6.0.json" /p:CoverletOutputFormat=\"cobertura,json\" /p:ThresholdType=\"line,branch,method\" -m:1