diff --git a/.version/PipelineAssemblyInfo.cs b/.version/PipelineAssemblyInfo.cs index ce9e1a4d..f5cc4c28 100644 --- a/.version/PipelineAssemblyInfo.cs +++ b/.version/PipelineAssemblyInfo.cs @@ -3,8 +3,6 @@ // This is pipeline generated file. Do not modify. This will be replaced with the actual versions in the actual Pipeline. using System.Reflection; -using System.Runtime.CompilerServices; [assembly: AssemblyVersion("0.0.0.0")] [assembly: AssemblyFileVersion("0.0.0.0")] -[assembly: AssemblyInformationalVersion("0.0.0.0-dev-00000000")] -[assembly: InternalsVisibleTo("Persistence.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] \ No newline at end of file +[assembly: AssemblyInformationalVersion("0.0.0.0-dev-00000000")] \ No newline at end of file diff --git a/src/Persistence.Tests/TestBase.cs b/src/Persistence.Tests/TestBase.cs index ecad3a63..8f65a672 100644 --- a/src/Persistence.Tests/TestBase.cs +++ b/src/Persistence.Tests/TestBase.cs @@ -7,6 +7,7 @@ using Microsoft.PowerPlatform.PowerApps.Persistence.MsApp; using Microsoft.PowerPlatform.PowerApps.Persistence.Templates; using Microsoft.PowerPlatform.PowerApps.Persistence.Yaml; +using Microsoft.PowerPlatform.PowerApps.Persistence.YamlValidator; namespace Persistence.Tests; @@ -20,6 +21,8 @@ public abstract class TestBase : VSTestBase public IControlFactory ControlFactory { get; private set; } + public IValidatorFactory ValidatorFactory { get; private set; } + static TestBase() { ServiceProvider = BuildServiceProvider(); @@ -31,6 +34,7 @@ public TestBase() ControlTemplateStore = ServiceProvider.GetRequiredService(); MsappArchiveFactory = ServiceProvider.GetRequiredService(); ControlFactory = ServiceProvider.GetRequiredService(); + ValidatorFactory = ServiceProvider.GetRequiredService(); } private static ServiceProvider BuildServiceProvider() @@ -44,6 +48,7 @@ private static ServiceProvider BuildServiceProvider() private static ServiceProvider ConfigureServices(IServiceCollection services) { services.AddPowerAppsPersistence(useDefaultTemplates: true); + services.AddPowerAppsPersistenceYamlValidator(); return services.BuildServiceProvider(); } diff --git a/src/Persistence.Tests/YamlValidator/ValidatorFactoryTest.cs b/src/Persistence.Tests/YamlValidator/ValidatorFactoryTest.cs index cb0d8d77..ef35347a 100644 --- a/src/Persistence.Tests/YamlValidator/ValidatorFactoryTest.cs +++ b/src/Persistence.Tests/YamlValidator/ValidatorFactoryTest.cs @@ -6,13 +6,13 @@ namespace Persistence.Tests.YamlValidator; [TestClass] -public class ValidatorFactoryTest +public class ValidatorFactoryTest : TestBase { [TestMethod] public void GetValidatorTest() { var factory = new ValidatorFactory(); - var validator = factory.GetValidator(); + var validator = factory.CreateValidator(); Assert.IsNotNull(validator); Assert.IsInstanceOfType(validator, typeof(IValidator)); diff --git a/src/Persistence.Tests/YamlValidator/ValidatorTest.cs b/src/Persistence.Tests/YamlValidator/ValidatorTest.cs index e12dfd51..94ab9087 100644 --- a/src/Persistence.Tests/YamlValidator/ValidatorTest.cs +++ b/src/Persistence.Tests/YamlValidator/ValidatorTest.cs @@ -6,7 +6,7 @@ namespace Persistence.Tests.YamlValidator; [TestClass] -public class ValidatorTest +public class ValidatorTest : TestBase { private static readonly string _validPath = Path.Combine(".", "_TestData", "ValidatorTests", "ValidYaml") + @@ -19,8 +19,7 @@ public class ValidatorTest public ValidatorTest() { - var validatorFactory = new ValidatorFactory(); - _yamlValidator = validatorFactory.GetValidator(); + _yamlValidator = ValidatorFactory.CreateValidator(); } [TestMethod] diff --git a/src/Persistence/Extensions/ServiceCollectionExtensions.cs b/src/Persistence/Extensions/ServiceCollectionExtensions.cs index 0114e6e9..771a4615 100644 --- a/src/Persistence/Extensions/ServiceCollectionExtensions.cs +++ b/src/Persistence/Extensions/ServiceCollectionExtensions.cs @@ -4,6 +4,7 @@ using Microsoft.PowerPlatform.PowerApps.Persistence.MsApp; using Microsoft.PowerPlatform.PowerApps.Persistence.Templates; using Microsoft.PowerPlatform.PowerApps.Persistence.Yaml; +using Microsoft.PowerPlatform.PowerApps.Persistence.YamlValidator; namespace Microsoft.PowerPlatform.PowerApps.Persistence.Extensions; @@ -35,6 +36,11 @@ public static void AddPowerAppsPersistence(this IServiceCollection services, boo }); } + public static void AddPowerAppsPersistenceYamlValidator(this IServiceCollection services) + { + services.AddSingleton(); + } + private static void AddMinimalTemplates(ControlTemplateStore store) { store.Add(new() { Name = "hostControl", DisplayName = "host", Id = BuiltInTemplates.Host.Id }); diff --git a/src/Persistence/InternalsVisibleTo.cs b/src/Persistence/InternalsVisibleTo.cs new file mode 100644 index 00000000..4b575c19 --- /dev/null +++ b/src/Persistence/InternalsVisibleTo.cs @@ -0,0 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Persistence.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] diff --git a/src/Persistence/YamlValidator/IValidatorFactory.cs b/src/Persistence/YamlValidator/IValidatorFactory.cs index 5f0533dc..ee8721f0 100644 --- a/src/Persistence/YamlValidator/IValidatorFactory.cs +++ b/src/Persistence/YamlValidator/IValidatorFactory.cs @@ -5,5 +5,5 @@ namespace Microsoft.PowerPlatform.PowerApps.Persistence.YamlValidator; public interface IValidatorFactory { - IValidator GetValidator(); + IValidator CreateValidator(); } diff --git a/src/Persistence/YamlValidator/SchemaLoader.cs b/src/Persistence/YamlValidator/SchemaLoader.cs index 26e3471d..e170718f 100644 --- a/src/Persistence/YamlValidator/SchemaLoader.cs +++ b/src/Persistence/YamlValidator/SchemaLoader.cs @@ -11,8 +11,7 @@ internal class SchemaLoader private const string _schemaFolderPath = "schema"; private const string _subschemaFolderPath = "subschemas"; - [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1822:Mark members as static", - Justification = "Suppress to make classes stateless")] + [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Suppress to make classes stateless")] public JsonSchema Load() { var assembly = typeof(SchemaLoader).Assembly; @@ -21,7 +20,7 @@ public JsonSchema Load() foreach (var file in assembly.GetManifestResourceNames()) { var fileStream = assembly.GetManifestResourceStream(file); - var assemblyName = Assembly.GetExecutingAssembly().GetName().Name; + var assemblyName = assembly.GetName().Name; if (fileStream == null) { throw new IOException($"Resource {file} could not found in assembly {assemblyName}"); diff --git a/src/Persistence/YamlValidator/Validator.cs b/src/Persistence/YamlValidator/Validator.cs index fce20306..e3154d2e 100644 --- a/src/Persistence/YamlValidator/Validator.cs +++ b/src/Persistence/YamlValidator/Validator.cs @@ -3,7 +3,6 @@ using Json.Schema; using Yaml2JsonNode; -using System.Text.Json; using YamlDotNet.Core; using YamlDotNet.RepresentationModel; @@ -12,15 +11,11 @@ namespace Microsoft.PowerPlatform.PowerApps.Persistence.YamlValidator; internal class Validator : IValidator { private readonly EvaluationOptions _verbosityOptions; - [System.Diagnostics.CodeAnalysis.SuppressMessage("CodeQuality", "IDE0052:Remove unread private member", - Justification = "Suppress serializing the raw validator errors into json will be useful for future use")] - private readonly JsonSerializerOptions _serializerOptions; private readonly JsonSchema _schema; - public Validator(EvaluationOptions options, JsonSerializerOptions resultSerializeOptions, JsonSchema schema) + public Validator(EvaluationOptions options, JsonSchema schema) { // to do: add verbosity flag and allow users to choose verbosity of evaluation _verbosityOptions = options; - _serializerOptions = resultSerializeOptions; _schema = schema; } public ValidatorResults Validate(string yamlFileData) diff --git a/src/Persistence/YamlValidator/ValidatorFactory.cs b/src/Persistence/YamlValidator/ValidatorFactory.cs index 86a9f2ed..d6b31307 100644 --- a/src/Persistence/YamlValidator/ValidatorFactory.cs +++ b/src/Persistence/YamlValidator/ValidatorFactory.cs @@ -2,7 +2,6 @@ // Licensed under the MIT License. using Json.Schema; -using System.Text.Json; namespace Microsoft.PowerPlatform.PowerApps.Persistence.YamlValidator; @@ -10,7 +9,7 @@ internal class ValidatorFactory : IValidatorFactory { [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Suppress to make classes stateless")] - public IValidator GetValidator() + public IValidator CreateValidator() { // register schema in from memory into global schema registry var schemaLoader = new SchemaLoader(); @@ -21,13 +20,6 @@ public IValidator GetValidator() OutputFormat = OutputFormat.List }; - // pass in serailization options for validator results object to json - // This is unused for now but can be useful for producing raw json validation results which can be consumed elsewhere - var resultSerializeOptions = new JsonSerializerOptions - { - Converters = { new EvaluationResultsJsonConverter() } - }; - - return new Validator(evalOptions, resultSerializeOptions, serializedSchema); + return new Validator(evalOptions, serializedSchema); } }