-
Notifications
You must be signed in to change notification settings - Fork 225
/
IntegrationContextTests.cs
87 lines (81 loc) · 2.7 KB
/
IntegrationContextTests.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
namespace CruiseControl.Core.Tests
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using System.Threading;
[TestFixture]
public class IntegrationContextTests
{
#region Tests
[Test]
public void ConstructorSetsProject()
{
var project = new Project();
var context = new IntegrationContext(project);
Assert.AreSame(project, context.Item);
}
[Test]
public void WaitWillTimeoutIfNotReleased()
{
var project = new Project();
var context = new IntegrationContext(project);
context.Lock();
var released = context.Wait(TimeSpan.FromMilliseconds(5));
Assert.IsFalse(released);
Assert.IsFalse(context.WasCancelled);
}
[Test]
public void WaitWillContinueIfNotLocked()
{
var project = new Project();
var context = new IntegrationContext(project);
var released = context.Wait(TimeSpan.FromMilliseconds(5));
Assert.IsTrue(released);
}
[Test]
public void WaitWillContinueWhenReleased()
{
var project = new Project();
var context = new IntegrationContext(project);
var releaseThread = new Thread(o =>
{
Thread.Sleep(TimeSpan.FromSeconds(1));
context.Release();
});
releaseThread.Start();
context.Lock();
var released = context.Wait(TimeSpan.FromSeconds(5));
Assert.IsTrue(released);
}
[Test]
public void CompletedIsFiredOnComplete()
{
var project = new Project();
var context = new IntegrationContext(project);
var wasFired = false;
context.Completed += (o, e) => wasFired = true;
context.Complete();
Assert.IsTrue(wasFired);
}
[Test]
public void CancelWillReleaseALock()
{
var project = new Project();
var context = new IntegrationContext(project);
var releaseThread = new Thread(o =>
{
Thread.Sleep(TimeSpan.FromSeconds(1));
context.Cancel();
});
releaseThread.Start();
context.Lock();
var released = context.Wait(TimeSpan.FromSeconds(5));
Assert.IsFalse(released);
Assert.IsTrue(context.WasCancelled);
}
#endregion
}
}