-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
LoggingTest.cs
47 lines (42 loc) · 1.94 KB
/
LoggingTest.cs
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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Diagnostics.Tracing;
using System.Threading.Tasks;
using Microsoft.DotNet.RemoteExecutor;
using Xunit;
namespace System.Net.Mail.Tests
{
[SkipOnPlatform(TestPlatforms.Browser, "SmtpClient is not supported on Browser")]
public class LoggingTest
{
[Fact]
public void EventSource_ExistsWithCorrectId()
{
Type esType = typeof(SmtpClient).Assembly.GetType("System.Net.NetEventSource", throwOnError: true, ignoreCase: false);
Assert.NotNull(esType);
Assert.Equal("Private.InternalDiagnostics.System.Net.Mail", EventSource.GetName(esType));
Assert.Equal(Guid.Parse("6fff04ac-5aab-530c-03b3-b1b32d2538e9"), EventSource.GetGuid(esType));
Assert.NotEmpty(EventSource.GenerateManifest(esType, esType.Assembly.Location));
}
[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
public async Task EventSource_EventsRaisedAsExpected()
{
await RemoteExecutor.Invoke(() =>
{
using (var listener = new TestEventListener("Private.InternalDiagnostics.System.Net.Mail", EventLevel.Verbose))
{
var events = new ConcurrentQueue<EventWrittenEventArgs>();
listener.RunWithCallback(events.Enqueue, () =>
{
// Invoke a test that'll cause some events to be generated
new SmtpClientTest().TestMailDelivery();
});
Assert.DoesNotContain(events, ev => ev.EventId == 0); // errors from the EventSource itself
Assert.InRange(events.Count, 1, int.MaxValue);
}
}).DisposeAsync();
}
}
}