File: JsonDocumentAuthExtensionsTests.cs
Web Access
Project: src\src\Security\Authentication\test\Microsoft.AspNetCore.Authentication.Test.csproj (Microsoft.AspNetCore.Authentication.Test)
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
 
using System.Text.Json;
 
namespace Microsoft.AspNetCore.Authentication.Test;
 
public class JsonDocumentAuthExtensionsTests
{
    [Theory]
    [InlineData("{ \"foo\": null }"{ \"foo\": null }", null)]
    [InlineData("{ \"foo\": \"\" }"{ \"foo\": \"\" }", "")]
    [InlineData("{ \"foo\": \"bar\" }"{ \"foo\": \"bar\" }", "bar")]
    [InlineData("{ \"foo\": 1 }"{ \"foo\": 1 }", "1")]
    [InlineData("{ \"bar\": \"baz\" }"{ \"bar\": \"baz\" }", null)]
    public void GetStringReturnsCorrectValue(string json, string expected)
    {
        using (var document = JsonDocument.Parse(json))
        {
            var value = document.RootElement.GetString("foo");
            Assert.Equal(expected, value);
        }
    }
}