forked from npgsql/npgsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNpgsqlEventSourceTests.cs
More file actions
54 lines (45 loc) · 1.72 KB
/
NpgsqlEventSourceTests.cs
File metadata and controls
54 lines (45 loc) · 1.72 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
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using NUnit.Framework;
namespace Npgsql.Tests
{
[NonParallelizable]
public class NpgsqlEventSourceTests : TestBase
{
[Test, Ignore("Not working, needs investigation")]
public void CommandStartStop()
{
using (var conn = OpenConnection())
{
conn.ExecuteScalar("SELECT 1");
}
var commandStart = _events.Single(e => e.EventId == NpgsqlEventSource.CommandStartId);
Assert.That(commandStart.EventName, Is.EqualTo("CommandStart"));
var commandStop = _events.Single(e => e.EventId == NpgsqlEventSource.CommandStopId);
Assert.That(commandStop.EventName, Is.EqualTo("CommandStop"));
}
[OneTimeSetUp]
public void EnableEventSource()
{
_listener = new TestEventListener(_events);
_listener.EnableEvents(NpgsqlEventSource.Log, EventLevel.Informational);
}
[OneTimeTearDown]
public void DisableEventSource()
{
_listener.DisableEvents(NpgsqlEventSource.Log);
_listener.Dispose();
}
[SetUp]
public void ClearEvents() => _events.Clear();
TestEventListener _listener = null!;
readonly List<EventWrittenEventArgs> _events = new List<EventWrittenEventArgs>();
class TestEventListener : EventListener
{
readonly List<EventWrittenEventArgs> _events;
public TestEventListener(List<EventWrittenEventArgs> events) => _events = events;
protected override void OnEventWritten(EventWrittenEventArgs eventData) => _events.Add(eventData);
}
}
}