-
Notifications
You must be signed in to change notification settings - Fork 610
Expand file tree
/
Copy pathTestHttpRuntimeCacheStorage.cs
More file actions
63 lines (54 loc) · 2.14 KB
/
TestHttpRuntimeCacheStorage.cs
File metadata and controls
63 lines (54 loc) · 2.14 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
using System;
using System.Linq;
using StackExchange.Profiling.Storage;
using Xunit;
namespace StackExchange.Profiling.Tests.Storage
{
public class TestMemoryCacheStorage
{
private MiniProfilerOptions Options { get; }
public TestMemoryCacheStorage()
{
Options = new MiniProfilerOptions()
{
Storage = new MemoryCacheStorage(new TimeSpan(1, 0, 0))
};
}
[Fact]
public void TestWeCanSaveTheSameProfilerTwice()
{
Skip.IfNotWindows();
var profiler = new MiniProfiler("/", Options) { Started = DateTime.UtcNow, Id = Guid.NewGuid() };
Options.Storage.Save(profiler);
Options.Storage.Save(profiler);
var guids = Options.Storage.List(100).ToArray();
Assert.Equal(profiler.Id, guids[0]);
Assert.Single(guids);
}
[Fact]
public void TestRangeQueries()
{
Skip.IfNotWindows();
var now = DateTime.UtcNow;
var inASec = now.AddSeconds(1);
var in2Secs = now.AddSeconds(2);
var in3Secs = now.AddSeconds(3);
var profiler = new MiniProfiler("/", Options) { Started = now, Id = Guid.NewGuid() };
var profiler1 = new MiniProfiler("/", Options) { Started = inASec, Id = Guid.NewGuid() };
var profiler2 = new MiniProfiler("/", Options) { Started = in2Secs, Id = Guid.NewGuid() };
var profiler3 = new MiniProfiler("/", Options) { Started = in3Secs, Id = Guid.NewGuid() };
Options.Storage.Save(profiler);
Options.Storage.Save(profiler3);
Options.Storage.Save(profiler2);
Options.Storage.Save(profiler1);
var guids = Options.Storage.List(100);
Assert.Equal(4, guids.Count());
guids = Options.Storage.List(1);
Assert.Single(guids);
guids = Options.Storage.List(2, now, in2Secs);
Assert.Equal(profiler2.Id, guids.First());
Assert.Equal(profiler1.Id, guids.Skip(1).First());
Assert.Equal(2, guids.Count());
}
}
}