public static async Task NotifyOnValuePropertyChange()
{
bool expectThreadContextChange = false;
int expectedPreviousValue = 0;
int expectedCurrentValue = 1;
bool gotNotification = false;
bool expectNotification = false;
AsyncLocal<int> local = new AsyncLocal<int>(
args =>
{
gotNotification = true;
Assert.True(expectNotification);
expectNotification = false;
Assert.Equal(args.ThreadContextChanged, expectThreadContextChange);
Assert.Equal(args.PreviousValue, expectedPreviousValue);
Assert.Equal(args.CurrentValue, expectedCurrentValue);
});
expectNotification = true;
local.Value = 1;
Assert.True(gotNotification);
expectNotification = true;
expectThreadContextChange = true;
expectedPreviousValue = local.Value;
expectedCurrentValue = 0;
return;
}