diff --git a/Directory.Build.props b/Directory.Build.props index 0f1605e51e..b68e4850c0 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -24,6 +24,9 @@ or $(MSBuildProjectName.EndsWith('.Analyzers.VisualBasic')) or $(MSBuildProjectName.EndsWith('.Analyzers.CSharp')))" >true + + + $(WarningsNotAsErrors);NU1901;NU1902;NU1903;NU1904 + + + + diff --git a/eng/Versions.props b/eng/Versions.props index d2c3e90c7e..e50e3a7768 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -76,7 +76,7 @@ 17.0.15-alpha 7.0.0 - 4.10.0 + 4.20.70 6.11.0 8.0.0-beta.23107.1 8.0.0-beta.23107.1 @@ -103,7 +103,7 @@ $(MicrosoftCodeAnalysisAnalyzersVersion) 8.0.0-preview.23327.3 1.2.0-beta.556 - 6.3.4 + 6.11.0 @@ -111,5 +111,7 @@ 3.0.0 13.0.1 2.6.7 + + 8.0.1 diff --git a/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System.Windows.Forms.Analyzers.CSharp.Tests.csproj b/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System.Windows.Forms.Analyzers.CSharp.Tests.csproj index f694dc3208..713a40fa9b 100644 --- a/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System.Windows.Forms.Analyzers.CSharp.Tests.csproj +++ b/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System.Windows.Forms.Analyzers.CSharp.Tests.csproj @@ -17,6 +17,7 @@ + diff --git a/src/System.Windows.Forms.Analyzers.VisualBasic/tests/UnitTests/System.Windows.Forms.Analyzers.VisualBasic.Tests/System.Windows.Forms.Analyzers.VisualBasic.Tests.vbproj b/src/System.Windows.Forms.Analyzers.VisualBasic/tests/UnitTests/System.Windows.Forms.Analyzers.VisualBasic.Tests/System.Windows.Forms.Analyzers.VisualBasic.Tests.vbproj index 083c68dac3..32e1784ab7 100644 --- a/src/System.Windows.Forms.Analyzers.VisualBasic/tests/UnitTests/System.Windows.Forms.Analyzers.VisualBasic.Tests/System.Windows.Forms.Analyzers.VisualBasic.Tests.vbproj +++ b/src/System.Windows.Forms.Analyzers.VisualBasic/tests/UnitTests/System.Windows.Forms.Analyzers.VisualBasic.Tests/System.Windows.Forms.Analyzers.VisualBasic.Tests.vbproj @@ -18,6 +18,7 @@ + diff --git a/src/System.Windows.Forms.Analyzers/tests/UnitTests/System.Windows.Forms.Analyzers.Tests.csproj b/src/System.Windows.Forms.Analyzers/tests/UnitTests/System.Windows.Forms.Analyzers.Tests.csproj index 949bc02cc2..3cd07e52e7 100644 --- a/src/System.Windows.Forms.Analyzers/tests/UnitTests/System.Windows.Forms.Analyzers.Tests.csproj +++ b/src/System.Windows.Forms.Analyzers/tests/UnitTests/System.Windows.Forms.Analyzers.Tests.csproj @@ -20,6 +20,7 @@ + diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/CollectionEditorTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/CollectionEditorTests.cs index 3336d68aff..a9d6babbd1 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/CollectionEditorTests.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/CollectionEditorTests.cs @@ -602,9 +602,6 @@ public class CollectionEditorTests .Returns(mockEditorService.Object); Mock mockTransaction = new(MockBehavior.Strict); - mockTransaction - .Protected() - .Setup("Dispose", It.IsAny()); mockTransaction .Protected() .Setup("OnCommit") @@ -652,9 +649,6 @@ public class CollectionEditorTests .Returns(mockEditorService.Object); Mock mockTransaction = new(MockBehavior.Strict); - mockTransaction - .Protected() - .Setup("Dispose", It.IsAny()); mockTransaction .Protected() .Setup("OnCancel") diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/MaskedTextBoxTextEditorTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/MaskedTextBoxTextEditorTests.cs index 1708dd1166..7d8f32860f 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/MaskedTextBoxTextEditorTests.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/MaskedTextBoxTextEditorTests.cs @@ -17,7 +17,7 @@ public class MaskedTextBoxTextEditorTests Mock mockContext = new(MockBehavior.Strict); mockContext .Setup(c => c.Instance) - .Returns(null); + .Returns((object?)null); Mock mockEditorService = new(MockBehavior.Strict); mockEditorService diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/DataGridViewCellAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/DataGridViewCellAccessibleObjectTests.cs index fe44050343..f68dc944f2 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/DataGridViewCellAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/DataGridViewCellAccessibleObjectTests.cs @@ -465,6 +465,9 @@ public class DataGridViewCellAccessibleObjectTests : DataGridViewCell public void DataGridViewCellAccessibleObject_Select_HasSelectionFlagsWithoutValidDataGridView_DoesNothing() { Mock 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 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 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 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()) .Verifiable(); diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ApplicationContextTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ApplicationContextTests.cs index daee4b4419..2a39508f20 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ApplicationContextTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ApplicationContextTests.cs @@ -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 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 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] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AxSystemMonitorTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AxSystemMonitorTests.cs index db3d62e00d..352476de30 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AxSystemMonitorTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AxSystemMonitorTests.cs @@ -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);