mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 15:42:48 -05:00
Start Migration from Newtonsoft.Json to System.Text.Json (#1803)
* Start switch to System.Text.Json * Work on switching to System.Text.Json * Main work on STJ refactor * Fix build errors * Run formatting * Delete unused file * Use legacy for two factor providers * Run formatter * Add TokenProviderTests * Run formatting * Fix merge issues * Switch to use JsonSerializer * Address PR feedback * Fix formatting * Ran formatter * Switch to async * Ensure Enums are serialized as strings * Fix formatting * Enqueue single items as arrays * Remove CreateAsync method on AzureQueueService
This commit is contained in:
66
test/Core.Test/Utilities/JsonHelpersTests.cs
Normal file
66
test/Core.Test/Utilities/JsonHelpersTests.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using System.Text.Json;
|
||||
using Bit.Core.Utilities;
|
||||
using Xunit;
|
||||
|
||||
namespace Bit.Core.Test.Helpers
|
||||
{
|
||||
public class JsonHelpersTests
|
||||
{
|
||||
private static void CompareJson<T>(T value, JsonSerializerOptions options, Newtonsoft.Json.JsonSerializerSettings settings)
|
||||
{
|
||||
var stgJson = JsonSerializer.Serialize(value, options);
|
||||
var nsJson = Newtonsoft.Json.JsonConvert.SerializeObject(value, settings);
|
||||
|
||||
Assert.Equal(stgJson, nsJson);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void DefaultJsonOptions()
|
||||
{
|
||||
var testObject = new SimpleTestObject
|
||||
{
|
||||
Id = 0,
|
||||
Name = "Test",
|
||||
};
|
||||
|
||||
CompareJson(testObject, JsonHelpers.Default, new Newtonsoft.Json.JsonSerializerSettings());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IndentedJsonOptions()
|
||||
{
|
||||
var testObject = new SimpleTestObject
|
||||
{
|
||||
Id = 10,
|
||||
Name = "Test Name"
|
||||
};
|
||||
|
||||
CompareJson(testObject, JsonHelpers.Indented, new Newtonsoft.Json.JsonSerializerSettings
|
||||
{
|
||||
Formatting = Newtonsoft.Json.Formatting.Indented,
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NullValueHandlingJsonOptions()
|
||||
{
|
||||
var testObject = new SimpleTestObject
|
||||
{
|
||||
Id = 14,
|
||||
Name = null,
|
||||
};
|
||||
|
||||
CompareJson(testObject, JsonHelpers.IgnoreWritingNull, new Newtonsoft.Json.JsonSerializerSettings
|
||||
{
|
||||
NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public class SimpleTestObject
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user