root / trunk / Pithos.Core.Test / WorkflowFileStatusTest.cs @ 7f5882da
History | View | Annotate | Download (6.3 kB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Linq; |
4 |
using System.Text; |
5 |
using NUnit.Framework; |
6 |
|
7 |
|
8 |
namespace Pithos.Core.Test |
9 |
{ |
10 |
[TestFixture] |
11 |
public class WorkflowFileStatusTest |
12 |
{ |
13 |
private MockSettings _settings; |
14 |
private MockStatusChecker _statusChecker; |
15 |
|
16 |
[SetUp] |
17 |
public void SetUp() |
18 |
{ |
19 |
_settings = new MockSettings |
20 |
{ |
21 |
PithosPath = @"e:\Pithos", |
22 |
IconsPath = @"C:\Program Files\Common Files\TortoiseOverlays\icons\XPStyle" |
23 |
}; |
24 |
_statusChecker = new MockStatusChecker { Settings = _settings }; |
25 |
} |
26 |
|
27 |
[Test] |
28 |
public void TestSetFileStatusCreated() |
29 |
{ |
30 |
PithosWorkflow workflow = new PithosWorkflow { Settings = _settings, StatusKeeper = _statusChecker }; |
31 |
|
32 |
var path = @"e:\pithos\0File1.txt"; |
33 |
workflow.SetFileStatus(path, FileStatus.Created); |
34 |
var status = _statusChecker.GetFileStatus(path); |
35 |
Assert.AreEqual(FileStatus.Created, status); |
36 |
|
37 |
} |
38 |
|
39 |
[Test] |
40 |
public void TestSetFileStatusCreatedTransitions() |
41 |
{ |
42 |
IPithosWorkflow workflow = new PithosWorkflow { Settings = _settings, StatusKeeper = _statusChecker }; |
43 |
|
44 |
var path = @"e:\pithos\0File1.txt"; |
45 |
|
46 |
var initialStatus = FileStatus.Created; |
47 |
FileStatus[,] transitions = { { FileStatus.Modified, FileStatus.Created }, |
48 |
{ FileStatus.Created, FileStatus.Created }, |
49 |
{ FileStatus.Deleted, FileStatus.Deleted }, |
50 |
{ FileStatus.Renamed, FileStatus.Renamed }, |
51 |
{ FileStatus.Unchanged, FileStatus.Unchanged }, |
52 |
}; |
53 |
|
54 |
|
55 |
TestTransitions(transitions, workflow, path, initialStatus); |
56 |
} |
57 |
|
58 |
[Test] |
59 |
public void TestSetFileStatusModifiedTransitions() |
60 |
{ |
61 |
IPithosWorkflow workflow = new PithosWorkflow { Settings = _settings, StatusKeeper = _statusChecker }; |
62 |
|
63 |
var path = @"e:\pithos\0File1.txt"; |
64 |
|
65 |
var initialStatus = FileStatus.Modified; |
66 |
FileStatus[,] transitions = { { FileStatus.Modified, FileStatus.Modified }, |
67 |
{ FileStatus.Created, FileStatus.Modified }, |
68 |
{ FileStatus.Deleted, FileStatus.Deleted }, |
69 |
{ FileStatus.Renamed, FileStatus.Renamed }, |
70 |
{ FileStatus.Unchanged, FileStatus.Unchanged }, |
71 |
}; |
72 |
|
73 |
|
74 |
TestTransitions(transitions, workflow, path, initialStatus); |
75 |
} |
76 |
|
77 |
[Test] |
78 |
public void TestSetFileStatusUnchangedTransitions() |
79 |
{ |
80 |
IPithosWorkflow workflow = new PithosWorkflow { Settings = _settings, StatusKeeper = _statusChecker }; |
81 |
|
82 |
var path = @"e:\pithos\0File1.txt"; |
83 |
|
84 |
var initialStatus = FileStatus.Unchanged; |
85 |
FileStatus[,] transitions = { { FileStatus.Modified, FileStatus.Modified }, |
86 |
{ FileStatus.Created, FileStatus.Created }, |
87 |
{ FileStatus.Deleted, FileStatus.Deleted }, |
88 |
{ FileStatus.Renamed, FileStatus.Renamed }, |
89 |
{ FileStatus.Unchanged, FileStatus.Unchanged }, |
90 |
}; |
91 |
|
92 |
|
93 |
TestTransitions(transitions, workflow, path, initialStatus); |
94 |
} |
95 |
|
96 |
[Test] |
97 |
public void TestSetFileStatusDeletedTransitions() |
98 |
{ |
99 |
IPithosWorkflow workflow = new PithosWorkflow { Settings = _settings, StatusKeeper = _statusChecker }; |
100 |
|
101 |
var path = @"e:\pithos\0File1.txt"; |
102 |
|
103 |
var initialStatus = FileStatus.Deleted; |
104 |
FileStatus[,] transitions = { { FileStatus.Modified, FileStatus.Deleted }, |
105 |
{ FileStatus.Created, FileStatus.Deleted }, |
106 |
{ FileStatus.Deleted, FileStatus.Deleted }, |
107 |
{ FileStatus.Renamed, FileStatus.Deleted }, |
108 |
{ FileStatus.Unchanged, FileStatus.Deleted }, |
109 |
}; |
110 |
|
111 |
|
112 |
TestTransitions(transitions, workflow, path, initialStatus); |
113 |
} |
114 |
|
115 |
[Test] |
116 |
public void TestSetFileStatusRenamedTransitions() |
117 |
{ |
118 |
IPithosWorkflow workflow = new PithosWorkflow { Settings = _settings, StatusKeeper = _statusChecker }; |
119 |
|
120 |
var path = @"e:\pithos\0File1.txt"; |
121 |
|
122 |
var initialStatus = FileStatus.Renamed; |
123 |
FileStatus[,] transitions = { { FileStatus.Modified, FileStatus.Modified }, |
124 |
{ FileStatus.Created, FileStatus.Renamed }, |
125 |
{ FileStatus.Deleted, FileStatus.Deleted }, |
126 |
{ FileStatus.Renamed, FileStatus.Renamed }, |
127 |
{ FileStatus.Unchanged, FileStatus.Unchanged }, |
128 |
}; |
129 |
|
130 |
|
131 |
TestTransitions(transitions, workflow, path, initialStatus); |
132 |
} |
133 |
|
134 |
private void TestTransitions(FileStatus[,] transitions, IPithosWorkflow workflow, string path, FileStatus initialStatus) |
135 |
{ |
136 |
workflow.SetFileStatus(path, initialStatus); |
137 |
var status = _statusChecker.GetFileStatus(path); |
138 |
Assert.AreEqual(initialStatus, status, "Setting new file to {0}", status); |
139 |
for (int i = 0; i < transitions.GetLength(0); i++) |
140 |
{ |
141 |
workflow.ClearFileStatus(path); |
142 |
status = _statusChecker.GetFileStatus(path); |
143 |
Assert.AreEqual(FileStatus.Missing, status, "Clear status"); |
144 |
|
145 |
workflow.SetFileStatus(path, initialStatus); |
146 |
|
147 |
var transition = transitions[i, 0]; |
148 |
var result = transitions[i, 1]; |
149 |
workflow.SetFileStatus(path, transition); |
150 |
status = _statusChecker.GetFileStatus(path); |
151 |
Assert.AreEqual(result, status, "Marking {0} as {1}", initialStatus, transition); |
152 |
|
153 |
} |
154 |
} |
155 |
} |
156 |
} |