forked from JSONAPIdotNET/JSONAPI.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestHelpers.cs
More file actions
40 lines (37 loc) · 1.5 KB
/
Copy pathTestHelpers.cs
File metadata and controls
40 lines (37 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
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using FluentAssertions;
using JSONAPI.Json;
using Moq;
namespace JSONAPI.Tests
{
internal static class TestHelpers
{
public static string ReadEmbeddedFile(string path)
{
var resourcePath = "JSONAPI.Tests." + path.Replace("\\", ".").Replace("/", ".");
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourcePath))
{
if (stream == null) throw new Exception("Could not find a file at the path: " + path);
return new StreamReader(stream).ReadToEnd();
}
}
public static void StreamContentsMatchFixtureContents(MemoryStream stream, string fixtureFileName)
{
var output = System.Text.Encoding.ASCII.GetString(stream.ToArray());
var expectedJson = ReadEmbeddedFile(fixtureFileName);
var minifiedExpectedJson = JsonHelpers.MinifyJson(expectedJson);
output.Should().Be(minifiedExpectedJson);
}
public static void SetupIQueryable<T>(this Mock<T> mock, IQueryable queryable)
where T : class, IQueryable
{
mock.Setup(r => r.GetEnumerator()).Returns(queryable.GetEnumerator());
mock.Setup(r => r.Provider).Returns(queryable.Provider);
mock.Setup(r => r.ElementType).Returns(queryable.ElementType);
mock.Setup(r => r.Expression).Returns(queryable.Expression);
}
}
}