aboutsummaryrefslogtreecommitdiff
path: root/tests/Jellyfin.Common.Tests/Json/JsonGuidConverterTests.cs
blob: d9e66d677462b71d4d53e9b11d948880544e3668 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;
using System.Text.Json;
using MediaBrowser.Common.Json.Converters;
using Xunit;

namespace Jellyfin.Common.Tests.Extensions
{
    public static class JsonGuidConverterTests
    {
        [Fact]
        public static void Deserialize_Valid_Success()
        {
            var options = new JsonSerializerOptions();
            options.Converters.Add(new JsonGuidConverter());
            Guid value = JsonSerializer.Deserialize<Guid>(@"""a852a27afe324084ae66db579ee3ee18""", options);
            Assert.Equal(new Guid("a852a27afe324084ae66db579ee3ee18"), value);

            value = JsonSerializer.Deserialize<Guid>(@"""e9b2dcaa-529c-426e-9433-5e9981f27f2e""", options);
            Assert.Equal(new Guid("e9b2dcaa-529c-426e-9433-5e9981f27f2e"), value);
        }

        [Fact]
        public static void Roundtrip_Valid_Success()
        {
            var options = new JsonSerializerOptions();
            options.Converters.Add(new JsonGuidConverter());
            Guid guid = new Guid("a852a27afe324084ae66db579ee3ee18");
            string value = JsonSerializer.Serialize(guid, options);
            Assert.Equal(guid, JsonSerializer.Deserialize<Guid>(value, options));
        }
    }
}