Skip to content

Commit e35d823

Browse files
committed
Move json file deserializer to own file, so it can be reused
1 parent 2450411 commit e35d823

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed

Source/Tests/Plugins/DeduplicationBenchmarks.cs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,17 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.IO;
3+
using System.Linq;
44
using BenchmarkDotNet.Attributes;
5-
using Exceptionless.Extensions;
65
using Exceptionless.Models;
76
using Exceptionless.Plugins;
87
using Exceptionless.Plugins.Default;
9-
using Exceptionless.Serializer;
8+
using Exceptionless.Tests.Utility;
109

1110
namespace Exceptionless.Tests.Plugins {
1211
public class DeduplicationBenchmarks {
13-
private readonly List<Event> _events = new List<Event>();
12+
private readonly List<Event> _events;
1413
public DeduplicationBenchmarks() {
15-
foreach (var file in Directory.GetFiles(@"..\..\ErrorData", "*.json")) {
16-
_events.Add(GetEvent(file));
17-
}
18-
}
19-
protected virtual IJsonSerializer GetSerializer() {
20-
return new DefaultJsonSerializer();
21-
}
22-
23-
Event GetEvent(string fileName) {
24-
var json = File.ReadAllText(fileName);
25-
var serializer = GetSerializer();
26-
return serializer.Deserialize<Event>(json);
14+
_events = ErrorDataReader.GetEvents().ToList();
2715
}
2816

2917
[Benchmark]
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using Exceptionless.Extensions;
8+
using Exceptionless.Models;
9+
using Exceptionless.Serializer;
10+
11+
namespace Exceptionless.Tests.Utility
12+
{
13+
class ErrorDataReader
14+
{
15+
static IJsonSerializer GetSerializer()
16+
{
17+
return new DefaultJsonSerializer();
18+
}
19+
20+
static Event GetEvent(string fileName)
21+
{
22+
var json = File.ReadAllText(fileName);
23+
var serializer = GetSerializer();
24+
return serializer.Deserialize<Event>(json);
25+
}
26+
public static IEnumerable<Event> GetEvents() {
27+
return Directory.EnumerateFiles(@"..\..\ErrorData", "*.json").Select(GetEvent);
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)