Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Yaml Validator into Persistence Part 2 #700

Merged
merged 24 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f47376e
move Yaml Validator into persistence to setup for PAC CLI integration
abaskk-msft Jul 9, 2024
cee7faf
clean yaml validator project residue to integrate into persistence an…
abaskk-msft Jul 10, 2024
ef050cd
couple schema with schema loader
abaskk-msft Jul 11, 2024
ca58cc6
iteration two, ready for consumption by pac cli
abaskk-msft Jul 15, 2024
43dfe41
supress unused member of class
abaskk-msft Jul 15, 2024
5322752
rewrite of schema loader to store schema in dll on build and access f…
abaskk-msft Jul 17, 2024
dfb79a3
clean up new schema loader
abaskk-msft Jul 17, 2024
1d5d8c7
Merge branch 'master' into users/t-abaskar/persistence-yaml-validator…
abaskk-msft Jul 17, 2024
378656e
keep current commit head
abaskk-msft Jul 17, 2024
f773b62
add suppression suggestions
abaskk-msft Jul 17, 2024
ca1d151
access assembly from type to improve performance
abaskk-msft Jul 17, 2024
54b9b17
Interfaces for external use, make classes that interact with dependen…
abaskk-msft Jul 17, 2024
be6a1bf
Merge branch 'master' into users/t-abaskar/persistence-yaml-validator…
abaskk-msft Jul 17, 2024
e4def43
delete unused files
abaskk-msft Jul 17, 2024
82f1abb
check for validator interface instead of validator
abaskk-msft Jul 18, 2024
7a07194
make schema loader internal
abaskk-msft Jul 18, 2024
32c1de6
add factory to service provider. Create internal access for test in P…
abaskk-msft Jul 18, 2024
18b912b
remove unused directive
abaskk-msft Jul 19, 2024
caa24cb
remove unused file
abaskk-msft Jul 19, 2024
d06cf27
nit: whietspace at end of file
abaskk-msft Jul 19, 2024
1cc054c
make supressions inline
abaskk-msft Jul 19, 2024
f8f3696
move yaml-validator out with changes (persistence not compatiable wit…
abaskk-msft Jul 22, 2024
dcfea66
update project name
abaskk-msft Jul 22, 2024
b39d57c
strongly sign vailidator and make it visible to tests
abaskk-msft Jul 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/PASopa.sln
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{7361DB16-D53
Versions.props = Versions.props
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YamlValidator", "YamlValidator\Microsoft.PowerPlatform.PowerApps.YamlValidator.csproj", "{296D952B-C284-4AAB-9A79-59538CA7BF38}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YamlValidator.Tests", "YamlValidator.Tests\YamlValidator.Tests.csproj", "{E6180C81-59C1-4B25-90E0-E4390D455518}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -52,6 +56,14 @@ Global
{8AB1C901-FE5E-44BF-AA21-B8F20A9D7CDD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8AB1C901-FE5E-44BF-AA21-B8F20A9D7CDD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8AB1C901-FE5E-44BF-AA21-B8F20A9D7CDD}.Release|Any CPU.Build.0 = Release|Any CPU
{296D952B-C284-4AAB-9A79-59538CA7BF38}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{296D952B-C284-4AAB-9A79-59538CA7BF38}.Debug|Any CPU.Build.0 = Debug|Any CPU
{296D952B-C284-4AAB-9A79-59538CA7BF38}.Release|Any CPU.ActiveCfg = Release|Any CPU
{296D952B-C284-4AAB-9A79-59538CA7BF38}.Release|Any CPU.Build.0 = Release|Any CPU
{E6180C81-59C1-4B25-90E0-E4390D455518}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E6180C81-59C1-4B25-90E0-E4390D455518}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E6180C81-59C1-4B25-90E0-E4390D455518}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E6180C81-59C1-4B25-90E0-E4390D455518}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -60,6 +72,7 @@ Global
{8AD94CC0-7330-4880-A8E0-177B37CDB27B} = {4993E606-484B-46D9-892E-7AE9CE8D4423}
{8AB1C901-FE5E-44BF-AA21-B8F20A9D7CDD} = {4993E606-484B-46D9-892E-7AE9CE8D4423}
{7361DB16-D534-4E0E-8597-BE22317DEF47} = {794D8C68-BF6F-49C8-BCA5-AA52D8F45EF4}
{E6180C81-59C1-4B25-90E0-E4390D455518} = {4993E606-484B-46D9-892E-7AE9CE8D4423}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C936F8B1-DE7A-4401-95D5-5E199210F960}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<PublicSign>true</PublicSign>
<!-- Workaround for version range https://github.com/NuGet/Home/issues/11842 -->
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<NoWarn>$(NoWarn);NU1601;CA1822</NoWarn>
<NoWarn>$(NoWarn);NU1601</NoWarn>
</PropertyGroup>

<ItemGroup Label="Global usings">
Expand All @@ -43,18 +43,6 @@
<PackageReference Include="Microsoft.PowerFx.Core" Version="1.2.0" />
<PackageReference Include="YamlDotNet" Version="$(YamlDotNetVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="$(MicrosoftExtensionsLoggingVersion)" />
<PackageReference Include="JsonSchema.Net" Version="7.1.0" />
<PackageReference Include="Yaml2JsonNode" Version="2.1.0" />
</ItemGroup>

<ItemGroup>
<Content Include="..\..\docs\pa.yaml-schema.json" Link="YamlValidator\schema\pa.yaml-schema.json" CopyToOutputDirectory="PreserveNewest" />
<Content Include="..\..\docs\subschemas\control-type-schema.json" Link="YamlValidator\schema\subschemas\control-type-schema.json" CopyToOutputDirectory="PreserveNewest" />
<Content Include="..\..\docs\subschemas\control-property-schema.json" Link="YamlValidator\schema\subschemas\control-property-schema.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="Persistence.Tests" Key="0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9" />
abaskk-msft marked this conversation as resolved.
Show resolved Hide resolved
</ItemGroup>

</Project>
</Project>
18 changes: 0 additions & 18 deletions src/Persistence/YamlValidator/Constants.cs

This file was deleted.

29 changes: 0 additions & 29 deletions src/Persistence/YamlValidator/SchemaLoader.cs

This file was deleted.

40 changes: 0 additions & 40 deletions src/Persistence/YamlValidator/ValidationProcessor.cs

This file was deleted.

25 changes: 0 additions & 25 deletions src/Persistence/YamlValidator/VerbosityData.cs

This file was deleted.

49 changes: 0 additions & 49 deletions src/Persistence/YamlValidator/YamlLoader.cs

This file was deleted.

38 changes: 38 additions & 0 deletions src/YamlValidator.Tests/TestBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using Microsoft.PowerPlatform.PowerApps.Persistence.YamlValidator;


namespace Persistence.YamlValidator.Tests;
public abstract class TestBase : VSTestBase
{
public static IServiceProvider ServiceProvider { get; set; }
public IValidatorFactory ValidatorFactory { get; private set; }

static TestBase()
{
ServiceProvider = BuildServiceProvider();
}

public TestBase()
{
ValidatorFactory = ServiceProvider.GetRequiredService<IValidatorFactory>();
}

private static ServiceProvider BuildServiceProvider()
{
var serviceCollection = new ServiceCollection();
var serviceProvider = ConfigureServices(serviceCollection);

return serviceProvider;
}

private static ServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddPowerAppsPersistenceYamlValidator();

return services.BuildServiceProvider();
}

}
16 changes: 16 additions & 0 deletions src/YamlValidator.Tests/VSTestBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace Persistence.YamlValidator.Tests;

/// <summary>
/// Represents a shared base class for any test class that uses the Visual Studio Test Framework.
/// </summary>
/// <remarks>
/// DO NOT add any setup/tear down logic to this class, as not all tests may require it.
/// The preferred approach is to use a different derived base class for tests that require setup/tear down logic specific to some shared scenarios.
/// </remarks>
public abstract class VSTestBase
{
public required TestContext TestContext { get; set; }
}
20 changes: 20 additions & 0 deletions src/YamlValidator.Tests/ValidatorFactoryTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using Microsoft.PowerPlatform.PowerApps.Persistence.YamlValidator;

namespace Persistence.YamlValidator.Tests;

[TestClass]
public class ValidatorFactoryTest : TestBase
{
[TestMethod]
public void GetValidatorTest()
{
var factory = new ValidatorFactory();
var validator = factory.CreateValidator();

Assert.IsNotNull(validator);
Assert.IsInstanceOfType(validator, typeof(IValidator));
}
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using Json.Schema;
using Microsoft.PowerPlatform.PowerApps.Persistence.YamlValidator;

namespace Persistence.Tests.YamlValidator;
namespace Persistence.YamlValidator.Tests;

[TestClass]
public class ValidatorTest
public class ValidatorTest : TestBase
{

private static readonly string _validPath = Path.Combine(".", "_TestData", "ValidatorTests", "ValidYaml") +
private static readonly string _validPath = Path.Combine(".", "_TestData", "ValidYaml") +
Path.DirectorySeparatorChar;

private static readonly string _invalidPath = Path.Combine(".", "_TestData", "ValidatorTests", "InvalidYaml") +
private static readonly string _invalidPath = Path.Combine(".", "_TestData", "InvalidYaml") +
Path.DirectorySeparatorChar;

private readonly JsonSchema _schema;
private readonly Validator _yamlValidator;
private readonly IValidator _yamlValidator;

public ValidatorTest()
{
var schemaFileLoader = new SchemaLoader();
_schema = schemaFileLoader.Load();
var resultVerbosity = new VerbosityData(Constants.Verbose);
_yamlValidator = new Validator(resultVerbosity.EvalOptions, resultVerbosity.JsonOutputOptions);
_yamlValidator = ValidatorFactory.CreateValidator();
}

[TestMethod]
Expand All @@ -34,8 +29,8 @@ public ValidatorTest()

public void TestValidationValidYaml(string filename)
{
var rawYaml = Utility.ReadFileData($@"{_validPath}{filename}");
var result = _yamlValidator.Validate(_schema, rawYaml);
var rawYaml = File.ReadAllText($@"{_validPath}{filename}");
var result = _yamlValidator.Validate(rawYaml);
Assert.IsTrue(result.SchemaValid);
}

Expand All @@ -48,10 +43,11 @@ public void TestValidationValidYaml(string filename)
[DataRow("EmptyArray.yaml")]
[DataRow("Empty.yaml")]
[DataRow("NamelessObjectNoControl.yaml")]
[DataRow("NotYaml.yaml")]
public void TestValidationInvalidYaml(string filename)
{
var rawYaml = Utility.ReadFileData($@"{_invalidPath}{filename}");
var result = _yamlValidator.Validate(_schema, rawYaml);
var rawYaml = File.ReadAllText($@"{_invalidPath}{filename}");
var result = _yamlValidator.Validate(rawYaml);
Assert.IsFalse(result.SchemaValid);
}
}
Loading
Loading