JsonGuidConverterTests.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. using System;
  2. using System.Text.Json;
  3. using MediaBrowser.Common.Json.Converters;
  4. using Xunit;
  5. namespace Jellyfin.Common.Tests.Extensions
  6. {
  7. public static class JsonGuidConverterTests
  8. {
  9. [Fact]
  10. public static void Deserialize_Valid_Success()
  11. {
  12. var options = new JsonSerializerOptions();
  13. options.Converters.Add(new JsonGuidConverter());
  14. Guid value = JsonSerializer.Deserialize<Guid>(@"""a852a27afe324084ae66db579ee3ee18""", options);
  15. Assert.Equal(new Guid("a852a27afe324084ae66db579ee3ee18"), value);
  16. value = JsonSerializer.Deserialize<Guid>(@"""e9b2dcaa-529c-426e-9433-5e9981f27f2e""", options);
  17. Assert.Equal(new Guid("e9b2dcaa-529c-426e-9433-5e9981f27f2e"), value);
  18. }
  19. [Fact]
  20. public static void Roundtrip_Valid_Success()
  21. {
  22. var options = new JsonSerializerOptions();
  23. options.Converters.Add(new JsonGuidConverter());
  24. Guid guid = new Guid("a852a27afe324084ae66db579ee3ee18");
  25. string value = JsonSerializer.Serialize(guid, options);
  26. Assert.Equal(guid, JsonSerializer.Deserialize<Guid>(value, options));
  27. }
  28. }
  29. }