forked from Inumedia/SlackAPI
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPostMessage.cs
More file actions
125 lines (110 loc) · 3.64 KB
/
Copy pathPostMessage.cs
File metadata and controls
125 lines (110 loc) · 3.64 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using System;
using SlackAPI.RPCMessages;
using SlackAPI.Tests.Configuration;
using SlackAPI.Tests.Helpers;
using System.Linq;
using Xunit;
namespace SlackAPI.Tests
{
[Collection("Integration tests")]
public class PostMessage
{
private readonly IntegrationFixture fixture;
public PostMessage(IntegrationFixture fixture)
{
this.fixture = fixture;
}
[Fact]
public void SimpleMessageDelivery()
{
// given
var client = this.fixture.UserClient;
PostMessageResponse actual = null;
// when
using (var sync = new InSync(nameof(SlackClient.PostMessage)))
{
client.PostMessage(
response =>
{
actual = response;
sync.Proceed();
},
this.fixture.Config.TestChannel,
"Hi there!");
}
// then
Assert.True(actual.ok, "Error while posting message to channel. ");
Assert.Equal("Hi there!", actual.message.text);
Assert.Equal("message", actual.message.type);
}
[Fact]
public void Attachments()
{
// given
var client = this.fixture.UserClient;
PostMessageResponse actual = null;
// when
using (var sync = new InSync(nameof(SlackClient.PostMessage)))
{
client.PostMessage(
response =>
{
actual = response;
sync.Proceed();
},
this.fixture.Config.TestChannel,
string.Empty,
attachments: SlackMother.SomeAttachments);
}
// then
Assert.True(actual.ok, "Error while posting message to channel. ");
}
[Fact]
public void AttachmentsWithActions()
{
// given
var client = this.fixture.UserClient;
PostMessageResponse actual = null;
// when
using (var sync = new InSync())
{
client.PostMessage(
response =>
{
actual = response;
sync.Proceed();
},
this.fixture.Config.TestChannel,
string.Empty,
attachments: SlackMother.SomeAttachmentsWithActions);
}
// then
Assert.True(actual.ok, "Error while posting message to channel. ");
}
[Fact]
public void PostEphemeralMessage()
{
// given
var client = this.fixture.UserClient;
PostEphemeralResponse actual = null;
string userName = this.fixture.Config.DirectMessageUser;
string userId = client.Users.First(x => x.name.Equals(userName, StringComparison.OrdinalIgnoreCase)).id;
// when
using (var sync = new InSync(nameof(SlackClient.PostEphemeralMessage)))
{
client.PostEphemeralMessage(
response =>
{
actual = response;
sync.Proceed();
},
this.fixture.Config.TestChannel,
"Hi there!",
userId);
}
// then
Assert.True(actual.ok, "Error while posting message to channel. ");
Assert.Null(actual.error);
}
}
}