File: System\Value\StoringNull.cs
Web Access
Project: src\src\System.Private.Windows.Core\tests\System.Private.Windows.Core.Tests\System.Private.Windows.Core.Tests.csproj (System.Private.Windows.Core.Tests)
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
 
namespace System.ValueTests;
 
public class StoringNull
{
    [Fact]
    public void GetIntFromStoredNull()
    {
        Value nullValue = new((object?)null);
        Assert.Throws<InvalidCastException>(() => _ = nullValue.GetValue<int>());
 
        Value nullFastValue = new((object?)null);
        Assert.Throws<InvalidCastException>(() => _ = nullFastValue.GetValue<int>());
 
        bool success = nullFastValue.TryGetValue(out int result);
        Assert.False(success);
 
        Assert.Equal(default(int), result);
    }
}