-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Enable NuGet Audit and Fix Errors #12120
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
64ccfcc
enable nuget audit
lonitra 726504f
fix nuget audit errors
lonitra b786851
avoid nuget audit errors unless official build
lonitra 1f457b8
fix failing tests due to moq version upgrade
lonitra e963b90
try removing mocking dispose
lonitra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 void Dispose_InvokeWithoutForm_Success() | |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the upgrade to latest moq version, I get errors with moq complaining that there is no protected Dispose(bool) method even though there is. I have opted to avoiding mocking a test object and creating a real test object instead or just removing the Dispose setup if it doesn't look to be necessary. |
||
.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 void ExitThread_InvokeWithThreadExit_CallsHandler() | |
[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] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created issue to track unpinning this #12121