From ef4080687cb1d212db27a01ecf2248d79edd74a3 Mon Sep 17 00:00:00 2001 From: Zijian <161275903+ZijianFLG@users.noreply.github.com> Date: Sat, 1 Jun 2024 19:28:40 +1000 Subject: [PATCH] refactoring --- .editorconfig | 31 +++++++++++++++++++ .../HttpClientWithUsername.cs | 2 +- Fonlow.Testing.HttpCore/TestingSettings.cs | 2 +- .../DotNetHostFixture.cs | 1 - .../IisExpressAgentBase.cs | 5 ++- .../ServiceCommandsFixture.cs | 3 -- FonlowTesting.sln | 1 + 7 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..d2800d5 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,31 @@ +[*.cs] + +# CA1303: Do not pass literals as localized parameters +dotnet_diagnostic.CA1303.severity = none + +# CA1307: Specify StringComparison +dotnet_diagnostic.CA1307.severity = none + +# CA1305: Specify IFormatProvider +dotnet_diagnostic.CA1305.severity = none + +# CA1304: Specify CultureInfo +dotnet_diagnostic.CA1304.severity = none + +# CA1062: Validate arguments of public methods +dotnet_diagnostic.CA1062.severity = none + +# CA1819: Properties should not return arrays +dotnet_diagnostic.CA1819.severity = none + +# CA1055: Uri return values should not be strings +dotnet_diagnostic.CA1055.severity = none + +# CA1054: Uri parameters should not be strings +dotnet_diagnostic.CA1054.severity = none + +# CA1051: Do not declare visible instance fields +dotnet_diagnostic.CA1051.severity = none + +dotnet_diagnostic.CA1056.severity = none + diff --git a/Fonlow.Testing.HttpCore/HttpClientWithUsername.cs b/Fonlow.Testing.HttpCore/HttpClientWithUsername.cs index 7a35a87..c2ef640 100644 --- a/Fonlow.Testing.HttpCore/HttpClientWithUsername.cs +++ b/Fonlow.Testing.HttpCore/HttpClientWithUsername.cs @@ -128,7 +128,7 @@ public string GetToken(Uri baseUri, string userName, string password) new KeyValuePair( "username", userName ), new KeyValuePair ( "password", password ) }; - var content = new FormUrlEncodedContent(pairs); + using var content = new FormUrlEncodedContent(pairs); try { using (var client = new HttpClient(this.handler, false)) diff --git a/Fonlow.Testing.HttpCore/TestingSettings.cs b/Fonlow.Testing.HttpCore/TestingSettings.cs index 71b0e21..ef24a9d 100644 --- a/Fonlow.Testing.HttpCore/TestingSettings.cs +++ b/Fonlow.Testing.HttpCore/TestingSettings.cs @@ -74,7 +74,7 @@ public sealed class ServiceCommand { public string Arguments { get; set; } /// - /// Some services may take some seconds to launch then listen. + /// Some services may take some seconds to launch then listen, especially in GitHub Actions which VM/container could be slow. A good bet may be 5 seconds. /// public int Delay { get; set; } public string ConnectionString{ get; set; } diff --git a/Fonlow.Testing.ServiceCore/DotNetHostFixture.cs b/Fonlow.Testing.ServiceCore/DotNetHostFixture.cs index 698c355..8b2b0cf 100644 --- a/Fonlow.Testing.ServiceCore/DotNetHostFixture.cs +++ b/Fonlow.Testing.ServiceCore/DotNetHostFixture.cs @@ -25,7 +25,6 @@ public DotNetHostFixture() public void Dispose() { - Console.WriteLine("DotNetHostFixture is being disposed."); Dispose(true); GC.SuppressFinalize(this); } diff --git a/Fonlow.Testing.ServiceCore/IisExpressAgentBase.cs b/Fonlow.Testing.ServiceCore/IisExpressAgentBase.cs index 0985b09..d6b5b83 100644 --- a/Fonlow.Testing.ServiceCore/IisExpressAgentBase.cs +++ b/Fonlow.Testing.ServiceCore/IisExpressAgentBase.cs @@ -50,6 +50,7 @@ public string IisExpressArguments { get { +#pragma warning disable CA1065 if (SlnRoot== "SLN_ROOT_.VS") { var d = DirFunctions.GetSlnDir(System.IO.Directory.GetCurrentDirectory()); @@ -65,8 +66,10 @@ public string IisExpressArguments var appHostConfig = String.IsNullOrEmpty(SlnName) ? System.IO.Path.Combine(SlnRoot, @".vs\config\applicationhost.config"): System.IO.Path.Combine(SlnRoot, $@".vs\{SlnName}\config\applicationhost.config"); if (!System.IO.File.Exists(appHostConfig)) + { throw new ArgumentException("app.config does not contain correct info pointing to applicationhost.config for IIS Express."); - + } +#pragma warning restore CA1065 var iisStartArguments = String.IsNullOrEmpty(SlnRoot) ? String.Format("/site:\"{0}\" /apppool:\"{1}\"", HostSite, HostSiteApplicationPool) : String.Format("/site:\"{0}\" /apppool:\"{1}\" /config:\"{2}\"", HostSite, HostSiteApplicationPool, appHostConfig); return iisStartArguments; diff --git a/Fonlow.Testing.ServiceCore/ServiceCommandsFixture.cs b/Fonlow.Testing.ServiceCore/ServiceCommandsFixture.cs index 6cb813c..1db5794 100644 --- a/Fonlow.Testing.ServiceCore/ServiceCommandsFixture.cs +++ b/Fonlow.Testing.ServiceCore/ServiceCommandsFixture.cs @@ -21,15 +21,12 @@ public ServiceCommandsFixture() } } - public ServiceCommand[] ServiceCommands => TestingSettings.Instance.ServiceCommands; - List serviceCommandAgents = new List(); bool disposed; public void Dispose() { - Console.WriteLine("ServiceCommandsFixture is being disposed."); Dispose(true); GC.SuppressFinalize(this); } diff --git a/FonlowTesting.sln b/FonlowTesting.sln index 4308912..8565577 100644 --- a/FonlowTesting.sln +++ b/FonlowTesting.sln @@ -7,6 +7,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{A3630AD3 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{68F190A5-D31E-4259-A7D8-BC96EC10EFA3}" ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig BuildRelease.ps1 = BuildRelease.ps1 DotNetPack.ps1 = DotNetPack.ps1 README.md = README.md