Skip to content

Instantly share code, notes, and snippets.

@EgorBo
Last active November 8, 2017 15:46
Show Gist options
  • Save EgorBo/ce2e7aca568ef60bec1da78aba621668 to your computer and use it in GitHub Desktop.
Save EgorBo/ce2e7aca568ef60bec1da78aba621668 to your computer and use it in GitHub Desktop.
using System;
using Xunit;
namespace ConsoleApp7
{
public class FinalizerTest
{
static void AllocAndLeaveScope()
{
new TestClass();
}
[Fact]
public void CanBeFinalized()
{
AllocAndLeaveScope();
GC.Collect();
GC.WaitForPendingFinalizers();
if (!TestClass.isFinalized)
throw new InvalidOperationException();
}
}
public class TestClass
{
public static bool isFinalized;
~TestClass()
{
isFinalized = true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment