-
Notifications
You must be signed in to change notification settings - Fork 874
Expand file tree
/
Copy pathNpgsqlEventSourceTests.cs
More file actions
53 lines (43 loc) · 1.52 KB
/
NpgsqlEventSourceTests.cs
File metadata and controls
53 lines (43 loc) · 1.52 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
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using NUnit.Framework;
namespace Npgsql.Tests;
[NonParallelizable] // Events
public class NpgsqlEventSourceTests : TestBase
{
[Test]
public void Command_start_stop()
{
using (var conn = OpenConnection())
{
// There is a new pool created, which sends a few queries to load pg types
ClearEvents();
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(NpgsqlSqlEventSource.Log, EventLevel.Informational);
}
[OneTimeTearDown]
public void DisableEventSource()
{
_listener.DisableEvents(NpgsqlSqlEventSource.Log);
_listener.Dispose();
}
[SetUp]
public void ClearEvents() => _events.Clear();
TestEventListener _listener = null!;
readonly List<EventWrittenEventArgs> _events = [];
class TestEventListener(List<EventWrittenEventArgs> events) : EventListener
{
protected override void OnEventWritten(EventWrittenEventArgs eventData) => events.Add(eventData);
}
}