Enable NuGet Audit and Fix Errors (#12120)

* enable nuget audit

* fix nuget audit errors

* avoid nuget audit errors unless official build

* fix failing tests due to moq version upgrade

* try removing mocking dispose
This commit is contained in:
Loni Tra 2024-09-12 13:41:44 -07:00 коммит произвёл GitHub
Родитель 26c0ae6adc
Коммит ee9bd2fdf8
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
11 изменённых файлов: 65 добавлений и 36 удалений

Просмотреть файл

@ -24,6 +24,9 @@
or $(MSBuildProjectName.EndsWith('.Analyzers.VisualBasic'))
or $(MSBuildProjectName.EndsWith('.Analyzers.CSharp')))"
>true</IsAnalyzerProject>
<!-- Only upgrade NuGetAudit warnings to errors for official builds. -->
<WarningsNotAsErrors Condition="'$(OfficialBuild)' != 'true'">$(WarningsNotAsErrors);NU1901;NU1902;NU1903;NU1904</WarningsNotAsErrors>
</PropertyGroup>
<!--

Просмотреть файл

@ -18,6 +18,10 @@
<!-- CsWin32 dailies -->
<add key="winsdk" value="https://pkgs.dev.azure.com/azure-public/winsdk/_packaging/CI/nuget/v3/index.json" />
</packageSources>
<auditSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</auditSources>
<disabledPackageSources>
<clear />
</disabledPackageSources>

Просмотреть файл

@ -76,7 +76,7 @@
<MicrosoftVisualStudioThreadingVersion>17.0.15-alpha</MicrosoftVisualStudioThreadingVersion>
<!-- This is needed for Verify.Xunit to pull correct version of System.Speech -->
<MicrosoftWindowsCompatibilityVersion>7.0.0</MicrosoftWindowsCompatibilityVersion>
<MoqPackageVersion>4.10.0</MoqPackageVersion>
<MoqPackageVersion>4.20.70</MoqPackageVersion>
<FluentAssertionsVersion>6.11.0</FluentAssertionsVersion>
<SystemComponentModelTypeConverterTestDataVersion>8.0.0-beta.23107.1</SystemComponentModelTypeConverterTestDataVersion>
<SystemDrawingCommonTestDataVersion>8.0.0-beta.23107.1</SystemDrawingCommonTestDataVersion>
@ -103,7 +103,7 @@
<MicrosoftCodeAnalysisPublicApiAnalyzersVersion>$(MicrosoftCodeAnalysisAnalyzersVersion)</MicrosoftCodeAnalysisPublicApiAnalyzersVersion>
<MicrosoftCodeAnalysisNetAnalyzersVersion>8.0.0-preview.23327.3</MicrosoftCodeAnalysisNetAnalyzersVersion>
<StyleCopAnalyzersVersion>1.2.0-beta.556</StyleCopAnalyzersVersion>
<NugetPackagingVersion>6.3.4</NugetPackagingVersion>
<NugetPackagingVersion>6.11.0</NugetPackagingVersion>
</PropertyGroup>
<!-- Additional unchanging dependencies -->
<PropertyGroup>
@ -111,5 +111,7 @@
<MicrosoftWindowsDesktopAppRefv30PackageVersion>3.0.0</MicrosoftWindowsDesktopAppRefv30PackageVersion>
<NewtonsoftJsonVersion>13.0.1</NewtonsoftJsonVersion>
<VsWherePackageVersion>2.6.7</VsWherePackageVersion>
<!-- Pin transitive dependency to avoid vulnerable 8.0.0 version. -->
<SystemFormatsAsn1PackageVersion>8.0.1</SystemFormatsAsn1PackageVersion>
</PropertyGroup>
</Project>

Просмотреть файл

@ -17,6 +17,7 @@
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.XUnit" Version="$(MicrosoftCodeAnalysisPackagesVersion)" />
<PackageReference Include="Verify.Xunit" Version="$(VerifyXunitVersion)" />
<PackageReference Include="NuGet.Packaging" Version="$(NugetPackagingVersion)" />
<PackageReference Include="System.Formats.Asn1" Version="$(SystemFormatsAsn1PackageVersion)" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -18,6 +18,7 @@
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.SourceGenerators.Testing.XUnit" Version="$(MicrosoftCodeAnalysisPackagesVersion)" />
<PackageReference Include="Verify.Xunit" Version="$(VerifyXunitVersion)" />
<PackageReference Include="NuGet.Packaging" Version="$(NugetPackagingVersion)" />
<PackageReference Include="System.Formats.Asn1" Version="$(SystemFormatsAsn1PackageVersion)" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -20,6 +20,7 @@
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.CodeFix.Testing.XUnit" Version="$(MicrosoftCodeAnalysisPackagesVersion)" />
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.CodeRefactoring.Testing.XUnit" Version="$(MicrosoftCodeAnalysisPackagesVersion)" />
<PackageReference Include="NuGet.Packaging" Version="$(NugetPackagingVersion)" />
<PackageReference Include="System.Formats.Asn1" Version="$(SystemFormatsAsn1PackageVersion)" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -602,9 +602,6 @@ public class CollectionEditorTests
.Returns(mockEditorService.Object);
Mock<DesignerTransaction> mockTransaction = new(MockBehavior.Strict);
mockTransaction
.Protected()
.Setup("Dispose", It.IsAny<bool>());
mockTransaction
.Protected()
.Setup("OnCommit")
@ -652,9 +649,6 @@ public class CollectionEditorTests
.Returns(mockEditorService.Object);
Mock<DesignerTransaction> mockTransaction = new(MockBehavior.Strict);
mockTransaction
.Protected()
.Setup("Dispose", It.IsAny<bool>());
mockTransaction
.Protected()
.Setup("OnCancel")

Просмотреть файл

@ -17,7 +17,7 @@ public class MaskedTextBoxTextEditorTests
Mock<ITypeDescriptorContext> mockContext = new(MockBehavior.Strict);
mockContext
.Setup(c => c.Instance)
.Returns(null);
.Returns((object?)null);
Mock<IWindowsFormsEditorService> mockEditorService = new(MockBehavior.Strict);
mockEditorService

Просмотреть файл

@ -465,6 +465,9 @@ public class DataGridViewCellAccessibleObjectTests : DataGridViewCell
public void DataGridViewCellAccessibleObject_Select_HasSelectionFlagsWithoutValidDataGridView_DoesNothing()
{
Mock<DataGridViewCell> mockCell = new(MockBehavior.Strict);
mockCell
.SetupSet(s => s.State = DataGridViewElementStates.None)
.Verifiable();
mockCell
.SetupSet(s => s.State = DataGridViewElementStates.Visible)
.Verifiable();
@ -495,6 +498,9 @@ public class DataGridViewCellAccessibleObjectTests : DataGridViewCell
Assert.True(dataGridView.IsHandleCreated);
Mock<DataGridViewCell> mockCell = new(MockBehavior.Strict);
mockCell
.SetupSet(s => s.State = DataGridViewElementStates.None)
.Verifiable();
mockCell
.SetupSet(s => s.State = DataGridViewElementStates.Visible)
.Verifiable();
@ -525,6 +531,9 @@ public class DataGridViewCellAccessibleObjectTests : DataGridViewCell
Assert.True(dataGridView.IsHandleCreated);
Mock<DataGridViewCell> mockCell = new(MockBehavior.Strict);
mockCell
.SetupSet(s => s.State = DataGridViewElementStates.None)
.Verifiable();
mockCell
.SetupSet(s => s.State = DataGridViewElementStates.Visible)
.Verifiable();
@ -561,6 +570,9 @@ public class DataGridViewCellAccessibleObjectTests : DataGridViewCell
Assert.True(dataGridView.IsHandleCreated);
Mock<DataGridViewCell> mockCell = new(MockBehavior.Strict);
mockCell
.SetupSet(s => s.State = DataGridViewElementStates.None)
.Verifiable();
mockCell
.SetupSet(s => s.State = DataGridViewElementStates.Visible)
.Verifiable();
@ -595,6 +607,9 @@ public class DataGridViewCellAccessibleObjectTests : DataGridViewCell
mockCell
.SetupSet(s => s.State = DataGridViewElementStates.Visible)
.Verifiable();
mockCell
.SetupSet(s => s.State = DataGridViewElementStates.None)
.Verifiable();
mockCell
.SetupSet(s => s.Selected = It.IsAny<bool>())
.Verifiable();

Просмотреть файл

@ -1,9 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Moq;
using Moq.Protected;
namespace System.Windows.Forms.Tests;
public class ApplicationContextTests
@ -210,20 +207,39 @@ public class ApplicationContextTests
Assert.Null(context.MainForm);
}
private class TestApplicationContext : ApplicationContext
{
public TestApplicationContext() : base()
{
}
public int DisposeCallCount { get; private set; }
public int ExitThreadCoreCount { get; private set; }
protected override void Dispose(bool disposing)
{
DisposeCallCount++;
base.Dispose(disposing);
}
protected override void ExitThreadCore()
{
ExitThreadCoreCount++;
base.ExitThreadCore();
}
}
[WinFormsFact]
public void Dispose_Invoke_CallsDisposeDisposing()
{
Mock<ApplicationContext> mockContext = new(MockBehavior.Strict);
mockContext
.Protected()
.Setup("Dispose", true)
.Verifiable();
mockContext.Object.Dispose();
mockContext.Protected().Verify("Dispose", Times.Once(), true);
TestApplicationContext context = new();
context.Dispose();
context.DisposeCallCount.Should().Be(1);
// Call again.
mockContext.Object.Dispose();
mockContext.Protected().Verify("Dispose", Times.Exactly(2), true);
context.Dispose();
context.DisposeCallCount.Should().Be(2);
}
[WinFormsFact]
@ -296,20 +312,13 @@ public class ApplicationContextTests
[WinFormsFact]
public void ExitThread_Invoke_CallsExitThreadCore()
{
Mock<ApplicationContext> mockContext = new(MockBehavior.Strict);
mockContext
.Protected()
.Setup("ExitThreadCore")
.Verifiable();
mockContext
.Protected()
.Setup("Dispose", false);
mockContext.Object.ExitThread();
mockContext.Protected().Verify("ExitThreadCore", Times.Once());
TestApplicationContext context = new();
context.ExitThread();
context.ExitThreadCoreCount.Should().Be(1);
// Call again.
mockContext.Object.ExitThread();
mockContext.Protected().Verify("ExitThreadCore", Times.Exactly(2));
context.ExitThread();
context.ExitThreadCoreCount.Should().Be(2);
}
[WinFormsFact]

Просмотреть файл

@ -1,6 +1,5 @@
using System.ComponentModel;
using System.Reflection;
using Castle.Core.Internal;
namespace System.Windows.Forms.Tests;
@ -38,7 +37,7 @@ public class AxSystemMonitorTests : IDisposable
foreach(PropertyDescriptor prop in properties)
{
string assemblyFromTestingControl = prop.ComponentType.Assembly.GetName().Name;
if (!assemblyFromTestingControl.IsNullOrEmpty()
if (!string.IsNullOrEmpty(assemblyFromTestingControl)
&& assemblyFromTestingControl == assemblyNameFromType)
{
testingControlProps.Add(prop.Name);
@ -49,7 +48,7 @@ public class AxSystemMonitorTests : IDisposable
foreach(EventDescriptor singleEvent in events)
{
string assemblyFromTestingControl = singleEvent.ComponentType.Assembly.GetName().Name;
if (!assemblyFromTestingControl.IsNullOrEmpty()
if (!string.IsNullOrEmpty(assemblyFromTestingControl)
&& assemblyFromTestingControl == assemblyNameFromType)
{
testingControlEvents.Add(singleEvent.Name);