forked from anthonyreilly/NetCoreForce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMockReponse.cs
40 lines (36 loc) · 1.16 KB
/
MockReponse.cs
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.Net;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;
using NetCoreForce.Client;
using Xunit;
namespace NetCoreForce.Client.Tests
{
public static class MockResponse
{
const string subfolder = "responses";
public static HttpResponseMessage GetResponse(string filename, HttpStatusCode statusCode)
{
HttpResponseMessage msg = new HttpResponseMessage(statusCode);
msg.Content = new StringContent(GetFileContent(filename));
return msg;
}
public static string GetFileContent(string filename)
{
try
{
string executabledirectory = System.IO.Directory.GetCurrentDirectory();
string filePath = Path.Combine(executabledirectory, subfolder, filename);
string contents = File.ReadAllText(filePath);
return contents;
}
catch (Exception ex)
{
Console.WriteLine(string.Format("Error reading file [{0}]: {1}", filename, ex.Message));
throw;
}
}
}
}