Skip to content
Merged
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
64 changes: 64 additions & 0 deletions PolyShim.Tests/Net70/ProcessTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using System.Diagnostics;
using FluentAssertions;
using Xunit;

namespace PolyShim.Tests.Net70;

public class ProcessTests
{
[Fact]
public void WaitForExit_TimeSpan_Test()
{
// Arrange
using var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = OperatingSystem.IsWindows() ? "cmd" : "sleep",
Arguments = OperatingSystem.IsWindows() ? "/c timeout 1" : "1",
CreateNoWindow = true,
UseShellExecute = false,
},
};

process.Start();

// Act
var exited = process.WaitForExit(TimeSpan.FromSeconds(10));

// Assert
exited.Should().BeTrue();
process.HasExited.Should().BeTrue();
}
Comment thread
Tyrrrz marked this conversation as resolved.

[Fact]
public void WaitForExit_TimeSpan_Timeout_Test()
{
// Arrange
using var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = OperatingSystem.IsWindows() ? "cmd" : "sleep",
Arguments = OperatingSystem.IsWindows() ? "/c timeout 30 /nobreak" : "30",
CreateNoWindow = true,
UseShellExecute = false,
},
};
process.Start();

try
{
// Act
var exited = process.WaitForExit(TimeSpan.FromMilliseconds(100));

// Assert
exited.Should().BeFalse();
}
finally
{
process.Kill();
Comment thread
Tyrrrz marked this conversation as resolved.
}
}
}
29 changes: 29 additions & 0 deletions PolyShim/Net70/Process.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#if FEATURE_PROCESS
#if (NETCOREAPP && !NET7_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD)
#nullable enable
#pragma warning disable CS0436

using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

#if !POLYSHIM_INCLUDE_COVERAGE
[ExcludeFromCodeCoverage]
#endif
internal static class MemberPolyfills_Net70_Process
{
extension(Process process)
{
// https://learn.microsoft.com/dotnet/api/system.diagnostics.process.waitforexit#system-diagnostics-process-waitforexit(system-timespan)
public bool WaitForExit(TimeSpan timeout)
{
var totalMilliseconds = (long)timeout.TotalMilliseconds;
if (totalMilliseconds < -1 || totalMilliseconds > int.MaxValue)
throw new ArgumentOutOfRangeException(nameof(timeout));

return process.WaitForExit((int)totalMilliseconds);
Comment thread
Tyrrrz marked this conversation as resolved.
}
}
}
#endif
#endif
5 changes: 3 additions & 2 deletions Signatures.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Signatures

- **Total:** 487
- **Total:** 488
- **Types:** 106
- **Members:** 381
- **Members:** 382

___

Expand Down Expand Up @@ -369,6 +369,7 @@ ___
- [`static string Join(params string?[])`](https://learn.microsoft.com/dotnet/api/system.io.path.join#system-io-path-join(system-string())) <sup><sub>.NET Core 3.0</sub></sup>
- [`static string TrimEndingDirectorySeparator(string)`](https://learn.microsoft.com/dotnet/api/system.io.path.trimendingdirectoryseparator#system-io-path-trimendingdirectoryseparator(system-string)) <sup><sub>.NET Core 3.0</sub></sup>
- `Process`
- [`bool WaitForExit(TimeSpan)`](https://learn.microsoft.com/dotnet/api/system.diagnostics.process.waitforexit#system-diagnostics-process-waitforexit(system-timespan)) <sup><sub>.NET 7.0</sub></sup>
- [`Task WaitForExitAsync(CancellationToken)`](https://learn.microsoft.com/dotnet/api/system.diagnostics.process.waitforexitasync) <sup><sub>.NET 5.0</sub></sup>
- [`void Kill(bool)`](https://learn.microsoft.com/dotnet/api/system.diagnostics.process.kill#system-diagnostics-process-kill(system-boolean)) <sup><sub>.NET Core 3.0</sub></sup>
- `Queue<T>`
Expand Down
Loading