forked from restsharp/RestSharp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFileTests.cs
55 lines (46 loc) · 1.86 KB
/
FileTests.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.IO;
using NUnit.Framework;
using RestSharp.IntegrationTests.Helpers;
namespace RestSharp.IntegrationTests
{
[TestFixture]
public class FileTests
{
[Test]
public void Handles_Binary_File_Download()
{
Uri baseUrl = new Uri("http://localhost:8888/");
using (SimpleServer.Create(baseUrl.AbsoluteUri, Handlers.FileHandler))
{
RestClient client = new RestClient(baseUrl);
RestRequest request = new RestRequest("Assets/Koala.jpg");
byte[] response = client.DownloadData(request);
byte[] expected = File.ReadAllBytes(Environment.CurrentDirectory + "\\Assets\\Koala.jpg");
Assert.AreEqual(expected, response);
}
}
[Test]
public void Writes_Response_To_Stream()
{
const string baseUrl = "http://localhost:8888/";
using (SimpleServer.Create(baseUrl, Handlers.FileHandler))
{
string tempFile = Path.GetTempFileName();
using (FileStream writer = File.OpenWrite(tempFile))
{
RestClient client = new RestClient(baseUrl);
RestRequest request = new RestRequest("Assets/Koala.jpg")
{
ResponseWriter = (responseStream) => responseStream.CopyTo(writer)
};
byte[] response = client.DownloadData(request);
Assert.Null(response);
}
byte[] fromTemp = File.ReadAllBytes(tempFile);
byte[] expected = File.ReadAllBytes(Environment.CurrentDirectory + "\\Assets\\Koala.jpg");
Assert.AreEqual(expected, fromTemp);
}
}
}
}