forked from Inumedia/SlackAPI
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathUploadFile.cs
More file actions
75 lines (67 loc) · 2.49 KB
/
Copy pathUploadFile.cs
File metadata and controls
75 lines (67 loc) · 2.49 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
70
71
72
73
74
75
using System;
using System.Linq;
using System.Threading.Tasks;
using SlackAPI.Tests.Configuration;
using SlackAPI.Tests.Helpers;
using Xunit;
namespace SlackAPI.Tests
{
[Collection("Integration tests")]
public class UploadFile
{
private readonly IntegrationFixture fixture;
public UploadFile(IntegrationFixture fixture)
{
this.fixture = fixture;
}
[Fact]
public void UploadFile_Succeeds()
{
// Arrange
const int FileSize = 500;
const string FileName = "MyFile.bin";
byte[] data = new byte[FileSize];
// Act
FileUploadResponse fileUploadResponse = null;
using (var sync = new InSync(nameof(SlackClient.UploadFile)))
{
this.fixture.UserClient.UploadFile(c =>
{
fileUploadResponse = c;
Assert.True(c.ok);
sync.Proceed();
},
data, FileName, new[] {this.fixture.Config.TestChannel});
}
// Assert
using (var sync = new InSync(nameof(SlackClient.UploadFile)))
{
this.fixture.UserClient.GetFileInfo(c =>
{
Assert.True(c.ok);
Assert.Equal(FileSize, c.file.size);
Assert.Equal(FileName, c.file.name);
Assert.Equal(new[] { this.fixture.Config.TestChannel}, c.file.channels);
sync.Proceed();
}, fileUploadResponse.file.id);
}
}
[Fact]
public async Task UploadFileAsync_Succeeds()
{
// Arrange
const int FileSize = 500;
const string FileName = "MyFile.bin";
byte[] data = new byte[FileSize];
// Act
var fileUploadResponse = await this.fixture.UserClientAsync.UploadFileAsync(data, FileName, new[] { this.fixture.Config.TestChannel });
// Assert
Assert.True(fileUploadResponse.ok);
var fileInfoResponse = await this.fixture.UserClientAsync.GetFileInfoAsync(fileUploadResponse.file.id);
Assert.True(fileInfoResponse.ok);
Assert.Equal(FileSize, fileInfoResponse.file.size);
Assert.Equal(FileName, fileInfoResponse.file.name);
Assert.Equal(new[] { this.fixture.Config.TestChannel}, fileInfoResponse.file.channels);
}
}
}