Skip to content

Commit e17703a

Browse files
authored
show snapshot testing (#620)
1 parent 429c58b commit e17703a

6 files changed

+69
-5
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ docs/api/*
2121
docs/_site/*
2222
docs/docfx/*
2323
docs/docfx.zip
24+
25+
*.received.*

test/Sentry.Tests/ModuleInit.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System.Collections.Generic;
2+
using System.Runtime.CompilerServices;
3+
using Sentry.Protocol;
4+
using VerifyTests;
5+
6+
namespace Sentry.Tests
7+
{
8+
public static class ModuleInit
9+
{
10+
[ModuleInitializer]
11+
public static void Init()
12+
{
13+
VerifierSettings.ModifySerialization(
14+
settings => settings.MemberConverter<Breadcrumb, IReadOnlyDictionary<string, string>>(
15+
target => target.Data,
16+
(_, value) =>
17+
{
18+
var dictionary = new Dictionary<string, string>();
19+
foreach (var pair in value)
20+
{
21+
if (pair.Key == "stackTrace")
22+
{
23+
dictionary[pair.Key] = Scrubbers.ScrubStackTrace(pair.Value, true);
24+
}
25+
else
26+
{
27+
dictionary[pair.Key] = pair.Value.Replace('\\','/');
28+
}
29+
}
30+
return dictionary;
31+
}));
32+
}
33+
}
34+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#if(!NET5_0)
2+
namespace System.Runtime.CompilerServices
3+
{
4+
[AttributeUsage(AttributeTargets.Method, Inherited = false)]
5+
public sealed class ModuleInitializerAttribute : Attribute
6+
{
7+
}
8+
}
9+
#endif

test/Sentry.Tests/Sentry.Tests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
<DefineConstants>NETFX;$(AdditionalConstants)</DefineConstants>
99
</PropertyGroup>
1010

11+
<ItemGroup>
12+
<PackageReference Include="Verify.Xunit" Version="8.11.0" />
13+
</ItemGroup>
14+
1115
<ItemGroup>
1216
<ProjectReference Include="../../src/Sentry/Sentry.csproj" />
1317
<ProjectReference Include="../Sentry.Testing/Sentry.Testing.csproj" />
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[
2+
{
3+
Timestamp: DateTimeOffset_1,
4+
Message: BeforeSend callback failed.,
5+
Data: {
6+
message: Exception message!,
7+
stackTrace:
8+
at Sentry.Tests.SentryClientTests.<>c__DisplayClass18_0.<CaptureEvent_BeforeEventThrows_ErrorToEventBreadcrumb>b__0(...)
9+
at Sentry.SentryClient.BeforeSend(...)
10+
},
11+
Category: SentryClient,
12+
Level: error
13+
}
14+
]

test/Sentry.Tests/SentryClientTests.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
using System;
22
using System.Linq;
33
using System.Net.Http;
4+
using System.Threading.Tasks;
45
using NSubstitute;
56
using Sentry.Extensibility;
67
using Sentry.Internal;
78
using Sentry.Protocol;
89
using Sentry.Protocol.Envelopes;
10+
using VerifyXunit;
11+
using VerifyTests;
912
using Xunit;
1013

1114
namespace Sentry.Tests
1215
{
16+
[UsesVerify]
1317
public class SentryClientTests
1418
{
1519
private class Fixture
@@ -252,7 +256,7 @@ public void CaptureEvent_SamplingNull_DropEvent()
252256
}
253257

254258
[Fact]
255-
public void CaptureEvent_BeforeEventThrows_ErrorToEventBreadcrumb()
259+
public Task CaptureEvent_BeforeEventThrows_ErrorToEventBreadcrumb()
256260
{
257261
var error = new Exception("Exception message!");
258262
_fixture.SentryOptions.BeforeSend = e => throw error;
@@ -262,10 +266,7 @@ public void CaptureEvent_BeforeEventThrows_ErrorToEventBreadcrumb()
262266
var sut = _fixture.GetSut();
263267
_ = sut.CaptureEvent(@event);
264268

265-
var crumb = @event.Breadcrumbs.First();
266-
Assert.Equal("BeforeSend callback failed.", crumb.Message);
267-
Assert.Equal(error.Message, crumb.Data["message"]);
268-
Assert.Equal(error.StackTrace, crumb.Data["stackTrace"]);
269+
return Verifier.Verify(@event.Breadcrumbs);
269270
}
270271

271272
[Fact]

0 commit comments

Comments
 (0)