document_download.cs
1.55 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using NUnit.Framework;
using System;
using System.IO;
using System.Net;
namespace MonoTests.KnowledgeTree
{
[TestFixture]
public class DocumentSystemMetadataTest : KTTest
{
private int _folderId;
private Document _doc1;
[SetUp]
public void SetUp()
{
this._folderId = 1;
this._doc1 = new Document(1, this._session, this._kt, this._verbose,false);
this._doc1.createFile(this._folderId);
}
[TearDown]
public void TearDown()
{
this._doc1.deleteFile();
}
[Test]
public void DownloadTest()
{
kt_response update_resp = this._kt.download_document(this._session, this._doc1.docId );
Assert.AreEqual(0, update_resp.status_code);
System.Console.WriteLine("Download...." + update_resp.message);
String uri = update_resp.message;
HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(uri);
WebResponse response = webrequest.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream());
String content = sr.ReadToEnd();
System.Console.WriteLine(content);
}
[Test]
public void SmallDownloadTest()
{
kt_response update_resp = this._kt.download_small_document(this._session, this._doc1.docId );
Assert.AreEqual(0, update_resp.status_code);
String filename = Helper.isUnix()?("/tmp/kt_unit_test_tmp.txt"):("c:\\kt_unit_test_tmp.txt");
long length = Helper.ConvertBase64EncodingToFile(update_resp.message, filename);
System.Console.WriteLine(Helper.readFile(filename));
// TODO - why???
Assert.AreEqual(length, this._doc1.filesize+1);
}
}
}