-
Notifications
You must be signed in to change notification settings - Fork 238
Expand file tree
/
Copy pathIntegrationFixture.cs
More file actions
executable file
·70 lines (58 loc) · 2.42 KB
/
IntegrationFixture.cs
File metadata and controls
executable file
·70 lines (58 loc) · 2.42 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
using Newtonsoft.Json;
using SlackAPI.Tests.Helpers;
using System;
using System.IO;
using System.Reflection;
using Xunit;
namespace SlackAPI.Tests.Configuration
{
public class IntegrationFixture : IDisposable
{
public IntegrationFixture()
{
this.Config = this.GetConfig();
this.UserClient = this.GetClient(this.Config.UserAuthToken);
this.UserClientWithPresence = this.GetClient(this.Config.UserAuthToken, new[] { new Tuple<string, string>("batch_presence_aware", "true") });
this.BotClient = this.GetClient(this.Config.BotAuthToken);
}
public SlackConfig Config { get; }
public SlackSocketClient UserClient { get; }
public SlackSocketClient UserClientWithPresence { get; }
public SlackSocketClient BotClient { get; }
public void Dispose()
{
this.UserClient.CloseSocket();
this.UserClientWithPresence.CloseSocket();
this.BotClient.CloseSocket();
}
private SlackConfig GetConfig()
{
var currentAssembly = this.GetType().GetTypeInfo().Assembly.Location;
var assemblyDirectory = Path.GetDirectoryName(currentAssembly);
string fileName = Path.Combine(assemblyDirectory, @"configuration\config.json");
string json = System.IO.File.ReadAllText(fileName);
var jsonObject = new { slack = (SlackConfig)null };
return JsonConvert.DeserializeAnonymousType(json, jsonObject).slack;
}
private SlackSocketClient GetClient(string authToken, Tuple<string, string>[] loginParameters = null)
{
SlackSocketClient client;
using (var syncClient = new InSync($"{nameof(SlackClient.Connect)} - Connected callback"))
using (var syncClientSocket = new InSync($"{nameof(SlackClient.Connect)} - SocketConnected callback"))
{
client = new SlackSocketClient(authToken, loginParameters);
client.Connect(x =>
{
Console.WriteLine("Connected");
syncClient.Proceed();
}, () =>
{
Console.WriteLine("Socket Connected");
syncClientSocket.Proceed();
});
}
Assert.True(client.IsConnected, "Doh, still isn't connected");
return client;
}
}
}