Skip to content

Commit

Permalink
SCAN4NET-257 Fix Quality Gate (#2328)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastien-marichal authored Feb 18, 2025
1 parent 85eaacd commit 376f225
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SonarScanner.MSBuild.Common;
using SonarScanner.MSBuild.PreProcessor.Roslyn;
using TestUtilities;

namespace SonarScanner.MSBuild.PreProcessor.Test;

Expand Down Expand Up @@ -262,7 +254,7 @@ private MockSonarWebServer CreateServerWithDummyPlugin(string languageKey)
private void AddPlugin(MockSonarWebServer server, Plugin plugin, params string[] files) =>
server.Data.AddEmbeddedZipFile(plugin.Key, plugin.StaticResourceName, files);

private static IList<string> CalculateExpectedCachedFilePaths(string baseDir, int count, params string[] fileNames) =>
private static List<string> CalculateExpectedCachedFilePaths(string baseDir, int count, params string[] fileNames) =>
fileNames.Select(x => Path.Combine(baseDir, count.ToString(), x)).ToList();

private void AssertExpectedFilesReturned(IEnumerable<string> expectedFileNames, IEnumerable<AnalyzerPlugin> actualPlugins)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NSubstitute;
using SonarScanner.MSBuild.Common;
using SonarScanner.MSBuild.PreProcessor.JreResolution;
using TestUtilities;

namespace SonarScanner.MSBuild.PreProcessor.Test.JreResolution;

Expand All @@ -45,7 +34,7 @@ public class JreResolverTests
private IJreCache cache;
private TestLogger logger;
private ISonarWebServer server;
private IJreResolver sut;
private JreResolver sut;

[TestInitialize]
public void Initialize()
Expand Down
13 changes: 2 additions & 11 deletions Tests/SonarScanner.MSBuild.PreProcessor.Test/ProcessedArgsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

using System;
using System.Collections.Generic;
using System.IO;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NSubstitute;
using SonarScanner.MSBuild.Common;
using TestUtilities;

namespace SonarScanner.MSBuild.PreProcessor.Test;

[TestClass]
Expand Down Expand Up @@ -535,6 +526,6 @@ private static void AssertExpectedValue(string key, string expectedValue, Proces
actualValue.Should().Be(expectedValue, "Setting does not have the expected value. Key: {0}", key);
}

private static IOperatingSystemProvider CreateOperatingSystemProvider() =>
new OperatingSystemProvider(Substitute.For<IFileWrapper>(), Substitute.For<ILogger>());
private static OperatingSystemProvider CreateOperatingSystemProvider() =>
new(Substitute.For<IFileWrapper>(), Substitute.For<ILogger>());
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ namespace SonarScanner.MSBuild.PreProcessor.Test.Roslyn;
[TestClass]
public class PluginTests
{
[TestMethod]
public void Plugin_IsValid()
{
var plugin = new Plugin() { Key = "pluginKey", Version = "42", StaticResourceName = "test.zip" };
var plugin = new Plugin { Key = "pluginKey", Version = "42", StaticResourceName = "test.zip" };
plugin.IsValid.Should().BeTrue();
}

Expand All @@ -41,7 +42,7 @@ public void Plugin_IsValid()
[DataRow(null, null, null)]
public void Plugin_Is_InValid(string key, string version, string resourceName)
{
var plugin = new Plugin() { Key = key, Version = version, StaticResourceName = resourceName };
var plugin = new Plugin { Key = key, Version = version, StaticResourceName = resourceName };
plugin.IsValid.Should().BeFalse();
}

Expand All @@ -63,9 +64,9 @@ public void Plugin_AddProperty_Populates_Correctly()
public void XmlSerialization_SaveAndReload()
{
var tempFileName = Path.GetTempFileName();
var original = new Plugin() { Key = "my key", Version = "MY VERSION", StaticResourceName = "my resource" };
SonarScanner.MSBuild.Common.Serializer.SaveModel(original, tempFileName);
var reloaded = SonarScanner.MSBuild.Common.Serializer.LoadModel<Plugin>(tempFileName);
var original = new Plugin { Key = "my key", Version = "MY VERSION", StaticResourceName = "my resource" };
Serializer.SaveModel(original, tempFileName);
var reloaded = Serializer.LoadModel<Plugin>(tempFileName);
reloaded.Key.Should().Be("my key");
reloaded.Version.Should().Be("MY VERSION");
reloaded.StaticResourceName.Should().Be("my resource");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,11 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using FluentAssertions;
using Google.Protobuf;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NSubstitute;
using NSubstitute.ExceptionExtensions;
using SonarScanner.MSBuild.Common;
using SonarScanner.MSBuild.PreProcessor.JreResolution;
using SonarScanner.MSBuild.PreProcessor.Protobuf;
using SonarScanner.MSBuild.PreProcessor.WebServer;
using TestUtilities;

namespace SonarScanner.MSBuild.PreProcessor.Test;

Expand Down Expand Up @@ -732,7 +720,7 @@ private static Stream CreateCacheStream(IMessage message)
return stream;
}

private void MockStreamDownload(IDownloader downloader, Stream stream) =>
private static void MockStreamDownload(IDownloader downloader, Stream stream) =>
downloader.DownloadStream(Arg.Any<string>()).Returns(Task.FromResult(stream));

private static ProcessedArgs CreateLocalSettings(string projectKey, string branch, string organization = "placeholder", string token = "placeholder")
Expand All @@ -753,7 +741,7 @@ private static ProcessedArgs CreateLocalSettings(string projectKey, string branc
return args;
}

private SonarQubeWebServer CreateServer(IDownloader downloader = null, Version version = null, ILogger logger = null, string organization = null)
private static SonarQubeWebServer CreateServer(IDownloader downloader = null, Version version = null, ILogger logger = null, string organization = null)
{
version ??= new("9.9");
downloader ??= Substitute.For<IDownloader>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NSubstitute;
using SonarScanner.MSBuild.Common;
using TestUtilities;

namespace SonarScanner.MSBuild.PreProcessor.Test;

Expand Down Expand Up @@ -308,7 +299,7 @@ private static void CleanupMsbuildDirectories()
{
// SONARMSBRU-149: we used to deploy the targets file to the 4.0 directory but this
// is no longer supported. To be on the safe side we'll clean up the old location too.
IList<string> cleanUpDirs = new MsBuildPathSettings(Substitute.For<ILogger>()).GetImportBeforePaths().ToList();
var cleanUpDirs = new MsBuildPathSettings(Substitute.For<ILogger>()).GetImportBeforePaths().ToList();

var appData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
cleanUpDirs.Add(Path.Combine(appData, "Microsoft", "MSBuild", "4.0", "Microsoft.Common.targets", "ImportBefore"));
Expand Down

0 comments on commit 376f225

Please sign in to comment.