-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Enable NuGet Audit and Fix Errors #12120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
64ccfcc
726504f
b786851
1f457b8
e963b90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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] | ||
|
|
||
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