-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConnect.cs
121 lines (97 loc) · 3.9 KB
/
Connect.cs
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
using NUnit.Framework;
using System;
using cmpctircd;
using System.Linq;
using cmpctircd.Configuration;
using System.Configuration;
using cmpctircd.Threading;
using System.Threading;
using System.Threading.Tasks;
using IrcDotNet;
namespace cmpctircd.Tests
{
public class ConnectTests
{
Task task;
IRCd ircd;
Log log;
CmpctConfigurationSection config;
IrcClient irc;
[SetUp]
public void Setup()
{
task = Task.Run(() => {
using(var sc = new QueuedSynchronizationContext()) {
config = CmpctConfigurationSection.GetConfiguration();
SynchronizationContext.SetSynchronizationContext(sc);
log = new Log();
ircd = new IRCd(log, config);
log.Initialise(ircd, config.Loggers.OfType<LoggerElement>().ToList());
ircd.Run();
sc.Run();
}
}
);
// Hack to give the IRCd long enough to listen before we start trying to connect to it
// TODO: Can we do without this?
task.Wait(100);
}
[TearDown]
public void Teardown() {
// TODO: Shut down the ircd/listener
ircd.Stop();
}
[Test]
public void TestBasicConnectAndRegistration() {
var client = new StandardIrcClient();
using(var connectedEvent = new ManualResetEventSlim(false)) {
var registrationInfo = new IrcUserRegistrationInfo() {
NickName = "cmpct_test",
Password = "",
UserName = "cmpct_test",
RealName = "cmpct_test"
};
client.Connected += (sender, e) => connectedEvent.Set();
client.Connect("127.0.0.1", 6667, false, registrationInfo);
if(!connectedEvent.Wait(100)) {
client.Dispose();
Assert.Fail("ConnectedEvent not called: server not listening?");
}
using(var registrationEvent = new ManualResetEventSlim(false)) {
client.Registered += (sender, e) => registrationEvent.Set();
if(!registrationEvent.Wait(500)) {
client.Dispose();
Assert.Fail("RegistrationEvent not called: not registered?");
}
}
}
}
[Test]
public void TestJoinChannel() {
var client = new StandardIrcClient();
var registrationInfo = new IrcUserRegistrationInfo() {
NickName = "cmpct_test",
Password = "",
UserName = "cmpct_test",
RealName = "cmpct_test"
};
client.Connect("127.0.0.1", 6667, false, registrationInfo);
using(var registrationEvent = new ManualResetEventSlim(false)) {
// Need to include the registration check for the delay
client.Registered += (sender, e) => registrationEvent.Set();
if(!registrationEvent.Wait(500)) {
client.Dispose();
Assert.Fail("RegistrationEvent not called: not registered?");
}
}
using(var joinedChannelEvent = new ManualResetEventSlim(false)) {
client.LocalUser.JoinedChannel += (sender, e) => joinedChannelEvent.Set();
client.Channels.Join("#test");
if(!joinedChannelEvent.Wait(500)) {
client.Dispose();
Assert.Fail("JoinedChannelEvent not called: channel not joined?");
}
}
}
}
}