mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
* Rename Interface to Interfaces in namespaces * Rename Lib to Library in namespaces * Rename project and directory and enable fxcop * Add CA2213 suppression * Minor fixes
64 lines
2.4 KiB
C#
64 lines
2.4 KiB
C#
// Copyright (c) Microsoft Corporation
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using System;
|
|
using Microsoft.PowerToys.Settings.UI.Library;
|
|
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
|
using Microsoft.PowerToys.Settings.UI.UnitTests.Mocks;
|
|
using Microsoft.PowerToys.Settings.UnitTest;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using Moq;
|
|
using Newtonsoft.Json.Linq;
|
|
using Newtonsoft.Json.Schema;
|
|
|
|
namespace CommonLibTest
|
|
{
|
|
[TestClass]
|
|
public class BasePTModuleSettingsTest
|
|
{
|
|
// Work around for System.JSON required properties:
|
|
// https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-migrate-from-newtonsoft-how-to.
|
|
// Test also fails when the attributes are not initialized i.e they have null values.
|
|
[TestMethod]
|
|
[ObsoleteAttribute("This test method is obsolete.", true)]
|
|
public void ToJsonStringShouldReturnValidJSONOfModelWhenSuccessful()
|
|
{
|
|
//Mock Disk access
|
|
string saveContent = string.Empty;
|
|
string savePath = string.Empty;
|
|
var mockIOProvider = IIOProviderMocks.GetMockIOProviderForSaveLoadExists();
|
|
|
|
var settingsUtils = new SettingsUtils(mockIOProvider.Object);
|
|
|
|
// Arrange
|
|
string file_name = "test\\BasePTModuleSettingsTest";
|
|
string expectedSchemaText = @"
|
|
{
|
|
'$schema': 'http://json-schema.org/draft-04/schema#',
|
|
'type': 'object',
|
|
'properties': {
|
|
'name': {
|
|
'type': 'string'
|
|
},
|
|
'version': {
|
|
'type': 'string'
|
|
}
|
|
},
|
|
'additionalProperties': false
|
|
}";
|
|
|
|
string testSettingsConfigs = new BasePTSettingsTest().ToJsonString();
|
|
settingsUtils.SaveSettings(testSettingsConfigs, file_name);
|
|
JsonSchema expectedSchema = JsonSchema.Parse(expectedSchemaText);
|
|
|
|
// Act
|
|
JObject actualSchema = JObject.Parse(settingsUtils.GetSettings<BasePTSettingsTest>(file_name).ToJsonString());
|
|
bool valid = actualSchema.IsValid(expectedSchema);
|
|
|
|
// Assert
|
|
Assert.IsTrue(valid);
|
|
}
|
|
}
|
|
}
|