Skip to content

Commit 1c2e911

Browse files
committed
unit test fix
1 parent 07de0b0 commit 1c2e911

6 files changed

Lines changed: 181 additions & 147 deletions

File tree

src/LogExpert.Tests/PluginRegistry/Priority3ArchitecturalTests.cs renamed to src/LogExpert.Tests/PluginRegistry/ArchitecturalTests.cs

Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,150 +1,150 @@
1-
using NUnit.Framework;
2-
31
using LogExpert.PluginRegistry;
4-
using LogExpert.PluginRegistry.Interfaces;
52
using LogExpert.PluginRegistry.Events;
3+
using LogExpert.PluginRegistry.Interfaces;
4+
5+
using NUnit.Framework;
66

77
namespace LogExpert.Tests.PluginRegistry;
88

99
[TestFixture]
10-
public class Priority3ArchitecturalTests
10+
public class ArchitecturalTests
1111
{
1212
[Test]
13-
public void DefaultPluginLoader_LoadsValidPlugin_Successfully()
13+
public void DefaultPluginLoader_LoadsValidPlugin_Successfully ()
1414
{
1515
// Note: This is a placeholder test that would need a real test plugin DLL
1616
// In a real scenario, you'd create a test assembly or use an existing one
17-
17+
1818
var loader = new DefaultPluginLoader();
19-
19+
2020
// This test verifies the loader is instantiable
2121
Assert.That(loader, Is.Not.Null);
2222
}
23-
23+
2424
[Test]
25-
public void PluginEventBus_SubscribeAndPublish_DeliversEvent()
25+
public void PluginEventBus_SubscribeAndPublish_DeliversEvent ()
2626
{
2727
// Arrange
2828
var bus = new PluginEventBus();
2929
var eventReceived = false;
3030
LogFileLoadedEvent? receivedEvent = null;
31-
31+
3232
bus.Subscribe<LogFileLoadedEvent>("TestPlugin", e =>
3333
{
3434
eventReceived = true;
3535
receivedEvent = e;
3636
});
37-
37+
3838
var testEvent = new LogFileLoadedEvent
3939
{
4040
Source = "TestSource",
4141
FileName = "test.log",
4242
FileSize = 1024
4343
};
44-
44+
4545
// Act
4646
bus.Publish(testEvent);
47-
47+
4848
// Assert
4949
Assert.That(eventReceived, Is.True, "Event should have been received");
5050
Assert.That(receivedEvent, Is.Not.Null);
5151
Assert.That(receivedEvent.Source, Is.EqualTo("TestSource"));
5252
Assert.That(receivedEvent.FileName, Is.EqualTo("test.log"));
5353
Assert.That(receivedEvent.FileSize, Is.EqualTo(1024));
5454
}
55-
55+
5656
[Test]
57-
public void PluginEventBus_Unsubscribe_StopsDeliveringEvents()
57+
public void PluginEventBus_Unsubscribe_StopsDeliveringEvents ()
5858
{
5959
// Arrange
6060
var bus = new PluginEventBus();
6161
var eventCount = 0;
62-
62+
6363
bus.Subscribe<LogFileLoadedEvent>("TestPlugin", e => eventCount++);
64-
64+
6565
// Act - publish first event
6666
bus.Publish(new LogFileLoadedEvent { Source = "Test", FileName = "test.log", FileSize = 100 });
67-
67+
6868
// Unsubscribe
6969
bus.Unsubscribe<LogFileLoadedEvent>("TestPlugin");
70-
70+
7171
// Publish second event
7272
bus.Publish(new LogFileLoadedEvent { Source = "Test", FileName = "test2.log", FileSize = 200 });
73-
73+
7474
// Assert
7575
Assert.That(eventCount, Is.EqualTo(1), "Should only receive the first event");
7676
}
77-
77+
7878
[Test]
79-
public void PluginEventBus_MultipleSubscribers_AllReceiveEvent()
79+
public void PluginEventBus_MultipleSubscribers_AllReceiveEvent ()
8080
{
8181
// Arrange
8282
var bus = new PluginEventBus();
8383
var plugin1Received = false;
8484
var plugin2Received = false;
85-
85+
8686
bus.Subscribe<LogFileLoadedEvent>("Plugin1", e => plugin1Received = true);
8787
bus.Subscribe<LogFileLoadedEvent>("Plugin2", e => plugin2Received = true);
88-
88+
8989
// Act
9090
bus.Publish(new LogFileLoadedEvent { Source = "Test", FileName = "test.log", FileSize = 100 });
91-
91+
9292
// Assert
9393
Assert.That(plugin1Received, Is.True, "Plugin1 should receive event");
9494
Assert.That(plugin2Received, Is.True, "Plugin2 should receive event");
9595
}
96-
96+
9797
[Test]
98-
public void PluginEventBus_ExceptionInHandler_DoesNotAffectOtherHandlers()
98+
public void PluginEventBus_ExceptionInHandler_DoesNotAffectOtherHandlers ()
9999
{
100100
// Arrange
101101
var bus = new PluginEventBus();
102102
var plugin1Received = false;
103103
var plugin2Received = false;
104-
104+
105105
bus.Subscribe<LogFileLoadedEvent>("Plugin1", e =>
106106
{
107107
plugin1Received = true;
108108
throw new InvalidOperationException("Test exception");
109109
});
110-
110+
111111
bus.Subscribe<LogFileLoadedEvent>("Plugin2", e => plugin2Received = true);
112-
112+
113113
// Act
114114
bus.Publish(new LogFileLoadedEvent { Source = "Test", FileName = "test.log", FileSize = 100 });
115-
115+
116116
// Assert
117117
Assert.That(plugin1Received, Is.True, "Plugin1 should receive event");
118118
Assert.That(plugin2Received, Is.True, "Plugin2 should still receive event despite Plugin1 exception");
119119
}
120-
120+
121121
[Test]
122-
public void PluginEventBus_UnsubscribeAll_RemovesAllSubscriptions()
122+
public void PluginEventBus_UnsubscribeAll_RemovesAllSubscriptions ()
123123
{
124124
// Arrange
125125
var bus = new PluginEventBus();
126126
var eventCount = 0;
127-
127+
128128
bus.Subscribe<LogFileLoadedEvent>("TestPlugin", e => eventCount++);
129129
bus.Subscribe<LogFileClosedEvent>("TestPlugin", e => eventCount++);
130-
130+
131131
// Act - publish events before unsubscribe
132132
bus.Publish(new LogFileLoadedEvent { Source = "Test", FileName = "test.log", FileSize = 100 });
133133
bus.Publish(new LogFileClosedEvent { Source = "Test", FileName = "test.log" });
134-
134+
135135
// Unsubscribe all
136136
bus.UnsubscribeAll("TestPlugin");
137-
137+
138138
// Publish events after unsubscribe
139139
bus.Publish(new LogFileLoadedEvent { Source = "Test", FileName = "test2.log", FileSize = 200 });
140140
bus.Publish(new LogFileClosedEvent { Source = "Test", FileName = "test2.log" });
141-
141+
142142
// Assert
143143
Assert.That(eventCount, Is.EqualTo(2), "Should only receive events before UnsubscribeAll");
144144
}
145-
145+
146146
[Test]
147-
public void PluginContext_InitializesWithCorrectValues()
147+
public void PluginContext_InitializesWithCorrectValues ()
148148
{
149149
// Arrange & Act
150150
var logger = new PluginLogger("TestPlugin");
@@ -155,29 +155,29 @@ public void PluginContext_InitializesWithCorrectValues()
155155
HostVersion = new Version(1, 2, 3),
156156
ConfigurationDirectory = @"C:\Config\TestPlugin"
157157
};
158-
158+
159159
// Assert
160160
Assert.That(context.Logger, Is.Not.Null);
161161
Assert.That(context.PluginDirectory, Is.EqualTo(@"C:\Plugins\TestPlugin"));
162162
Assert.That(context.HostVersion, Is.EqualTo(new Version(1, 2, 3)));
163163
Assert.That(context.ConfigurationDirectory, Is.EqualTo(@"C:\Config\TestPlugin"));
164164
}
165-
165+
166166
[Test]
167-
public void PluginLogger_LogsMessages_WithoutException()
167+
public void PluginLogger_LogsMessages_WithoutException ()
168168
{
169169
// Arrange
170170
var logger = new PluginLogger("TestPlugin");
171-
171+
172172
// Act & Assert - should not throw
173173
Assert.DoesNotThrow(() => logger.Debug("Debug message"));
174174
Assert.DoesNotThrow(() => logger.Info("Info message"));
175175
Assert.DoesNotThrow(() => logger.LogWarn("Warn message"));
176176
Assert.DoesNotThrow(() => logger.LogError("Error message"));
177177
}
178-
178+
179179
[Test]
180-
public void PluginLoadResult_Success_ContainsPluginAndManifest()
180+
public void PluginLoadResult_Success_ContainsPluginAndManifest ()
181181
{
182182
// Arrange
183183
var manifest = new PluginManifest
@@ -189,24 +189,24 @@ public void PluginLoadResult_Success_ContainsPluginAndManifest()
189189
Main = "TestPlugin.dll",
190190
ApiVersion = "1.0"
191191
};
192-
192+
193193
// Act
194194
var result = new PluginLoadResult
195195
{
196196
Success = true,
197197
Plugin = new object(),
198198
Manifest = manifest
199199
};
200-
200+
201201
// Assert
202202
Assert.That(result.Success, Is.True);
203203
Assert.That(result.Plugin, Is.Not.Null);
204204
Assert.That(result.Manifest, Is.Not.Null);
205205
Assert.That(result.Manifest.Name, Is.EqualTo("TestPlugin"));
206206
}
207-
207+
208208
[Test]
209-
public void PluginLoadResult_Failure_ContainsErrorMessage()
209+
public void PluginLoadResult_Failure_ContainsErrorMessage ()
210210
{
211211
// Arrange & Act
212212
var result = new PluginLoadResult
@@ -215,16 +215,16 @@ public void PluginLoadResult_Failure_ContainsErrorMessage()
215215
ErrorMessage = "Plugin not found",
216216
Exception = new FileNotFoundException()
217217
};
218-
218+
219219
// Assert
220220
Assert.That(result.Success, Is.False);
221221
Assert.That(result.ErrorMessage, Is.Not.Null);
222222
Assert.That(result.Exception, Is.Not.Null);
223223
Assert.That(result.Exception, Is.InstanceOf<FileNotFoundException>());
224224
}
225-
225+
226226
[Test]
227-
public void ValidationResult_Invalid_ContainsErrors()
227+
public void ValidationResult_Invalid_ContainsErrors ()
228228
{
229229
// Arrange & Act
230230
var result = new ValidationResult
@@ -234,16 +234,16 @@ public void ValidationResult_Invalid_ContainsErrors()
234234
Warnings = ["Optional field 'url' not provided"],
235235
UserFriendlyError = "The plugin manifest is incomplete"
236236
};
237-
237+
238238
// Assert
239239
Assert.That(result.IsValid, Is.False);
240240
Assert.That(result.Errors.Count, Is.EqualTo(2));
241241
Assert.That(result.Warnings.Count, Is.EqualTo(1));
242242
Assert.That(result.UserFriendlyError, Is.Not.Null);
243243
}
244-
244+
245245
[Test]
246-
public void CommonEvents_HaveCorrectProperties()
246+
public void CommonEvents_HaveCorrectProperties ()
247247
{
248248
// Arrange & Act
249249
var loadedEvent = new LogFileLoadedEvent
@@ -253,30 +253,30 @@ public void CommonEvents_HaveCorrectProperties()
253253
FileSize = 1024,
254254
LineCount = 100
255255
};
256-
256+
257257
var closedEvent = new LogFileClosedEvent
258258
{
259259
Source = "LogExpert",
260260
FileName = "test.log"
261261
};
262-
262+
263263
var pluginLoadedEvent = new PluginLoadedEvent
264264
{
265265
Source = "LogExpert",
266266
PluginName = "TestPlugin",
267267
PluginVersion = "1.0.0"
268268
};
269-
269+
270270
// Assert
271271
Assert.That(loadedEvent.Timestamp, Is.Not.Null);
272272
Assert.That(loadedEvent.Timestamp, Is.LessThanOrEqualTo(DateTime.UtcNow));
273273
Assert.That(loadedEvent.Source, Is.EqualTo("LogExpert"));
274274
Assert.That(loadedEvent.FileSize, Is.EqualTo(1024));
275275
Assert.That(loadedEvent.LineCount, Is.EqualTo(100));
276-
276+
277277
Assert.That(closedEvent.Source, Is.EqualTo("LogExpert"));
278278
Assert.That(closedEvent.FileName, Is.EqualTo("test.log"));
279-
279+
280280
Assert.That(pluginLoadedEvent.Source, Is.EqualTo("LogExpert"));
281281
Assert.That(pluginLoadedEvent.PluginName, Is.EqualTo("TestPlugin"));
282282
Assert.That(pluginLoadedEvent.PluginVersion, Is.EqualTo("1.0.0"));

src/LogExpert.Tests/PluginRegistry/PathTraversalProtectionTests.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
namespace LogExpert.Tests.PluginRegistry;
66

77
/// <summary>
8-
/// Unit tests for Path Traversal Protection (Priority 1, Task 1.3)
8+
/// Unit tests for Path Traversal Protection
99
/// </summary>
1010
[TestFixture]
11-
[Category("Priority1")]
1211
[Category("PathTraversal")]
1312
[Category("Security")]
1413
public class PathTraversalProtectionTests
@@ -101,8 +100,6 @@ public void ValidateManifestPaths_TildePath_Detected ()
101100
var result = ValidateManifestPathsHelper(manifest, _pluginDirectory);
102101

103102
// Assert
104-
// Note: This should log a warning but may still pass
105-
// Adjust based on actual implementation
106103
Assert.That(result, Is.True, "Tilde in dependencies is detected (logged as warning)");
107104
}
108105

0 commit comments

Comments
 (0)