From ba301e4b920eb2d00a00f9009e0d6d8084f71bc9 Mon Sep 17 00:00:00 2001 From: Grant Archibald <31553604+Grant-Archibald-MS@users.noreply.github.com> Date: Fri, 11 Oct 2024 18:24:55 -0700 Subject: [PATCH] Format updates --- .../TestEngineExtensionCheckerTests.cs | 7 ++-- .../Modules/TestEngineExtensionChecker.cs | 35 +++++++++---------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/Microsoft.PowerApps.TestEngine.Tests/Modules/TestEngineExtensionCheckerTests.cs b/src/Microsoft.PowerApps.TestEngine.Tests/Modules/TestEngineExtensionCheckerTests.cs index 54be1d69..ce3ad50f 100644 --- a/src/Microsoft.PowerApps.TestEngine.Tests/Modules/TestEngineExtensionCheckerTests.cs +++ b/src/Microsoft.PowerApps.TestEngine.Tests/Modules/TestEngineExtensionCheckerTests.cs @@ -106,7 +106,7 @@ public void IsValid(string usingStatements, string script, bool useTemplate, str Assert.Equal(expected, result); } - + private string _functionTemplate = @" #r ""Microsoft.PowerFx.Interpreter.dll"" using Microsoft.PowerFx; @@ -124,11 +124,12 @@ public void IsValid(string usingStatements, string script, bool useTemplate, str [InlineData("", "*", "public class FooFunction : ReflectionFunction { public FooFunction() : base(DPath.Root.Append(new DName(\"Other\")), \"Foo\", FormulaType.Blank) {} } public BlankValue Execute() { return FormulaValue.NewBlank(); }", false)] // Deny all and not in allow list [InlineData("Other", "*", "public class FooFunction : ReflectionFunction { public FooFunction() : base(DPath.Root.Append(new DName(\"Other\")), \"Foo\", FormulaType.Blank) {} } public BlankValue Execute() { return FormulaValue.NewBlank(); }", true)] // Deny all and in allow list [InlineData("", "", "public class OtherFunction : ReflectionFunction { public OtherFunction(int someNumber) : base(DPath.Root.Append(new DName(\"TestEngine\")), \"Other\", FormulaType.Blank) {} } public BlankValue Execute() { return FormulaValue.NewBlank(); }", true)] // Allow TestEngine namespace with a parameter - public void ValidPowerFxFunction(string allow, string deny, string code, bool valid) { + public void ValidPowerFxFunction(string allow, string deny, string code, bool valid) + { // Arrange var checker = new TestEngineExtensionChecker(MockLogger.Object); - var assembly = CompileScript(_functionTemplate.Replace("%CODE%",code)); + var assembly = CompileScript(_functionTemplate.Replace("%CODE%", code)); var settings = new TestSettingExtensions(); settings.AllowPowerFxNamespaces.AddRange(allow.Split(',')); diff --git a/src/Microsoft.PowerApps.TestEngine/Modules/TestEngineExtensionChecker.cs b/src/Microsoft.PowerApps.TestEngine/Modules/TestEngineExtensionChecker.cs index 23f22cf9..8673db84 100644 --- a/src/Microsoft.PowerApps.TestEngine/Modules/TestEngineExtensionChecker.cs +++ b/src/Microsoft.PowerApps.TestEngine/Modules/TestEngineExtensionChecker.cs @@ -1,25 +1,24 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. +using System.IO; +using System.Reflection; +using System.Reflection.Metadata; +using System.Reflection.PortableExecutable; using System.Security.Cryptography.X509Certificates; using System.Text; using ICSharpCode.Decompiler; +using ICSharpCode.Decompiler.CSharp; +using ICSharpCode.Decompiler.Metadata; using Microsoft.Extensions.Logging; using Microsoft.PowerApps.TestEngine.Config; using Mono.Cecil; using Mono.Cecil.Cil; using Mono.Cecil.Rocks; -using ICSharpCode.Decompiler.Metadata; -using ICSharpCode.Decompiler.CSharp; - -using System.Reflection; -using System.Reflection.PortableExecutable; -using System.Reflection.Metadata; +using MethodBody = Mono.Cecil.Cil.MethodBody; using ModuleDefinition = Mono.Cecil.ModuleDefinition; using TypeDefinition = Mono.Cecil.TypeDefinition; using TypeReference = Mono.Cecil.TypeReference; -using MethodBody = Mono.Cecil.Cil.MethodBody; -using System.IO; namespace Microsoft.PowerApps.TestEngine.Modules { @@ -243,7 +242,7 @@ public virtual bool Validate(TestSettingExtensions settings, string file) var valid = true; - if ( !VerifyContainsValidNamespacePowerFxFunctions(settings, contents) ) + if (!VerifyContainsValidNamespacePowerFxFunctions(settings, contents)) { Logger.LogInformation("Invalid Power FX Namespace"); valid = false; @@ -286,7 +285,7 @@ public bool VerifyContainsValidNamespacePowerFxFunctions(TestSettingExtensions s // Get the source code of the assembly as will be used to check Power FX Namespaces var code = DecompileModuleToCSharp(assembly); - + foreach (TypeDefinition type in module.GetAllTypes()) { if (type.BaseType != null && type.BaseType.Name == "ReflectionFunction") @@ -301,14 +300,14 @@ public bool VerifyContainsValidNamespacePowerFxFunctions(TestSettingExtensions s var constructor = constructors.First(); - if ( !constructor.HasBody ) + if (!constructor.HasBody) { Logger.LogInformation($"No body defined for {type.Name}"); // Needs body for call to base constructor return false; } - var baseCall = constructor.Body.Instructions.FirstOrDefault(i => i.OpCode == OpCodes.Call && i.Operand is MethodReference && ((MethodReference)i.Operand).Name == ".ctor" ); + var baseCall = constructor.Body.Instructions.FirstOrDefault(i => i.OpCode == OpCodes.Call && i.Operand is MethodReference && ((MethodReference)i.Operand).Name == ".ctor"); if (baseCall == null) { @@ -319,14 +318,14 @@ public bool VerifyContainsValidNamespacePowerFxFunctions(TestSettingExtensions s MethodReference baseConstructor = (MethodReference)baseCall.Operand; - if ( baseConstructor.Parameters.Count() < 2 ) + if (baseConstructor.Parameters.Count() < 2) { // Not enough parameters Logger.LogInformation($"No not enough parameters for {type.Name}"); return false; } - if (baseConstructor.Parameters[0].ParameterType.FullName != "Microsoft.PowerFx.Core.Utils.DPath" ) + if (baseConstructor.Parameters[0].ParameterType.FullName != "Microsoft.PowerFx.Core.Utils.DPath") { // First argument should be Namespace Logger.LogInformation($"No Power FX Namespace for {type.Name}"); @@ -336,7 +335,7 @@ public bool VerifyContainsValidNamespacePowerFxFunctions(TestSettingExtensions s // Use the decompiled code to get the values of the base constructor, specifically look for the namespace var name = GetPowerFxNamespace(type.Name, code); - if ( string.IsNullOrEmpty(name) ) + if (string.IsNullOrEmpty(name)) { // No Power FX Namespace found Logger.LogInformation($"No Power FX Namespace found for {type.Name}"); @@ -361,7 +360,7 @@ public bool VerifyContainsValidNamespacePowerFxFunctions(TestSettingExtensions s return false; } - if ( !settings.AllowPowerFxNamespaces.Contains(name) && name != "TestEngine" ) + if (!settings.AllowPowerFxNamespaces.Contains(name) && name != "TestEngine") { Logger.LogInformation($"Not allow Power FX Namespace {name} for {type.Name}"); // Not in allow list or the Reserved TestEngine namespace @@ -400,7 +399,7 @@ public OtherFunction(int start) var match = lines.Where(l => l.Contains($"public {name}(")).FirstOrDefault(); - if ( match == null ) + if (match == null) { return String.Empty; } @@ -413,7 +412,7 @@ public OtherFunction(int start) // Search for the DName var declaration = lines[index + 1].IndexOf(baseDeclaration); - if ( declaration >= 0 ) + if (declaration >= 0) { // Found a match var start = declaration + baseDeclaration.Length;