Skip to content

Commit e963b90

Browse files
committed
try removing mocking dispose
1 parent 1f457b8 commit e963b90

File tree

2 files changed

+13
-21
lines changed

2 files changed

+13
-21
lines changed

src/System.Windows.Forms.Design/tests/UnitTests/System/ComponentModel/Design/CollectionEditorTests.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -602,9 +602,6 @@ public void CollectionEditor_EditValue_ValidProviderValidHostWithTransactionOK_C
602602
.Returns(mockEditorService.Object);
603603

604604
Mock<DesignerTransaction> mockTransaction = new(MockBehavior.Strict);
605-
mockTransaction
606-
.Protected()
607-
.Setup("Dispose", It.IsAny<bool>());
608605
mockTransaction
609606
.Protected()
610607
.Setup("OnCommit")
@@ -652,9 +649,6 @@ public void CollectionEditor_EditValue_ValidProviderValidHostWithTransactionNotO
652649
.Returns(mockEditorService.Object);
653650

654651
Mock<DesignerTransaction> mockTransaction = new(MockBehavior.Strict);
655-
mockTransaction
656-
.Protected()
657-
.Setup("Dispose", It.IsAny<bool>());
658652
mockTransaction
659653
.Protected()
660654
.Setup("OnCancel")

src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ApplicationContextTests.cs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using Moq;
5-
using Moq.Protected;
6-
74
namespace System.Windows.Forms.Tests;
85

96
public class ApplicationContextTests
@@ -218,11 +215,19 @@ public TestApplicationContext() : base()
218215

219216
public int DisposeCallCount { get; private set; }
220217

218+
public int ExitThreadCoreCount { get; private set; }
219+
221220
protected override void Dispose(bool disposing)
222221
{
223222
DisposeCallCount++;
224223
base.Dispose(disposing);
225224
}
225+
226+
protected override void ExitThreadCore()
227+
{
228+
ExitThreadCoreCount++;
229+
base.ExitThreadCore();
230+
}
226231
}
227232

228233
[WinFormsFact]
@@ -307,20 +312,13 @@ public void ExitThread_InvokeWithThreadExit_CallsHandler()
307312
[WinFormsFact]
308313
public void ExitThread_Invoke_CallsExitThreadCore()
309314
{
310-
Mock<ApplicationContext> mockContext = new(MockBehavior.Strict);
311-
mockContext
312-
.Protected()
313-
.Setup("ExitThreadCore")
314-
.Verifiable();
315-
mockContext
316-
.Protected()
317-
.Setup("Dispose", false);
318-
mockContext.Object.ExitThread();
319-
mockContext.Protected().Verify("ExitThreadCore", Times.Once());
315+
TestApplicationContext context = new();
316+
context.ExitThread();
317+
context.ExitThreadCoreCount.Should().Be(1);
320318

321319
// Call again.
322-
mockContext.Object.ExitThread();
323-
mockContext.Protected().Verify("ExitThreadCore", Times.Exactly(2));
320+
context.ExitThread();
321+
context.ExitThreadCoreCount.Should().Be(2);
324322
}
325323

326324
[WinFormsFact]

0 commit comments

Comments
 (0)