forked from lurumad/serilog-sinks-elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestDataHelper.cs
More file actions
45 lines (41 loc) · 1.5 KB
/
TestDataHelper.cs
File metadata and controls
45 lines (41 loc) · 1.5 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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace Serilog.Sinks.Elasticsearch.Tests
{
public static class TestDataHelper
{
public static string ReadEmbeddedResource(
Assembly assembly,
string embeddedResourceNameEndsWith)
{
var resourceNames = assembly.GetManifestResourceNames();
var resourceName = resourceNames.SingleOrDefault(n => n.EndsWith(embeddedResourceNameEndsWith));
if (string.IsNullOrEmpty(resourceName))
{
throw new ArgumentException(
string.Format(
"Could not find embedded resouce name that ends with '{0}', only found these: {1}",
embeddedResourceNameEndsWith,
string.Join(", ", resourceNames)),
"embeddedResourceNameEndsWith");
}
using (var stream = assembly.GetManifestResourceStream(resourceName))
{
if (stream == null)
{
throw new ArgumentException(
string.Format("Failed to open embedded resource stream for resource '{0}'", resourceName));
}
using (var streamReader = new StreamReader(stream))
{
return streamReader.ReadToEnd();
}
}
}
}
}