com.wallstop-studios.unity-helpers 2.0.0-rc81.9 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +1 -1
- package/.gitattributes +1 -1
- package/.githooks/pre-commit +31 -5
- package/.githooks/pre-push +50 -0
- package/.github/dependabot.yml +24 -2
- package/.github/scripts/check-markdown-links.ps1 +77 -0
- package/.github/scripts/check_markdown_links.py +89 -0
- package/.github/scripts/check_markdown_url_encoding.py +74 -0
- package/.github/scripts/validate_markdown_links.py +194 -0
- package/.github/workflows/csharpier-autofix.yml +152 -0
- package/.github/workflows/format-on-demand.yml +305 -0
- package/.github/workflows/lint-doc-links.yml +8 -5
- package/.github/workflows/markdown-json.yml +6 -2
- package/.github/workflows/npm-publish.yml +1 -1
- package/.github/workflows/prettier-autofix.yml +195 -0
- package/.github/workflows/update-dotnet-tools.yml +80 -0
- package/.github/workflows/yaml-format-lint.yml +41 -0
- package/.lychee.toml +4 -4
- package/.markdownlint.jsonc +21 -0
- package/.pre-commit-config.yaml +11 -3
- package/.yamllint.yaml +31 -0
- package/AGENTS.md +5 -1
- package/Docs/CHANGELOG.md +11 -0
- package/Docs/CONTRIBUTING.md +49 -0
- package/Docs/CONTRIBUTING.md.meta +7 -0
- package/{EDITOR_TOOLS_GUIDE.md → Docs/EDITOR_TOOLS_GUIDE.md} +4 -0
- package/Docs/EFFECTS_SYSTEM.md +1316 -0
- package/{EFFECTS_SYSTEM_TUTORIAL.md → Docs/EFFECTS_SYSTEM_TUTORIAL.md} +1 -1
- package/{GETTING_STARTED.md → Docs/GETTING_STARTED.md} +50 -64
- package/{GLOSSARY.md → Docs/GLOSSARY.md} +4 -4
- package/Docs/HELPER_UTILITIES.md +885 -0
- package/Docs/HELPER_UTILITIES.md.meta +7 -0
- package/{INDEX.md → Docs/INDEX.md} +107 -62
- package/Docs/MATH_AND_EXTENSIONS.md +1039 -0
- package/{RANDOM_PERFORMANCE.md → Docs/RANDOM_PERFORMANCE.md} +15 -15
- package/{RELATIONAL_COMPONENTS.md → Docs/RELATIONAL_COMPONENTS.md} +111 -84
- package/{SERIALIZATION.md → Docs/SERIALIZATION.md} +15 -0
- package/{SPATIAL_TREES_2D_GUIDE.md → Docs/SPATIAL_TREES_2D_GUIDE.md} +2 -2
- package/{SPATIAL_TREES_3D_GUIDE.md → Docs/SPATIAL_TREES_3D_GUIDE.md} +1 -1
- package/Docs/SPATIAL_TREE_2D_PERFORMANCE.md +241 -0
- package/Docs/SPATIAL_TREE_3D_PERFORMANCE.md +243 -0
- package/{THIRD_PARTY_NOTICES.md → Docs/THIRD_PARTY_NOTICES.md} +1 -1
- package/Docs/UTILITY_COMPONENTS.md +906 -0
- package/Docs/UTILITY_COMPONENTS.md.meta +7 -0
- package/Docs/VISUAL_COMPONENTS.md +337 -0
- package/Docs/VISUAL_COMPONENTS.md.meta +7 -0
- package/Editor/AnimationEventEditor.cs +337 -160
- package/Editor/Core/Helper/AnimationEventHelpers.cs +178 -152
- package/Editor/CustomEditors/PersistentDirectoryGUI.cs +20 -11
- package/Editor/CustomEditors/TexturePlatformOverrideEntryDrawer.cs +11 -2
- package/Editor/FitTextureSizeWindow.cs +43 -19
- package/Editor/PersistentDirectorySettings.cs +64 -12
- package/Editor/PrefabChecker.cs +72 -5
- package/Editor/Sprites/AnimationCopier.cs +131 -55
- package/Editor/Sprites/AnimationCreator.cs +63 -22
- package/Editor/Sprites/AnimationViewerWindow.cs +42 -6
- package/Editor/Sprites/TexturePlatformNameHelper.cs +50 -39
- package/Editor/Sprites/TextureResizerWizard.cs +23 -1
- package/Editor/Sprites/TextureSettingsApplierWindow.cs +148 -85
- package/Editor/Tools/ImageBlurTool.cs +81 -10
- package/Editor/Utils/EditorUi.cs +1 -1
- package/Editor/Utils/ScriptableObjectSingletonCreator.cs +1 -1
- package/README.md +428 -2433
- package/Runtime/AssemblyInfo.cs +4 -0
- package/Runtime/Core/Attributes/NotNullAttribute.cs +1 -3
- package/Runtime/Core/Attributes/RelationalComponentAssigner.cs +50 -5
- package/Runtime/Core/DataStructure/CyclicBuffer.cs +0 -1
- package/Runtime/Core/DataStructure/KDTree3D.cs +1 -1
- package/Runtime/Core/DataStructure/OctTree3D.cs +1 -1
- package/Runtime/Core/Extension/AsyncOperationExtensions.cs +122 -0
- package/Runtime/Core/Extension/RandomExtensions.cs +68 -0
- package/Runtime/Core/Extension/WallstopStudiosLogger.cs +16 -0
- package/Runtime/Core/Helper/Partials/ObjectHelpers.cs +4 -1
- package/Runtime/Core/Helper/ReflectionHelpers.cs +21 -10
- package/Runtime/Core/Helper/SpriteHelpers.cs +3 -1
- package/Runtime/Core/Helper/UnityMainThreadDispatcher.cs +45 -1
- package/Runtime/Core/Serialization/JsonConverters/GameObjectConverter.cs +13 -5
- package/Runtime/Core/Serialization/JsonConverters/ResolutionConverter.cs +1 -1
- package/Runtime/Core/Serialization/JsonConverters/TypeConverter.cs +1 -1
- package/Runtime/Core/Serialization/ProtobufUnitySurrogates.cs +24 -29
- package/Runtime/Core/Serialization/Serializer.cs +101 -0
- package/Runtime/Integrations/Reflex/AssemblyInfo.cs +7 -0
- package/Runtime/Integrations/Reflex/AssemblyInfo.cs.meta +11 -0
- package/Runtime/Integrations/Reflex/ContainerRelationalExtensions.cs +198 -0
- package/Runtime/Integrations/Reflex/ContainerRelationalExtensions.cs.meta +11 -0
- package/Runtime/Integrations/Reflex/RelationalComponentsInstaller.cs +86 -0
- package/Runtime/Integrations/Reflex/RelationalComponentsInstaller.cs.meta +11 -0
- package/Runtime/Integrations/Reflex/RelationalReflexSceneBootstrapper.cs +316 -0
- package/Runtime/Integrations/Reflex/RelationalReflexSceneBootstrapper.cs.meta +11 -0
- package/Runtime/Integrations/Reflex/RelationalSceneAssignmentOptions.cs +86 -0
- package/Runtime/Integrations/Reflex/RelationalSceneAssignmentOptions.cs.meta +11 -0
- package/Runtime/Integrations/Reflex/WallstopStudios.UnityHelpers.Integration.Reflex.asmdef +20 -0
- package/Runtime/Integrations/Reflex/WallstopStudios.UnityHelpers.Integration.Reflex.asmdef.meta +7 -0
- package/Runtime/Integrations/Reflex.meta +8 -0
- package/Runtime/Integrations/VContainer/AssemblyInfo.cs +9 -0
- package/Runtime/Integrations/VContainer/AssemblyInfo.cs.meta +3 -0
- package/Runtime/Integrations/VContainer/ObjectResolverRelationalExtensions.cs +96 -0
- package/Runtime/Integrations/VContainer/RelationalComponentEntryPoint.cs +90 -10
- package/Runtime/Integrations/VContainer/RelationalComponentsBuilderExtensions.cs +13 -1
- package/Runtime/Integrations/VContainer/RelationalObjectPools.cs +114 -0
- package/Runtime/Integrations/VContainer/RelationalObjectPools.cs.meta +11 -0
- package/Runtime/Integrations/VContainer/RelationalSceneAssignmentOptions.cs +16 -4
- package/Runtime/Integrations/VContainer/RelationalSceneLoadListener.cs +241 -0
- package/Runtime/Integrations/VContainer/RelationalSceneLoadListener.cs.meta +11 -0
- package/Runtime/Integrations/Zenject/AssemblyInfo.cs +9 -0
- package/Runtime/Integrations/Zenject/AssemblyInfo.cs.meta +3 -0
- package/Runtime/Integrations/Zenject/DiContainerRelationalExtensions.cs +69 -2
- package/Runtime/Integrations/Zenject/RelationalComponentSceneInitializer.cs +89 -12
- package/Runtime/Integrations/Zenject/RelationalComponentsInstaller.cs +23 -1
- package/Runtime/Integrations/Zenject/RelationalMemoryPools.cs +44 -0
- package/Runtime/Integrations/Zenject/RelationalMemoryPools.cs.meta +11 -0
- package/Runtime/Integrations/Zenject/RelationalSceneAssignmentOptions.cs +16 -10
- package/Runtime/Integrations/Zenject/RelationalSceneLoadListener.cs +243 -0
- package/Runtime/Integrations/Zenject/RelationalSceneLoadListener.cs.meta +11 -0
- package/Runtime/Tags/AttributeMetadataCache.cs +1 -4
- package/Runtime/Utils/Buffers.cs +4 -4
- package/Runtime/Utils/ScriptableObjectSingleton.cs +1 -2
- package/Runtime/Utils/SetTextureImportData.cs +3 -1
- package/Runtime/Utils/TextureScale.cs +10 -2
- package/Runtime/Visuals/UGUI/EnhancedImage.cs +6 -0
- package/Runtime/Visuals/UIToolkit/LayeredImage.cs +4 -1
- package/Samples~/DI - Reflex/README.md +527 -0
- package/Samples~/DI - Reflex/README.md.meta +7 -0
- package/Samples~/DI - Reflex/Scripts/ReflexPaletteService.cs +36 -0
- package/Samples~/DI - Reflex/Scripts/ReflexPaletteService.cs.meta +11 -0
- package/Samples~/DI - Reflex/Scripts/ReflexRelationalConsumer.cs +79 -0
- package/Samples~/DI - Reflex/Scripts/ReflexRelationalConsumer.cs.meta +11 -0
- package/Samples~/DI - Reflex/Scripts/ReflexSampleInstaller.cs +30 -0
- package/Samples~/DI - Reflex/Scripts/ReflexSampleInstaller.cs.meta +11 -0
- package/Samples~/DI - Reflex/Scripts/ReflexSpawner.cs +79 -0
- package/Samples~/DI - Reflex/Scripts/ReflexSpawner.cs.meta +11 -0
- package/Samples~/DI - Reflex/Scripts/Samples.UnityHelpers.DI.Reflex.asmdef +26 -0
- package/Samples~/DI - Reflex/Scripts/Samples.UnityHelpers.DI.Reflex.asmdef.meta +9 -0
- package/Samples~/DI - Reflex/Scripts.meta +8 -0
- package/Samples~/DI - Reflex.meta +8 -0
- package/Samples~/DI - VContainer/README.md +238 -56
- package/Samples~/DI - VContainer/Scripts/GameLifetimeScope.cs +22 -4
- package/Samples~/DI - VContainer/Scripts/RelationalConsumer.cs +5 -2
- package/Samples~/DI - VContainer/Scripts/Spawner.cs +113 -4
- package/Samples~/DI - Zenject/README.md +223 -58
- package/Samples~/DI - Zenject/Scripts/RelationalConsumer.cs +3 -0
- package/Samples~/DI - Zenject/Scripts/RelationalConsumerPool.cs +37 -0
- package/Samples~/DI - Zenject/Scripts/RelationalConsumerPool.cs.meta +12 -0
- package/Samples~/DI - Zenject/Scripts/SpawnerZenject.cs +74 -3
- package/Samples~/Random - PRNG/README.md +2 -1
- package/Samples~/Relational Components - Basic/README.md +3 -1
- package/Samples~/Serialization - JSON/README.md +2 -1
- package/Samples~/Spatial Structures - 2D and 3D/README.md +2 -1
- package/Samples~/UGUI - EnhancedImage/README.md +2 -1
- package/Samples~/UI Toolkit - MultiFile Selector (Editor)/README.md +2 -1
- package/Tests/Editor/Attributes/AnimationEventHelpersTests.cs +16 -0
- package/Tests/Editor/Core/Attributes/RelationalComponentAssignerTests.cs +32 -34
- package/Tests/Editor/Integrations/Reflex/ReflexIntegrationCompilationTests.cs +41 -0
- package/Tests/Editor/Integrations/Reflex/ReflexIntegrationCompilationTests.cs.meta +11 -0
- package/Tests/Editor/Integrations/Reflex/WallstopStudios.UnityHelpers.Tests.Editor.Reflex.asmdef +27 -0
- package/Tests/Editor/Integrations/Reflex/WallstopStudios.UnityHelpers.Tests.Editor.Reflex.asmdef.meta +7 -0
- package/Tests/Editor/Integrations/Reflex.meta +8 -0
- package/Tests/Editor/Integrations/VContainer/VContainerRelationalEntryPointTests.cs +21 -18
- package/Tests/Editor/Integrations/VContainer/VContainerRelationalHelpersTests.cs +164 -0
- package/Tests/Editor/Integrations/VContainer/VContainerRelationalHelpersTests.cs.meta +11 -0
- package/Tests/Editor/Integrations/VContainer/WallstopStudios.UnityHelpers.Tests.Editor.VContainer.asmdef +2 -1
- package/Tests/Editor/Integrations/Zenject/WallstopStudios.UnityHelpers.Tests.Editor.Zenject.asmdef +3 -2
- package/Tests/Editor/Integrations/Zenject/ZenjectRelationalHelpersTests.cs +127 -0
- package/Tests/Editor/Integrations/Zenject/ZenjectRelationalHelpersTests.cs.meta +11 -0
- package/Tests/Editor/Integrations/Zenject/ZenjectRelationalInitializerTests.cs +25 -23
- package/Tests/Editor/PersistentDirectorySettingsTests.cs +58 -0
- package/Tests/Editor/PersistentDirectorySettingsTests.cs.meta +11 -0
- package/Tests/Editor/PrefabCheckerReportTests.cs +32 -0
- package/Tests/Editor/PrefabCheckerReportTests.cs.meta +11 -0
- package/Tests/Editor/Sprites/AnimationCopierFilterTests.cs +63 -0
- package/Tests/Editor/Sprites/AnimationCopierFilterTests.cs.meta +11 -0
- package/Tests/Editor/Sprites/AnimationCopierWindowTests.cs +1 -1
- package/Tests/Editor/Sprites/AnimationViewerWindowTests.cs +38 -0
- package/Tests/Editor/Sprites/AnimationViewerWindowTests.cs.meta +11 -0
- package/Tests/Editor/Sprites/ScriptableSpriteAtlasEditorTests.cs +1 -1
- package/Tests/Editor/Sprites/SpriteCropperAdditionalTests.cs +12 -12
- package/Tests/Editor/Sprites/SpriteCropperTests.cs +9 -9
- package/Tests/Editor/Sprites/SpritePivotAdjusterTests.cs +3 -3
- package/Tests/Editor/Sprites/TexturePlatformNameHelperTests.cs +18 -0
- package/Tests/Editor/Sprites/TextureResizerWizardTests.cs +5 -5
- package/Tests/Editor/Sprites/TextureSettingsApplierAPITests.cs +3 -3
- package/Tests/Editor/Sprites/TextureSettingsApplierWizardAdditionalTests.cs +4 -4
- package/Tests/Editor/Sprites/TextureSettingsApplierWizardTests.cs +4 -4
- package/Tests/Editor/Tools/ImageBlurToolTests.cs +22 -110
- package/Tests/Editor/Utils/CommonTestBase.cs +60 -1
- package/Tests/Editor/Utils/ScriptableObjectSingletonCreatorTests.cs +6 -6
- package/Tests/Editor/Windows/FitTextureSizeWindowTests.cs +66 -74
- package/Tests/Runtime/Attributes/RelationalComponentInitializerTests.cs +4 -15
- package/Tests/Runtime/DataStructures/SpatialTree3DBoundsConsistencyTests.cs +29 -29
- package/Tests/Runtime/Extensions/AsyncOperationExtensionsTests.cs +179 -0
- package/Tests/Runtime/Extensions/RandomExtensionTests.cs +55 -0
- package/Tests/Runtime/Integrations/Reflex/RelationalComponentsReflexTests.cs +445 -0
- package/Tests/Runtime/Integrations/Reflex/RelationalComponentsReflexTests.cs.meta +11 -0
- package/Tests/Runtime/Integrations/Reflex/WallstopStudios.UnityHelpers.Tests.Runtime.Reflex.asmdef +28 -0
- package/Tests/Runtime/Integrations/Reflex/WallstopStudios.UnityHelpers.Tests.Runtime.Reflex.asmdef.meta +7 -0
- package/Tests/Runtime/Integrations/Reflex.meta +8 -0
- package/Tests/Runtime/Integrations/VContainer/RelationalComponentsVContainerTests.cs +257 -221
- package/Tests/Runtime/Integrations/VContainer/RelationalObjectPoolsVContainerTests.cs +91 -0
- package/Tests/Runtime/Integrations/VContainer/RelationalObjectPoolsVContainerTests.cs.meta +11 -0
- package/Tests/Runtime/Integrations/Zenject/RelationalComponentsZenjectTests.cs +251 -233
- package/Tests/Runtime/Performance/RandomPerformanceTests.cs +1 -1
- package/Tests/Runtime/Performance/SpatialTree2DPerformanceTests.cs +6 -1
- package/Tests/Runtime/Performance/SpatialTree3DPerformanceTests.cs +4 -1
- package/Tests/Runtime/Serialization/JsonConverterAdditionalTests.cs +30 -0
- package/Tests/Runtime/Serialization/JsonConverterAdditionalTests.cs.meta +11 -0
- package/Tests/Runtime/Serialization/JsonConverterTests.cs +8 -12
- package/Tests/Runtime/Serialization/JsonRoundtripComprehensiveTests.cs +4 -9
- package/Tests/Runtime/Serialization/JsonSerializationTest.cs +16 -5
- package/Tests/Runtime/Serialization/ProtoRoundtripComprehensiveTests.cs +13 -13
- package/Tests/Runtime/Serialization/SerializerAdditionalTests.cs +12 -0
- package/Tests/Runtime/Serialization/SerializerFileIoTests.cs +105 -0
- package/Tests/Runtime/Serialization/SerializerFileIoTests.cs.meta +11 -0
- package/Tests/Runtime/Serialization/UnityEngineObjectJsonTests.cs +247 -0
- package/Tests/Runtime/Serialization/UnityEngineObjectJsonTests.cs.meta +11 -0
- package/Tests/Runtime/TestUtils/CommonTestBase.cs +99 -0
- package/Tests/Runtime/TestUtils/ReflexTestSupport.cs +111 -0
- package/Tests/Runtime/TestUtils/ReflexTestSupport.cs.meta +12 -0
- package/Tests/Runtime/Utils/CoroutineHandlerTests.cs +1 -1
- package/Tests/Runtime/Utils/LZMAComprehensiveTests.cs +1 -1
- package/Tests/Runtime/Utils/LZMATests.cs +1 -1
- package/Tests/Runtime/Utils/MatchColliderToSpriteTests.cs +5 -5
- package/Tests/Runtime/Visuals/EnhancedImageTests.cs +25 -56
- package/Tests/Runtime/Visuals/VisualsTestHelpers.cs +1 -8
- package/Tests/TestUtils.meta +8 -0
- package/package-lock.json.meta +7 -0
- package/package.json +13 -4
- package/scripts/check-eol.ps1 +4 -5
- package/scripts/lint-tests.ps1 +156 -0
- package/scripts/lint-tests.ps1.meta +7 -0
- package/scripts/normalize-eol.ps1 +6 -9
- package/.github/workflows/csharpier.yml +0 -135
- package/CHANGELOG.md +0 -0
- package/EFFECTS_SYSTEM.md +0 -242
- package/MATH_AND_EXTENSIONS.md +0 -316
- package/SPATIAL_TREE_2D_PERFORMANCE.md +0 -238
- package/SPATIAL_TREE_3D_PERFORMANCE.md +0 -240
- /package/{CHANGELOG.md.meta → Docs/CHANGELOG.md.meta} +0 -0
- /package/{DATA_STRUCTURES.md → Docs/DATA_STRUCTURES.md} +0 -0
- /package/{DATA_STRUCTURES.md.meta → Docs/DATA_STRUCTURES.md.meta} +0 -0
- /package/{EDITOR_TOOLS_GUIDE.md.meta → Docs/EDITOR_TOOLS_GUIDE.md.meta} +0 -0
- /package/{EFFECTS_SYSTEM.md.meta → Docs/EFFECTS_SYSTEM.md.meta} +0 -0
- /package/{EFFECTS_SYSTEM_TUTORIAL.md.meta → Docs/EFFECTS_SYSTEM_TUTORIAL.md.meta} +0 -0
- /package/{GETTING_STARTED.md.meta → Docs/GETTING_STARTED.md.meta} +0 -0
- /package/{GLOSSARY.md.meta → Docs/GLOSSARY.md.meta} +0 -0
- /package/{HULLS.md → Docs/HULLS.md} +0 -0
- /package/{HULLS.md.meta → Docs/HULLS.md.meta} +0 -0
- /package/{INDEX.md.meta → Docs/INDEX.md.meta} +0 -0
- /package/{LICENSE.md → Docs/LICENSE.md} +0 -0
- /package/{LICENSE.md.meta → Docs/LICENSE.md.meta} +0 -0
- /package/{MATH_AND_EXTENSIONS.md.meta → Docs/MATH_AND_EXTENSIONS.md.meta} +0 -0
- /package/{RANDOM_PERFORMANCE.md.meta → Docs/RANDOM_PERFORMANCE.md.meta} +0 -0
- /package/{REFLECTION_HELPERS.md → Docs/REFLECTION_HELPERS.md} +0 -0
- /package/{REFLECTION_HELPERS.md.meta → Docs/REFLECTION_HELPERS.md.meta} +0 -0
- /package/{RELATIONAL_COMPONENTS.md.meta → Docs/RELATIONAL_COMPONENTS.md.meta} +0 -0
- /package/{SERIALIZATION.md.meta → Docs/SERIALIZATION.md.meta} +0 -0
- /package/{SINGLETONS.md → Docs/SINGLETONS.md} +0 -0
- /package/{SINGLETONS.md.meta → Docs/SINGLETONS.md.meta} +0 -0
- /package/{SPATIAL_TREES_2D_GUIDE.md.meta → Docs/SPATIAL_TREES_2D_GUIDE.md.meta} +0 -0
- /package/{SPATIAL_TREES_3D_GUIDE.md.meta → Docs/SPATIAL_TREES_3D_GUIDE.md.meta} +0 -0
- /package/{SPATIAL_TREE_2D_PERFORMANCE.md.meta → Docs/SPATIAL_TREE_2D_PERFORMANCE.md.meta} +0 -0
- /package/{SPATIAL_TREE_3D_PERFORMANCE.md.meta → Docs/SPATIAL_TREE_3D_PERFORMANCE.md.meta} +0 -0
- /package/{SPATIAL_TREE_SEMANTICS.md → Docs/SPATIAL_TREE_SEMANTICS.md} +0 -0
- /package/{SPATIAL_TREE_SEMANTICS.md.meta → Docs/SPATIAL_TREE_SEMANTICS.md.meta} +0 -0
- /package/{THIRD_PARTY_NOTICES.md.meta → Docs/THIRD_PARTY_NOTICES.md.meta} +0 -0
|
@@ -265,7 +265,7 @@ namespace WallstopStudios.UnityHelpers.Tests.Performance
|
|
|
265
265
|
BenchmarkReadmeUpdater.UpdateSection(
|
|
266
266
|
"SPATIAL_TREE_3D_BENCHMARKS",
|
|
267
267
|
finalReadmeLines,
|
|
268
|
-
"SPATIAL_TREE_3D_PERFORMANCE.md"
|
|
268
|
+
"Docs/SPATIAL_TREE_3D_PERFORMANCE.md"
|
|
269
269
|
);
|
|
270
270
|
|
|
271
271
|
yield break;
|
|
@@ -389,6 +389,9 @@ namespace WallstopStudios.UnityHelpers.Tests.Performance
|
|
|
389
389
|
return lines;
|
|
390
390
|
}
|
|
391
391
|
|
|
392
|
+
// Add an intermediate heading so tab headers (####) increment correctly from h3.
|
|
393
|
+
lines.Add("### Datasets");
|
|
394
|
+
lines.Add(string.Empty);
|
|
392
395
|
lines.Add("<!-- tabs:start -->");
|
|
393
396
|
lines.Add(string.Empty);
|
|
394
397
|
foreach ((DatasetSpec dataset, List<string> datasetLines) in datasetOutputs)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
namespace WallstopStudios.UnityHelpers.Tests.Serialization
|
|
2
|
+
{
|
|
3
|
+
using System.Text.Json;
|
|
4
|
+
using NUnit.Framework;
|
|
5
|
+
using UnityEngine;
|
|
6
|
+
using WallstopStudios.UnityHelpers.Core.Serialization;
|
|
7
|
+
using WallstopStudios.UnityHelpers.Tests.TestUtils;
|
|
8
|
+
|
|
9
|
+
public sealed class JsonConverterAdditionalTests : CommonTestBase
|
|
10
|
+
{
|
|
11
|
+
[Test]
|
|
12
|
+
public void GameObjectConverterWritesStructuredJson()
|
|
13
|
+
{
|
|
14
|
+
GameObject go = Track(new GameObject("ConverterTestObject"));
|
|
15
|
+
int expectedId = go.GetInstanceID();
|
|
16
|
+
string json = Serializer.JsonStringify(go);
|
|
17
|
+
Assert.IsFalse(string.IsNullOrWhiteSpace(json));
|
|
18
|
+
|
|
19
|
+
using JsonDocument doc = JsonDocument.Parse(json);
|
|
20
|
+
JsonElement root = doc.RootElement;
|
|
21
|
+
Assert.AreEqual(JsonValueKind.Object, root.ValueKind);
|
|
22
|
+
Assert.True(root.TryGetProperty("name", out JsonElement name));
|
|
23
|
+
Assert.True(root.TryGetProperty("type", out JsonElement type));
|
|
24
|
+
Assert.True(root.TryGetProperty("instanceId", out JsonElement id));
|
|
25
|
+
Assert.AreEqual("ConverterTestObject", name.GetString());
|
|
26
|
+
StringAssert.Contains("UnityEngine.GameObject", type.GetString());
|
|
27
|
+
Assert.AreEqual(expectedId, id.GetInt32());
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -7,9 +7,10 @@ namespace WallstopStudios.UnityHelpers.Tests.Serialization
|
|
|
7
7
|
using UnityEngine.Rendering;
|
|
8
8
|
using UnityEngine.SceneManagement;
|
|
9
9
|
using WallstopStudios.UnityHelpers.Core.Serialization;
|
|
10
|
+
using WallstopStudios.UnityHelpers.Tests.TestUtils;
|
|
10
11
|
|
|
11
12
|
[TestFixture]
|
|
12
|
-
public sealed class JsonConverterTests
|
|
13
|
+
public sealed class JsonConverterTests : CommonTestBase
|
|
13
14
|
{
|
|
14
15
|
[Test]
|
|
15
16
|
public void QuaternionConverterSerializeAndDeserializeSuccess()
|
|
@@ -757,14 +758,12 @@ namespace WallstopStudios.UnityHelpers.Tests.Serialization
|
|
|
757
758
|
[Test]
|
|
758
759
|
public void GameObjectConverterSerializeValidGameObjectSuccess()
|
|
759
760
|
{
|
|
760
|
-
GameObject original = new("TestObject");
|
|
761
|
+
GameObject original = Track(new GameObject("TestObject"));
|
|
761
762
|
string json = Serializer.JsonStringify(original);
|
|
762
763
|
|
|
763
764
|
Assert.IsFalse(string.IsNullOrWhiteSpace(json));
|
|
764
765
|
Assert.IsTrue(json.Contains("TestObject"));
|
|
765
766
|
Assert.IsTrue(json.Contains("UnityEngine.GameObject"));
|
|
766
|
-
|
|
767
|
-
UnityEngine.Object.DestroyImmediate(original);
|
|
768
767
|
}
|
|
769
768
|
|
|
770
769
|
[Test]
|
|
@@ -779,7 +778,7 @@ namespace WallstopStudios.UnityHelpers.Tests.Serialization
|
|
|
779
778
|
[Test]
|
|
780
779
|
public void GameObjectConverterSerializeDestroyedGameObjectReturnsEmptyObject()
|
|
781
780
|
{
|
|
782
|
-
GameObject original = new("TestObject");
|
|
781
|
+
GameObject original = Track(new GameObject("TestObject"));
|
|
783
782
|
UnityEngine.Object.DestroyImmediate(original);
|
|
784
783
|
|
|
785
784
|
string json = Serializer.JsonStringify(original);
|
|
@@ -1088,10 +1087,9 @@ namespace WallstopStudios.UnityHelpers.Tests.Serialization
|
|
|
1088
1087
|
[Test]
|
|
1089
1088
|
public void BoundingSphereConverterSerializeAndDeserializeSuccess()
|
|
1090
1089
|
{
|
|
1091
|
-
|
|
1090
|
+
BoundingSphere original = new(new Vector3(1, 2, 3), 4f);
|
|
1092
1091
|
string json = Serializer.JsonStringify(original);
|
|
1093
|
-
|
|
1094
|
-
Serializer.JsonDeserialize<UnityEngine.BoundingSphere>(json);
|
|
1092
|
+
BoundingSphere deserialized = Serializer.JsonDeserialize<BoundingSphere>(json);
|
|
1095
1093
|
Assert.AreEqual(original.position, deserialized.position);
|
|
1096
1094
|
Assert.AreEqual(original.radius, deserialized.radius);
|
|
1097
1095
|
}
|
|
@@ -1120,11 +1118,9 @@ namespace WallstopStudios.UnityHelpers.Tests.Serialization
|
|
|
1120
1118
|
[Test]
|
|
1121
1119
|
public void SceneConverterSerializeAndDeserializeSuccess()
|
|
1122
1120
|
{
|
|
1123
|
-
Scene scene =
|
|
1121
|
+
Scene scene = SceneManager.GetActiveScene();
|
|
1124
1122
|
string json = Serializer.JsonStringify(scene);
|
|
1125
|
-
Scene deserialized = Serializer.JsonDeserialize<
|
|
1126
|
-
json
|
|
1127
|
-
);
|
|
1123
|
+
Scene deserialized = Serializer.JsonDeserialize<Scene>(json);
|
|
1128
1124
|
Assert.IsTrue(deserialized.IsValid());
|
|
1129
1125
|
Assert.AreEqual(scene.name, deserialized.name);
|
|
1130
1126
|
}
|
|
@@ -31,14 +31,9 @@ namespace WallstopStudios.UnityHelpers.Tests.Serialization
|
|
|
31
31
|
[Test]
|
|
32
32
|
public void AdaptersCollectionsRoundTrip()
|
|
33
33
|
{
|
|
34
|
-
List<FastVector3Int> list = new
|
|
35
|
-
{
|
|
36
|
-
new(1, 2, 3),
|
|
37
|
-
new(-4, 5, -6),
|
|
38
|
-
new(7, 0, -1),
|
|
39
|
-
};
|
|
34
|
+
List<FastVector3Int> list = new() { new(1, 2, 3), new(-4, 5, -6), new(7, 0, -1) };
|
|
40
35
|
|
|
41
|
-
Dictionary<string, FastVector2Int> map = new
|
|
36
|
+
Dictionary<string, FastVector2Int> map = new()
|
|
42
37
|
{
|
|
43
38
|
["a"] = new(9, -9),
|
|
44
39
|
["b"] = new(0, 1),
|
|
@@ -76,7 +71,7 @@ namespace WallstopStudios.UnityHelpers.Tests.Serialization
|
|
|
76
71
|
[Test]
|
|
77
72
|
public void CompositePayloadRoundTrips()
|
|
78
73
|
{
|
|
79
|
-
CompositePayload payload = new
|
|
74
|
+
CompositePayload payload = new()
|
|
80
75
|
{
|
|
81
76
|
fv2 = new FastVector2Int(-3, 7),
|
|
82
77
|
fv3 = new FastVector3Int(1, -2, 3),
|
|
@@ -147,7 +142,7 @@ namespace WallstopStudios.UnityHelpers.Tests.Serialization
|
|
|
147
142
|
[Test]
|
|
148
143
|
public void CompositePayloadRoundTripsWithFastOptions()
|
|
149
144
|
{
|
|
150
|
-
CompositePayload payload = new
|
|
145
|
+
CompositePayload payload = new()
|
|
151
146
|
{
|
|
152
147
|
fv2 = new FastVector2Int(9, -4),
|
|
153
148
|
fv3 = new FastVector3Int(5, 6, -7),
|
|
@@ -34,15 +34,24 @@ namespace WallstopStudios.UnityHelpers.Tests.Serialization
|
|
|
34
34
|
public void UnityEngineObjectSerializationWorks()
|
|
35
35
|
{
|
|
36
36
|
GameObject testGo = new("Test GameObject", typeof(SpriteRenderer));
|
|
37
|
+
int expectedId = testGo.GetInstanceID();
|
|
37
38
|
string json = testGo.ToJson();
|
|
38
39
|
Assert.IsFalse(string.IsNullOrWhiteSpace(json), json);
|
|
39
40
|
Assert.AreNotEqual("{}", json);
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
|
|
42
|
+
using System.Text.Json.JsonDocument doc = System.Text.Json.JsonDocument.Parse(json);
|
|
43
|
+
System.Text.Json.JsonElement root = doc.RootElement;
|
|
44
|
+
Assert.AreEqual(System.Text.Json.JsonValueKind.Object, root.ValueKind);
|
|
45
|
+
Assert.True(root.TryGetProperty("name", out var name));
|
|
46
|
+
Assert.True(root.TryGetProperty("type", out var type));
|
|
47
|
+
Assert.True(root.TryGetProperty("instanceId", out var id));
|
|
48
|
+
Assert.AreEqual("Test GameObject", name.GetString());
|
|
49
|
+
StringAssert.Contains("UnityEngine.GameObject", type.GetString());
|
|
50
|
+
Assert.AreEqual(expectedId, id.GetInt32());
|
|
42
51
|
}
|
|
43
52
|
|
|
44
|
-
[
|
|
45
|
-
public
|
|
53
|
+
[UnityEngine.TestTools.UnityTest]
|
|
54
|
+
public System.Collections.IEnumerator NullGameObjectSerializationWorks()
|
|
46
55
|
{
|
|
47
56
|
GameObject testGo = null;
|
|
48
57
|
string json = testGo.ToJson();
|
|
@@ -50,7 +59,9 @@ namespace WallstopStudios.UnityHelpers.Tests.Serialization
|
|
|
50
59
|
|
|
51
60
|
testGo = new GameObject();
|
|
52
61
|
testGo.Destroy();
|
|
53
|
-
|
|
62
|
+
yield return null; // allow Unity to nullify destroyed object
|
|
63
|
+
Assert.IsTrue(testGo == null);
|
|
64
|
+
json = testGo.ToJson();
|
|
54
65
|
Assert.AreEqual("null", json);
|
|
55
66
|
}
|
|
56
67
|
|
|
@@ -38,7 +38,7 @@ namespace WallstopStudios.UnityHelpers.Tests.Serialization
|
|
|
38
38
|
[Test]
|
|
39
39
|
public void Vector2RoundTrip()
|
|
40
40
|
{
|
|
41
|
-
Vector2 v = new
|
|
41
|
+
Vector2 v = new(1.5f, -2.25f);
|
|
42
42
|
Vector2 again = RoundTrip(v);
|
|
43
43
|
Assert.AreEqual(v.x, again.x, 0f, "Vector2 x should match");
|
|
44
44
|
Assert.AreEqual(v.y, again.y, 0f, "Vector2 y should match");
|
|
@@ -47,7 +47,7 @@ namespace WallstopStudios.UnityHelpers.Tests.Serialization
|
|
|
47
47
|
[Test]
|
|
48
48
|
public void Vector3RoundTrip()
|
|
49
49
|
{
|
|
50
|
-
Vector3 v = new
|
|
50
|
+
Vector3 v = new(-1.5f, 2.75f, 3.25f);
|
|
51
51
|
Vector3 again = RoundTrip(v);
|
|
52
52
|
Assert.AreEqual(v.x, again.x, 0f, "Vector3 x should match");
|
|
53
53
|
Assert.AreEqual(v.y, again.y, 0f, "Vector3 y should match");
|
|
@@ -57,12 +57,12 @@ namespace WallstopStudios.UnityHelpers.Tests.Serialization
|
|
|
57
57
|
[Test]
|
|
58
58
|
public void Vector2IntAndVector3IntRoundTrip()
|
|
59
59
|
{
|
|
60
|
-
Vector2Int v2i = new
|
|
60
|
+
Vector2Int v2i = new(int.MinValue + 1, int.MaxValue - 1);
|
|
61
61
|
Vector2Int v2iAgain = RoundTrip(v2i);
|
|
62
62
|
Assert.AreEqual(v2i.x, v2iAgain.x, "Vector2Int x should match");
|
|
63
63
|
Assert.AreEqual(v2i.y, v2iAgain.y, "Vector2Int y should match");
|
|
64
64
|
|
|
65
|
-
Vector3Int v3i = new
|
|
65
|
+
Vector3Int v3i = new(1, -2, 3);
|
|
66
66
|
Vector3Int v3iAgain = RoundTrip(v3i);
|
|
67
67
|
Assert.AreEqual(v3i.x, v3iAgain.x, "Vector3Int x should match");
|
|
68
68
|
Assert.AreEqual(v3i.y, v3iAgain.y, "Vector3Int y should match");
|
|
@@ -72,7 +72,7 @@ namespace WallstopStudios.UnityHelpers.Tests.Serialization
|
|
|
72
72
|
[Test]
|
|
73
73
|
public void QuaternionRoundTrip()
|
|
74
74
|
{
|
|
75
|
-
Quaternion q = new
|
|
75
|
+
Quaternion q = new(0.1f, 0.2f, 0.3f, 0.9f);
|
|
76
76
|
Quaternion again = RoundTrip(q);
|
|
77
77
|
Assert.AreEqual(q.x, again.x, 0f, "Quaternion x should match");
|
|
78
78
|
Assert.AreEqual(q.y, again.y, 0f, "Quaternion y should match");
|
|
@@ -83,14 +83,14 @@ namespace WallstopStudios.UnityHelpers.Tests.Serialization
|
|
|
83
83
|
[Test]
|
|
84
84
|
public void ColorAndColor32RoundTrip()
|
|
85
85
|
{
|
|
86
|
-
Color c = new
|
|
86
|
+
Color c = new(0.1f, 0.2f, 0.3f, 0.4f);
|
|
87
87
|
Color cAgain = RoundTrip(c);
|
|
88
88
|
Assert.AreEqual(c.r, cAgain.r, 0f, "Color r should match");
|
|
89
89
|
Assert.AreEqual(c.g, cAgain.g, 0f, "Color g should match");
|
|
90
90
|
Assert.AreEqual(c.b, cAgain.b, 0f, "Color b should match");
|
|
91
91
|
Assert.AreEqual(c.a, cAgain.a, 0f, "Color a should match");
|
|
92
92
|
|
|
93
|
-
Color32 c32 = new
|
|
93
|
+
Color32 c32 = new(10, 20, 30, 40);
|
|
94
94
|
Color32 c32Again = RoundTrip(c32);
|
|
95
95
|
Assert.AreEqual(c32.r, c32Again.r, "Color32 r should match");
|
|
96
96
|
Assert.AreEqual(c32.g, c32Again.g, "Color32 g should match");
|
|
@@ -113,11 +113,11 @@ namespace WallstopStudios.UnityHelpers.Tests.Serialization
|
|
|
113
113
|
[Test]
|
|
114
114
|
public void RectAndRectIntRoundTrip()
|
|
115
115
|
{
|
|
116
|
-
Rect r = new
|
|
116
|
+
Rect r = new(1.5f, 2.5f, 10f, 20f);
|
|
117
117
|
Rect rAgain = RoundTrip(r);
|
|
118
118
|
Assert.AreEqual(r, rAgain, "Rect should round-trip by value");
|
|
119
119
|
|
|
120
|
-
RectInt ri = new
|
|
120
|
+
RectInt ri = new(1, 2, 3, 4);
|
|
121
121
|
RectInt riAgain = RoundTrip(ri);
|
|
122
122
|
Assert.AreEqual(ri, riAgain, "RectInt should round-trip by value");
|
|
123
123
|
}
|
|
@@ -125,12 +125,12 @@ namespace WallstopStudios.UnityHelpers.Tests.Serialization
|
|
|
125
125
|
[Test]
|
|
126
126
|
public void BoundsAndBoundsIntRoundTrip()
|
|
127
127
|
{
|
|
128
|
-
Bounds b = new
|
|
128
|
+
Bounds b = new(new Vector3(1, 2, 3), new Vector3(4, 5, 6));
|
|
129
129
|
Bounds bAgain = RoundTrip(b);
|
|
130
130
|
Assert.AreEqual(b.center, bAgain.center, "Bounds center should round-trip");
|
|
131
131
|
Assert.AreEqual(b.size, bAgain.size, "Bounds size should round-trip");
|
|
132
132
|
|
|
133
|
-
BoundsInt bi = new
|
|
133
|
+
BoundsInt bi = new(new Vector3Int(1, 2, 3), new Vector3Int(4, 5, 6));
|
|
134
134
|
BoundsInt biAgain = RoundTrip(bi);
|
|
135
135
|
Assert.AreEqual(bi.position, biAgain.position, "BoundsInt position should round-trip");
|
|
136
136
|
Assert.AreEqual(bi.size, biAgain.size, "BoundsInt size should round-trip");
|
|
@@ -139,7 +139,7 @@ namespace WallstopStudios.UnityHelpers.Tests.Serialization
|
|
|
139
139
|
[Test]
|
|
140
140
|
public void ResolutionRoundTrip()
|
|
141
141
|
{
|
|
142
|
-
Resolution r = new
|
|
142
|
+
Resolution r = new() { width = 800, height = 600 };
|
|
143
143
|
Resolution rAgain = RoundTrip(r);
|
|
144
144
|
Assert.AreEqual(r.width, rAgain.width, "Resolution width should round-trip");
|
|
145
145
|
Assert.AreEqual(r.height, rAgain.height, "Resolution height should round-trip");
|
|
@@ -219,7 +219,7 @@ namespace WallstopStudios.UnityHelpers.Tests.Serialization
|
|
|
219
219
|
[Test]
|
|
220
220
|
public void CompositePayloadWithCollectionsRoundTrips()
|
|
221
221
|
{
|
|
222
|
-
Composite payload = new
|
|
222
|
+
Composite payload = new()
|
|
223
223
|
{
|
|
224
224
|
fv2 = new FastVector2Int(-3, 7),
|
|
225
225
|
fv3 = new FastVector3Int(1, -2, 3),
|
|
@@ -259,14 +259,18 @@ namespace WallstopStudios.UnityHelpers.Tests.Serialization
|
|
|
259
259
|
Values = new List<int> { 1 },
|
|
260
260
|
};
|
|
261
261
|
|
|
262
|
+
#pragma warning disable CS0618 // Type or member is obsolete
|
|
262
263
|
byte[] result = Serializer.Serialize(msg, SerializationType.SystemBinary);
|
|
264
|
+
#pragma warning restore CS0618 // Type or member is obsolete
|
|
263
265
|
|
|
264
266
|
Assert.NotNull(result);
|
|
265
267
|
Assert.Greater(result.Length, 0);
|
|
266
268
|
|
|
267
269
|
TestMessage deserialized = Serializer.Deserialize<TestMessage>(
|
|
268
270
|
result,
|
|
271
|
+
#pragma warning disable CS0618 // Type or member is obsolete
|
|
269
272
|
SerializationType.SystemBinary
|
|
273
|
+
#pragma warning restore CS0618 // Type or member is obsolete
|
|
270
274
|
);
|
|
271
275
|
Assert.AreEqual(msg.Id, deserialized.Id);
|
|
272
276
|
Assert.AreEqual(msg.Name, deserialized.Name);
|
|
@@ -368,7 +372,9 @@ namespace WallstopStudios.UnityHelpers.Tests.Serialization
|
|
|
368
372
|
TestMessage msg = new() { Id = 111, Name = "BufferBinary" };
|
|
369
373
|
byte[] buffer = null;
|
|
370
374
|
|
|
375
|
+
#pragma warning disable CS0618 // Type or member is obsolete
|
|
371
376
|
int length = Serializer.Serialize(msg, SerializationType.SystemBinary, ref buffer);
|
|
377
|
+
#pragma warning restore CS0618 // Type or member is obsolete
|
|
372
378
|
|
|
373
379
|
Assert.Greater(length, 0);
|
|
374
380
|
Assert.NotNull(buffer);
|
|
@@ -377,7 +383,9 @@ namespace WallstopStudios.UnityHelpers.Tests.Serialization
|
|
|
377
383
|
byte[] data = buffer.Take(length).ToArray();
|
|
378
384
|
TestMessage deserialized = Serializer.Deserialize<TestMessage>(
|
|
379
385
|
data,
|
|
386
|
+
#pragma warning disable CS0618 // Type or member is obsolete
|
|
380
387
|
SerializationType.SystemBinary
|
|
388
|
+
#pragma warning restore CS0618 // Type or member is obsolete
|
|
381
389
|
);
|
|
382
390
|
Assert.AreEqual(msg.Id, deserialized.Id);
|
|
383
391
|
}
|
|
@@ -444,7 +452,9 @@ namespace WallstopStudios.UnityHelpers.Tests.Serialization
|
|
|
444
452
|
foreach (
|
|
445
453
|
SerializationType type in new[]
|
|
446
454
|
{
|
|
455
|
+
#pragma warning disable CS0618 // Type or member is obsolete
|
|
447
456
|
SerializationType.SystemBinary,
|
|
457
|
+
#pragma warning restore CS0618 // Type or member is obsolete
|
|
448
458
|
SerializationType.Protobuf,
|
|
449
459
|
SerializationType.Json,
|
|
450
460
|
}
|
|
@@ -867,7 +877,9 @@ namespace WallstopStudios.UnityHelpers.Tests.Serialization
|
|
|
867
877
|
foreach (
|
|
868
878
|
SerializationType type in new[]
|
|
869
879
|
{
|
|
880
|
+
#pragma warning disable CS0618 // Type or member is obsolete
|
|
870
881
|
SerializationType.SystemBinary,
|
|
882
|
+
#pragma warning restore CS0618 // Type or member is obsolete
|
|
871
883
|
SerializationType.Protobuf,
|
|
872
884
|
}
|
|
873
885
|
)
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
namespace WallstopStudios.UnityHelpers.Tests.Serialization
|
|
2
|
+
{
|
|
3
|
+
using System.IO;
|
|
4
|
+
using System.Threading;
|
|
5
|
+
using System.Threading.Tasks;
|
|
6
|
+
using NUnit.Framework;
|
|
7
|
+
using UnityEngine;
|
|
8
|
+
using WallstopStudios.UnityHelpers.Core.Serialization;
|
|
9
|
+
using WallstopStudios.UnityHelpers.Tests.TestUtils;
|
|
10
|
+
|
|
11
|
+
public sealed class SerializerFileIoTests : CommonTestBase
|
|
12
|
+
{
|
|
13
|
+
private string _dir;
|
|
14
|
+
|
|
15
|
+
[SetUp]
|
|
16
|
+
public void SetUp()
|
|
17
|
+
{
|
|
18
|
+
_dir = Path.Combine(Application.persistentDataPath, "SerializerFileIoTests");
|
|
19
|
+
if (Directory.Exists(_dir))
|
|
20
|
+
{
|
|
21
|
+
Directory.Delete(_dir, recursive: true);
|
|
22
|
+
}
|
|
23
|
+
Directory.CreateDirectory(_dir);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
[TearDown]
|
|
27
|
+
public override void TearDown()
|
|
28
|
+
{
|
|
29
|
+
try
|
|
30
|
+
{
|
|
31
|
+
if (Directory.Exists(_dir))
|
|
32
|
+
{
|
|
33
|
+
Directory.Delete(_dir, recursive: true);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
catch { }
|
|
37
|
+
base.TearDown();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private sealed class Sample
|
|
41
|
+
{
|
|
42
|
+
public int a;
|
|
43
|
+
public string b;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
[Test]
|
|
47
|
+
public void TryWriteAndTryReadRoundTrip()
|
|
48
|
+
{
|
|
49
|
+
string path = Path.Combine(_dir, "sample.json");
|
|
50
|
+
Sample s = new() { a = 7, b = "test" };
|
|
51
|
+
|
|
52
|
+
bool wrote = Serializer.TryWriteToJsonFile(s, path, pretty: true);
|
|
53
|
+
Assert.IsTrue(wrote, "Expected TryWriteToJsonFile to succeed.");
|
|
54
|
+
Assert.IsTrue(File.Exists(path), "Expected file to be created.");
|
|
55
|
+
|
|
56
|
+
bool read = Serializer.TryReadFromJsonFile(path, out Sample loaded);
|
|
57
|
+
Assert.IsTrue(read, "Expected TryReadFromJsonFile to succeed.");
|
|
58
|
+
Assert.NotNull(loaded);
|
|
59
|
+
Assert.AreEqual(7, loaded.a);
|
|
60
|
+
Assert.AreEqual("test", loaded.b);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
[Test]
|
|
64
|
+
public void TryReadReturnsFalseWhenMissing()
|
|
65
|
+
{
|
|
66
|
+
string path = Path.Combine(_dir, "does_not_exist.json");
|
|
67
|
+
bool read = Serializer.TryReadFromJsonFile(path, out Sample loaded);
|
|
68
|
+
Assert.IsFalse(read);
|
|
69
|
+
Assert.IsNull(loaded);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
[Test]
|
|
73
|
+
public void ReadAsyncHonorsCancellation()
|
|
74
|
+
{
|
|
75
|
+
string path = Path.Combine(_dir, "big.json");
|
|
76
|
+
// Create a moderately large file
|
|
77
|
+
File.WriteAllText(path, new string('x', 200_000));
|
|
78
|
+
|
|
79
|
+
using CancellationTokenSource cts = new();
|
|
80
|
+
cts.Cancel();
|
|
81
|
+
Assert.Throws<TaskCanceledException>(() =>
|
|
82
|
+
Serializer
|
|
83
|
+
.ReadFromJsonFileAsync<Sample>(path, cts.Token)
|
|
84
|
+
.ConfigureAwait(false)
|
|
85
|
+
.GetAwaiter()
|
|
86
|
+
.GetResult()
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
[Test]
|
|
91
|
+
public void WriteAsyncHonorsCancellation()
|
|
92
|
+
{
|
|
93
|
+
string path = Path.Combine(_dir, "out.json");
|
|
94
|
+
using CancellationTokenSource cts = new();
|
|
95
|
+
cts.Cancel();
|
|
96
|
+
Assert.Throws<TaskCanceledException>(() =>
|
|
97
|
+
Serializer
|
|
98
|
+
.WriteToJsonFileAsync(new Sample { a = 1, b = "x" }, path, true, cts.Token)
|
|
99
|
+
.ConfigureAwait(false)
|
|
100
|
+
.GetAwaiter()
|
|
101
|
+
.GetResult()
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|