Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions CodeQuality.sln
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SoloX.CodeQuality.Playwrigh
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SoloX.CodeQuality.Playwright.E2ETest", "src\tests\SoloX.CodeQuality.Playwright.E2ETest\SoloX.CodeQuality.Playwright.E2ETest.csproj", "{D0CDEC61-7956-4F49-AC4D-C0DA3063969F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SoloX.CodeQuality.TestTool", "src\tests\SoloX.CodeQuality.TestTool\SoloX.CodeQuality.TestTool.csproj", "{C92C3947-9EBB-43E3-9104-58CADE937BB3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -106,6 +108,10 @@ Global
{D0CDEC61-7956-4F49-AC4D-C0DA3063969F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D0CDEC61-7956-4F49-AC4D-C0DA3063969F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D0CDEC61-7956-4F49-AC4D-C0DA3063969F}.Release|Any CPU.Build.0 = Release|Any CPU
{C92C3947-9EBB-43E3-9104-58CADE937BB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C92C3947-9EBB-43E3-9104-58CADE937BB3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C92C3947-9EBB-43E3-9104-58CADE937BB3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C92C3947-9EBB-43E3-9104-58CADE937BB3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -124,6 +130,7 @@ Global
{3507CA64-D718-427E-BA4F-40986B34F56A} = {5B172423-1455-41CB-8D81-7DCFCFF8855D}
{B339195D-10B0-471F-9401-F883B18838CE} = {5B172423-1455-41CB-8D81-7DCFCFF8855D}
{D0CDEC61-7956-4F49-AC4D-C0DA3063969F} = {1D5021C0-2423-494A-98F6-71AB937CDF8B}
{C92C3947-9EBB-43E3-9104-58CADE937BB3} = {1D5021C0-2423-494A-98F6-71AB937CDF8B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {74BCF463-5FDE-4DBC-B32A-431E8A228CA0}
Expand Down
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,26 @@ You can checkout this Github repository or you can use the NuGet package:

**Install using the command line from the Package Manager:**
```bash
Install-Package SoloX.CodeQuality.Prod -version 2.3.3
Install-Package SoloX.CodeQuality.Prod -version 2.3.4
or
Install-Package SoloX.CodeQuality.Test -version 2.3.3
Install-Package SoloX.CodeQuality.Test -version 2.3.4
```

**Install using the .Net CLI:**
```bash
dotnet add package SoloX.CodeQuality.Prod --version 2.3.3
dotnet add package SoloX.CodeQuality.Prod --version 2.3.4
or
dotnet add package SoloX.CodeQuality.Test --version 2.3.3
dotnet add package SoloX.CodeQuality.Test --version 2.3.4
```

**Install editing your project file (csproj):**
```xml
<PackageReference Include="SoloX.CodeQuality.Prod" Version="2.3.3">
<PackageReference Include="SoloX.CodeQuality.Prod" Version="2.3.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
or
<PackageReference Include="SoloX.CodeQuality.Test" Version="2.3.3">
<PackageReference Include="SoloX.CodeQuality.Test" Version="2.3.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down Expand Up @@ -218,17 +218,17 @@ You can checkout this Github repository or use the NuGet package:

**Install using the command line from the Package Manager:**
```bash
Install-Package SoloX.CodeQuality.Playwright -version 2.3.3
Install-Package SoloX.CodeQuality.Playwright -version 2.3.4
```

**Install using the .Net CLI:**
```bash
dotnet add package SoloX.CodeQuality.Playwright --version 2.3.3
dotnet add package SoloX.CodeQuality.Playwright --version 2.3.4
```

**Install editing your project file (csproj):**
```xml
<PackageReference Include="SoloX.CodeQuality.Playwright" Version="2.3.3" />
<PackageReference Include="SoloX.CodeQuality.Playwright" Version="2.3.4" />
```

* * *
Expand Down Expand Up @@ -424,29 +424,29 @@ You can checkout this Github repository or you can use the NuGet package:

**Install using the command line from the Package Manager:**
```bash
Install-Package SoloX.CodeQuality.Test.Helpers -version 2.3.3
Install-Package SoloX.CodeQuality.Test.Helpers -version 2.3.4

Install-Package SoloX.CodeQuality.Test.Helpers.XUnit -version 2.3.3
Install-Package SoloX.CodeQuality.Test.Helpers.XUnit -version 2.3.4

Install-Package SoloX.CodeQuality.Test.Helpers.NUnit -version 2.3.3
Install-Package SoloX.CodeQuality.Test.Helpers.NUnit -version 2.3.4
```

**Install using the .Net CLI:**
```bash
dotnet add package SoloX.CodeQuality.Test.Helpers --version 2.3.3
dotnet add package SoloX.CodeQuality.Test.Helpers --version 2.3.4

dotnet add package SoloX.CodeQuality.Test.Helpers.XUnit --version 2.3.3
dotnet add package SoloX.CodeQuality.Test.Helpers.XUnit --version 2.3.4

dotnet add package SoloX.CodeQuality.Test.Helpers.NUnit --version 2.3.3
dotnet add package SoloX.CodeQuality.Test.Helpers.NUnit --version 2.3.4
```

**Install editing your project file (csproj):**
```xml
<PackageReference Include="SoloX.CodeQuality.Test.Helpers" Version="2.3.3" />
<PackageReference Include="SoloX.CodeQuality.Test.Helpers" Version="2.3.4" />

<PackageReference Include="SoloX.CodeQuality.Test.Helpers.XUnit" Version="2.3.3" />
<PackageReference Include="SoloX.CodeQuality.Test.Helpers.XUnit" Version="2.3.4" />

<PackageReference Include="SoloX.CodeQuality.Test.Helpers.NUnit" Version="2.3.3" />
<PackageReference Include="SoloX.CodeQuality.Test.Helpers.NUnit" Version="2.3.4" />
```

* * *
Expand Down
4 changes: 2 additions & 2 deletions src/SharedProperties.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>

<PropertyGroup>
<Version>2.3.3</Version>
<Version>2.3.4</Version>
<Authors>Xavier Solau</Authors>
<Copyright>Copyright © 2021 Xavier Solau</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand All @@ -14,7 +14,7 @@
<CodeQualityHeaderLicense>$(PackageLicenseExpression)</CodeQualityHeaderLicense>
<CodeQualityHeaderLicenseFile>LICENSE</CodeQualityHeaderLicenseFile>

<AssemblyVersion>2.3.3.0</AssemblyVersion>
<AssemblyVersion>2.3.4.0</AssemblyVersion>
<LangVersion>12</LangVersion>

</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@

<PropertyGroup>
<OutputEditorConfigFile>$(MSBuildProjectDirectory)/.editorconfig</OutputEditorConfigFile>
<IntermediateOutputEditorConfigFile>$(MSBuildProjectDirectory)/obj/.editorconfig</IntermediateOutputEditorConfigFile>
<IntermediateOutputEditorConfigFile>$(MSBuildProjectDirectory)/obj/.editorconfig-$(TargetFramework)</IntermediateOutputEditorConfigFile>
<CsCaEditorConfigFile>$(MSBuildThisFileDirectory)../resources/style.cs.compiler.ca.editorconfig</CsCaEditorConfigFile>
<CsCsEditorConfigFile>$(MSBuildThisFileDirectory)../resources/style.cs.compiler.cs.editorconfig</CsCsEditorConfigFile>
<Ide1EditorConfigFile>$(MSBuildThisFileDirectory)../resources/style.cs.ide1.editorconfig</Ide1EditorConfigFile>
Expand Down
78 changes: 54 additions & 24 deletions src/libs/SoloX.CodeQuality.Test.Helpers/DotnetHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
// </copyright>
// ----------------------------------------------------------------------

using System.Collections.Specialized;
using System;

namespace SoloX.CodeQuality.Test.Helpers
{
#pragma warning disable CA1021 // Avoid out parameters
Expand All @@ -25,65 +28,92 @@ public static class DotnetHelper
private const string ADD = "add";
private const string PACKAGE = "package";
private const string REFERENCE = "reference ";
private const string TOOL = "tool";
private const string TOOL_MANIFEST = "tool-manifest";
private const string INSTALL = "install";

public static bool Restore(string projectPath, out ProcessResult processResult,
Action<StringDictionary>? environmentVariablesHandler = null)
{
return Dotnet(projectPath, RESTORE, out processResult, environmentVariablesHandler);
}

public static bool Build(string projectPath, out ProcessResult processResult,
Action<StringDictionary>? environmentVariablesHandler = null)
{
return Dotnet(projectPath, BUILD, out processResult, environmentVariablesHandler);
}

public static bool Restore(string projectPath, out ProcessResult processResult)
public static bool Test(string projectPath, out ProcessResult processResult,
Action<StringDictionary>? environmentVariablesHandler = null)
{
return Dotnet(projectPath, RESTORE, out processResult);
return Dotnet(projectPath, TEST, out processResult, environmentVariablesHandler);
}

public static bool Build(string projectPath, out ProcessResult processResult)
public static bool Publish(string projectPath, out ProcessResult processResult,
Action<StringDictionary>? environmentVariablesHandler = null)
{
return Dotnet(projectPath, BUILD, out processResult);
return Dotnet(projectPath, PUBLISH, out processResult, environmentVariablesHandler);
}

public static bool Test(string projectPath, out ProcessResult processResult)
public static bool New(string path, string template, string output, out ProcessResult processResult,
Action<StringDictionary>? environmentVariablesHandler = null)
{
return Dotnet(projectPath, TEST, out processResult);
return Dotnet(path, $"{NEW} {template} --output {output}", out processResult, environmentVariablesHandler);
}

public static bool Publish(string projectPath, out ProcessResult processResult)
public static bool NewSln(string path, string solutionName, out ProcessResult processResult,
Action<StringDictionary>? environmentVariablesHandler = null)
{
return Dotnet(projectPath, PUBLISH, out processResult);
return New(path, SLN, solutionName, out processResult, environmentVariablesHandler);
}

public static bool New(string path, string template, string output, out ProcessResult processResult)
public static bool SlnAdd(string path, string project, out ProcessResult processResult,
Action<StringDictionary>? environmentVariablesHandler = null)
{
return Dotnet(path, $"{NEW} {template} --output {output}", out processResult);
return Dotnet(path, $"{SLN} {ADD} {project}", out processResult, environmentVariablesHandler);
}

public static bool NewSln(string path, string solutionName, out ProcessResult processResult)
public static bool AddPackage(string path, string projectFilePath, string packageName, out ProcessResult processResult,
Action<StringDictionary>? environmentVariablesHandler = null)
{
return New(path, SLN, solutionName, out processResult);
return Dotnet(path, $"{ADD} {projectFilePath} {PACKAGE} {packageName}", out processResult, environmentVariablesHandler);
}

public static bool SlnAdd(string path, string project, out ProcessResult processResult)
public static bool AddReference(string path, string projectFilePath, string projectReferenceFilePath, out ProcessResult processResult,
Action<StringDictionary>? environmentVariablesHandler = null)
{
return Dotnet(path, $"{SLN} {ADD} {project}", out processResult);
return Dotnet(path, $"{ADD} {projectFilePath} {REFERENCE} {projectReferenceFilePath}", out processResult, environmentVariablesHandler);
}

public static bool AddPackage(string path, string projectFilePath, string packageName, out ProcessResult processResult)
public static bool Run(string projectPath, out ProcessResult processResult,
Action<StringDictionary>? environmentVariablesHandler = null)
{
return Dotnet(path, $"{ADD} {projectFilePath} {PACKAGE} {packageName}", out processResult);
return Run(projectPath, string.Empty, out processResult, environmentVariablesHandler);
}

public static bool AddReference(string path, string projectFilePath, string projectReferenceFilePath, out ProcessResult processResult)
public static bool Run(string projectPath, string args, out ProcessResult processResult,
Action<StringDictionary>? environmentVariablesHandler = null)
{
return Dotnet(path, $"{ADD} {projectFilePath} {REFERENCE} {projectReferenceFilePath}", out processResult);
return Dotnet(projectPath, $"{RUN} {args}", out processResult, environmentVariablesHandler);
}

public static bool Run(string projectPath, out ProcessResult processResult)
internal static bool NewToolManifest(string path, out ProcessResult processResult,
Action<StringDictionary>? environmentVariablesHandler = null)
{
return Run(projectPath, string.Empty, out processResult);
return Dotnet(path, $"{NEW} {TOOL_MANIFEST}", out processResult, environmentVariablesHandler);
}

public static bool Run(string projectPath, string args, out ProcessResult processResult)
internal static bool ToolInstall(string path, string toolName, out ProcessResult processResult,
Action<StringDictionary>? environmentVariablesHandler = null)
{
return Dotnet(projectPath, $"{RUN} {args}", out processResult);
return Dotnet(path, $"{TOOL} {INSTALL} {toolName}", out processResult, environmentVariablesHandler);
}

public static bool Dotnet(string path, string args, out ProcessResult processResult)
public static bool Dotnet(string path, string args, out ProcessResult processResult,
Action<StringDictionary>? environmentVariablesHandler = null)
{
processResult = ProcessHelper.Run(path, DOTNET, args);
processResult = ProcessHelper.Run(path, DOTNET, args, environmentVariablesHandler);
return processResult.ExitCode == 0;
}
}
Expand Down
30 changes: 19 additions & 11 deletions src/libs/SoloX.CodeQuality.Test.Helpers/ProcessHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Linq;
using System.Text;
Expand All @@ -28,9 +29,11 @@ public static class ProcessHelper
/// <param name="arguments">The command arguments.</param>
/// <param name="stdout">Standard output.</param>
/// <param name="stderr">Error output.</param>
/// <param name="environmentVariablesHandler">Handler to set up process environment variables.</param>
/// <returns>The process exit code.</returns>
public static int Run(string workingDirectory, string command, string arguments,
out string stdout, out string stderr)
out string stdout, out string stderr,
Action<StringDictionary>? environmentVariablesHandler = null)
{
var outBuilder = new StringBuilder();
var errBuilder = new StringBuilder();
Expand All @@ -40,7 +43,8 @@ public static int Run(string workingDirectory, string command, string arguments,
command,
arguments,
s => outBuilder.Append(s),
s => errBuilder.Append(s));
s => errBuilder.Append(s),
environmentVariablesHandler);

stderr = errBuilder.ToString();
stdout = outBuilder.ToString();
Expand All @@ -54,8 +58,10 @@ public static int Run(string workingDirectory, string command, string arguments,
/// <param name="workingDirectory">Working directory.</param>
/// <param name="command">The command to run.</param>
/// <param name="arguments">The command arguments.</param>
/// <param name="environmentVariablesHandler">Handler to set up process environment variables.</param>
/// <returns>The process result.</returns>
public static ProcessResult Run(string workingDirectory, string command, string arguments)
public static ProcessResult Run(string workingDirectory, string command, string arguments,
Action<StringDictionary>? environmentVariablesHandler = null)
{
var processResult = new ProcessResult();

Expand All @@ -64,15 +70,17 @@ public static ProcessResult Run(string workingDirectory, string command, string
command,
arguments,
processResult.AppendInfo,
processResult.AppendError);
processResult.AppendError,
environmentVariablesHandler);

processResult.SetReturnCode(exitCode);

return processResult;
}

private static int RunInternal(string workingDirectory, string command, string arguments,
Action<string> outCallback, Action<string> errorCallback)
Action<string> outCallback, Action<string> errorCallback,
Action<StringDictionary>? environmentVariablesHandler)
{
using (var process = new Process())
using (var outputWaitHandle = new AutoResetEvent(false))
Expand Down Expand Up @@ -109,6 +117,8 @@ private static int RunInternal(string workingDirectory, string command, string a
RedirectStandardInput = true,
};

environmentVariablesHandler?.Invoke(dotnetStartInfo.EnvironmentVariables);

process.StartInfo = dotnetStartInfo;

process.Start();
Expand All @@ -131,10 +141,8 @@ private static int RunInternal(string workingDirectory, string command, string a
/// </summary>
/// <param name="Message">Message log.</param>
/// <param name="IsError">Tells if this is an error log.</param>
public record Log(string Message, bool IsError)
{
public DateTime TimeStamp { get; } = DateTime.Now;
}
/// <param name="TimeStamp">Log message time stamp.</param>
public record struct Log(string Message, bool IsError, DateTime TimeStamp);

/// <summary>
/// Process logs.
Expand All @@ -155,12 +163,12 @@ public class ProcessResult

internal void AppendInfo(string logMessage)
{
this.logs.Add(new Log(logMessage, false));
this.logs.Add(new Log(logMessage, false, DateTime.Now));
}

internal void AppendError(string logMessage)
{
this.logs.Add(new Log(logMessage, true));
this.logs.Add(new Log(logMessage, true, DateTime.Now));
}

internal void SetReturnCode(int exitCode)
Expand Down
Loading
Loading