-
Notifications
You must be signed in to change notification settings - Fork 610
Expand file tree
/
Copy pathInternalErrorTests.cs
More file actions
67 lines (60 loc) · 2.78 KB
/
InternalErrorTests.cs
File metadata and controls
67 lines (60 loc) · 2.78 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
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using StackExchange.Profiling.Internal;
using StackExchange.Profiling.Storage;
using Xunit;
using Xunit.Abstractions;
namespace StackExchange.Profiling.Tests
{
public class InternalErrorTests : BaseTest
{
public InternalErrorTests(ITestOutputHelper output) : base(output) { }
[Fact]
public async Task StopErrorLogging()
{
int errorCount = 0;
Exception lastError = null;
void Log(Exception ex)
{
errorCount++;
lastError = ex;
}
var options = new MiniProfilerBaseOptions()
{
Storage = new KaboomStorage(),
StopwatchProvider = () => new UnitTestStopwatch(),
OnInternalError = Log
};
var profiler = options.StartProfiler();
AddRecursiveChildren(profiler, 1, 10);
Assert.Equal(0, errorCount);
profiler.Stop();
Assert.Equal(1, errorCount);
Assert.IsType<KaboomStorage.BoomBoom>(lastError);
profiler = options.StartProfiler();
AddRecursiveChildren(profiler, 1, 10);
Assert.Equal(1, errorCount);
await profiler.StopAsync().ConfigureAwait(false);
Assert.Equal(2, errorCount);
Assert.IsType<KaboomStorage.BoomBoom>(lastError);
}
}
public class KaboomStorage : IAsyncStorage
{
public List<Guid> GetUnviewedIds(string user) => throw new BoomBoom();
public Task<List<Guid>> GetUnviewedIdsAsync(string user) => throw new BoomBoom();
public IEnumerable<Guid> List(int maxResults, DateTime? start = null, DateTime? finish = null, ListResultsOrder orderBy = ListResultsOrder.Descending) => throw new BoomBoom();
public Task<IEnumerable<Guid>> ListAsync(int maxResults, DateTime? start = null, DateTime? finish = null, ListResultsOrder orderBy = ListResultsOrder.Descending) => throw new BoomBoom();
public MiniProfiler Load(Guid id) => throw new BoomBoom();
public Task<MiniProfiler> LoadAsync(Guid id) => throw new BoomBoom();
public void Save(MiniProfiler profiler) => throw new BoomBoom();
public Task SaveAsync(MiniProfiler profiler) => throw new BoomBoom();
public void SetUnviewed(string user, Guid id) => throw new BoomBoom();
public Task SetUnviewedAsync(string user, Guid id) => throw new BoomBoom();
public void SetViewed(string user, Guid id) => throw new BoomBoom();
public Task SetViewedAsync(string user, Guid id) => throw new BoomBoom();
public Task SetViewedAsync(string user, IEnumerable<Guid> ids) => throw new BoomBoom();
public class BoomBoom : Exception { }
}
}