forked from Inumedia/SlackAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJoinDirectMessageChannel.cs
More file actions
49 lines (43 loc) · 1.61 KB
/
Copy pathJoinDirectMessageChannel.cs
File metadata and controls
49 lines (43 loc) · 1.61 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
using System;
using System.Linq;
using System.Threading;
using IntegrationTest.Configuration;
using IntegrationTest.Helpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Polly;
namespace IntegrationTest
{
[TestClass]
public class JoinDirectMessageChannel
{
private readonly Config _config;
public JoinDirectMessageChannel()
{
_config = Config.GetConfig();
}
[TestMethod]
public void ShouldJoinDirectMessageChannel()
{
// given
var client = ClientHelper.GetClient(_config.Slack.UserAuthToken);
string userName = _config.Slack.DirectMessageUser;
string user = client.Users.First(x => x.name.Equals(userName, StringComparison.InvariantCultureIgnoreCase)).id;
// when
EventWaitHandle wait = new EventWaitHandle(false, EventResetMode.ManualReset);
client.JoinDirectMessageChannel(response =>
{
Assert.IsTrue(response.ok, "Error while joining user channel");
Assert.IsTrue(!string.IsNullOrEmpty(response.channel.id), "We expected a channel id to be returned");
wait.Set();
}, user);
// then
Policy
.Handle<AssertFailedException>()
.WaitAndRetry(15, x => TimeSpan.FromSeconds(0.2), (exception, span) => Console.WriteLine("Retrying in {0} seconds", span.TotalSeconds))
.Execute(() =>
{
Assert.IsTrue(wait.WaitOne(), "Took too long to do the THING");
});
}
}
}