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
2 changes: 1 addition & 1 deletion .globalconfig
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ dotnet_diagnostic.CA1814.severity = none
dotnet_diagnostic.CA1815.severity = none

# CA1816: Dispose methods should call SuppressFinalize
dotnet_diagnostic.CA1816.severity = suggestion
dotnet_diagnostic.CA1816.severity = warning

# CA1819: Properties should not return arrays
dotnet_diagnostic.CA1819.severity = none
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,28 @@ public class CommandLineCmdletBase : PSCmdlet, IDisposable
#region "IDisposable Members"

/// <summary>
/// Dispose Method.
/// Releases all resources used by the <see cref="CommandLineCmdletBase"/>.
/// </summary>
public void Dispose()
{
_process?.Dispose();
Dispose(true);
GC.SuppressFinalize(this);
}

/// <summary>
/// Releases the unmanaged resources used by the <see cref="CommandLineCmdletBase"/>
/// and optionally releases the managed resources.
/// </summary>
/// <param name="disposing">
/// <see langword="true"/> to release both managed and unmanaged resources;
/// <see langword="false"/> to release only unmanaged resources.
/// </param>
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
_process?.Dispose();
}
}

#endregion "IDisposable Members"
Expand Down
13 changes: 11 additions & 2 deletions test/xUnit/csharp/test_FileSystemProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,18 @@ public FileSystemProviderTests()
File.AppendAllText(testPath, testContent);
}

void IDisposable.Dispose()
public void Dispose()
{
File.Delete(testPath);
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
if (disposing)
{
File.Delete(testPath);
}
}

private ExecutionContext GetExecutionContext()
Expand Down
27 changes: 18 additions & 9 deletions test/xUnit/csharp/test_PSConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,27 @@ public PowerShellPolicyFixture()

public void Dispose()
{
CleanupConfigFiles();
if (systemWideConfigBackupFile != null)
{
File.Move(systemWideConfigBackupFile, systemWideConfigFile);
}
Dispose(true);
GC.SuppressFinalize(this);
}

if (currentUserConfigBackupFile != null)
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
File.Move(currentUserConfigBackupFile, currentUserConfigFile);
}
CleanupConfigFiles();
if (systemWideConfigBackupFile != null)
{
File.Move(systemWideConfigBackupFile, systemWideConfigFile);
}

InternalTestHooks.BypassGroupPolicyCaching = originalTestHookValue;
if (currentUserConfigBackupFile != null)
{
File.Move(currentUserConfigBackupFile, currentUserConfigFile);
}

InternalTestHooks.BypassGroupPolicyCaching = originalTestHookValue;
}
}

internal PowerShellPolicies SystemWidePolicies
Expand Down