-
Notifications
You must be signed in to change notification settings - Fork 186
Expand file tree
/
Copy pathLogWindowCoordinatorIntegrationTests.cs
More file actions
146 lines (121 loc) · 4.37 KB
/
LogWindowCoordinatorIntegrationTests.cs
File metadata and controls
146 lines (121 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
using System.Runtime.Versioning;
using LogExpert.Core.Config;
using LogExpert.Core.Entities;
using LogExpert.Core.Interfaces;
using LogExpert.UI.Controls.LogWindow;
using LogExpert.UI.Interface;
using Moq;
using NUnit.Framework;
namespace LogExpert.Tests.Controls;
[TestFixture]
[Apartment(ApartmentState.STA)]
[SupportedOSPlatform("windows")]
public class LogWindowCoordinatorIntegrationTests : IDisposable
{
private Mock<ILogWindowCoordinator> _coordinatorMock;
private Mock<IConfigManager> _configManagerMock;
private Settings _settings;
private LogWindow _logWindow;
private WindowsFormsSynchronizationContext _syncContext;
private bool _disposed;
[SetUp]
public void Setup ()
{
if (SynchronizationContext.Current == null)
{
_syncContext = new WindowsFormsSynchronizationContext();
SynchronizationContext.SetSynchronizationContext(_syncContext);
}
// Ensure PluginRegistry is initialized with default columnizers
PluginRegistry.PluginRegistry.Create(Path.GetTempPath(), 250);
_coordinatorMock = new Mock<ILogWindowCoordinator>();
_configManagerMock = new Mock<IConfigManager>();
_settings = new Settings();
_ = _configManagerMock.Setup(cm => cm.Settings).Returns(_settings);
// Setup default returns for coordinator
_ = _coordinatorMock.Setup(c => c.ResolveHighlightGroup(It.IsAny<string?>(), It.IsAny<string?>())).Returns(new HighlightGroup());
_ = _coordinatorMock.Setup(c => c.SearchParams).Returns(new SearchParams());
// Construct LogWindow with mocked dependencies
// Using a temp file name that doesn't need to exist for constructor test
_logWindow = new LogWindow(
_coordinatorMock.Object,
"test.log",
true, // isTempFile
false, // forcePersistenceLoading
_configManagerMock.Object);
}
[TearDown]
public void TearDown ()
{
_logWindow?.Dispose();
_syncContext?.Dispose();
}
protected virtual void Dispose (bool disposing)
{
if (!_disposed)
{
_logWindow?.Dispose();
_syncContext?.Dispose();
_disposed = true;
}
}
public void Dispose ()
{
Dispose(true);
GC.SuppressFinalize(this);
}
[Test]
public void Constructor_SubscribesToHighlightSettingsChanged ()
{
// Assert — verify event subscription happened during construction
_coordinatorMock.VerifyAdd(
c => c.HighlightSettingsChanged += It.IsAny<EventHandler>(),
Times.Once);
}
[Test]
public void SetCurrentHighlightGroup_CallsCoordinatorResolveHighlightGroup ()
{
// Arrange
var expectedGroup = new HighlightGroup { GroupName = "TestGroup" };
_ = _coordinatorMock.Setup(c => c.ResolveHighlightGroup("TestGroup", null))
.Returns(expectedGroup);
// Act
_logWindow.SetCurrentHighlightGroup("TestGroup");
// Assert
_coordinatorMock.Verify(
c => c.ResolveHighlightGroup("TestGroup", null),
Times.Once);
}
[Test]
public void Preferences_ReadsFromConfigManager_NotCoordinator ()
{
// Act
var preferences = _logWindow.Preferences;
// Assert — Preferences comes from ConfigManager, not coordinator
Assert.That(preferences, Is.SameAs(_settings.Preferences));
}
[Test]
public void SearchParams_ReadsFromCoordinator ()
{
// Arrange
var searchParams = new SearchParams { SearchText = "test" };
_ = _coordinatorMock.Setup(c => c.SearchParams).Returns(searchParams);
// Act — StartSearch accesses _coordinator.SearchParams
// We can't easily call StartSearch (needs dataGridView rows),
// but we can verify the property access pattern
var coordParams = _coordinatorMock.Object.SearchParams;
// Assert
Assert.That(coordParams.SearchText, Is.EqualTo("test"));
}
[Test]
public void Dispose_UnsubscribesFromHighlightSettingsChanged ()
{
// Act
_logWindow.Dispose();
// Assert
_coordinatorMock.VerifyRemove(
c => c.HighlightSettingsChanged -= It.IsAny<EventHandler>(),
Times.Once);
_logWindow = null; // prevent double-dispose in TearDown
}
}