/
FormattingServicesTests.cs
181 lines (160 loc) · 4.6 KB
/
FormattingServicesTests.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#region License Statement
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// The use and distribution terms for this software are covered by the
// Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
// which can be found in the file CPL.TXT at the root of this distribution.
// By using this software in any fashion, you are agreeing to be bound by
// the terms of this license.
//
// You must not remove this notice, or any other, from this software.
#endregion
using System;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Specialized;
using System.Text.RegularExpressions;
using System.Reflection;
using FlexWiki.Formatting;
using FlexWiki;
using NUnit.Framework;
namespace FlexWiki.UnitTests
{
[TestFixture]
[Ignore("This test disabled during the 2.0 upgrade. Re-enable as functionality is implemented.")]
public class FormattingServicesTests
{
private Federation _federation;
private LinkMaker _lm;
private NamespaceManager _storeManager;
private ArrayList _versions;
private Federation Federation
{
get { return _federation; }
set { _federation = value; }
}
private NamespaceManager StoreManager
{
get { return _storeManager; }
}
[SetUp]
public void SetUp()
{
string author = "tester-joebob";
_lm = new LinkMaker("http://bogusville");
MockWikiApplication application = new MockWikiApplication(
null,
_lm,
OutputFormat.HTML,
new MockTimeProvider(TimeSpan.FromSeconds(1)));
Federation = new Federation(application);
_versions = new ArrayList();
_storeManager = WikiTestUtilities.CreateMockStore(Federation, "FlexWiki.Base");
WikiTestUtilities.WriteTestTopicAndNewVersion(_storeManager, "TopicOne", @"1
2
3
4
5
6
7
8
9", author);
System.Threading.Thread.Sleep(100); // need the newer one to be newer enough!
WikiTestUtilities.WriteTestTopicAndNewVersion(_storeManager, "TopicOne", @"1
2
a
b
c
3
4
5
6
7
8
9", author);
System.Threading.Thread.Sleep(100); // need the newer one to be newer enough!
WikiTestUtilities.WriteTestTopicAndNewVersion(_storeManager, "TopicOne", @"1
2
a
b
6
7
8
9", author);
foreach (TopicChange change in _storeManager.AllChangesForTopic("TopicOne"))
_versions.Add(change.Version);
}
[TearDown]
public void TearDown()
{
_storeManager.DeleteAllTopicsAndHistory();
}
[Test]
public void OldestTest()
{
// Test the oldest; should have no markers
VersionCompare("TopicOne", (string) _versions[_versions.Count - 1], @"<p>1</p>
<p>2</p>
<p>3</p>
<p>4</p>
<p>5</p>
<p>6</p>
<p>7</p>
<p>8</p>
<p>9</p>
");
}
[Test]
public void InsertTest()
{
// Inserts oldest should have the
VersionCompare("TopicOne", (string) _versions[_versions.Count - 2], @"<p>1</p>
<p>2</p>
<p style=""background: palegreen"">a</p>
<p style=""background: palegreen"">b</p>
<p style=""background: palegreen"">c</p>
<p>3</p>
<p>4</p>
<p>5</p>
<p>6</p>
<p>7</p>
<p>8</p>
<p>9</p>
");
}
[Test]
public void DeleteTest()
{
VersionCompare("TopicOne", (string) _versions[_versions.Count - 3], @"<p>1</p>
<p>2</p>
<p>a</p>
<p>b</p>
<p style=""color: silver; text-decoration: line-through"">c</p>
<p style=""color: silver; text-decoration: line-through"">3</p>
<p style=""color: silver; text-decoration: line-through"">4</p>
<p style=""color: silver; text-decoration: line-through"">5</p>
<p>6</p>
<p>7</p>
<p>8</p>
<p>9</p>
");
}
private void VersionCompare(string topic, string version, string expecting)
{
QualifiedTopicRevision latest = new QualifiedTopicRevision(StoreManager.QualifiedTopicNameFor(topic));
latest.Version = version;
QualifiedTopicRevision oldTopic = StoreManager.VersionPreviousTo(
latest.LocalName, latest.Version);
string got = Formatter.FormattedTopic(latest, OutputFormat.Testing, oldTopic, Federation, _lm);
got = got.Replace("\r", "");
string o2 = expecting.Replace("\r", "");
if (got != o2)
{
Console.Error.WriteLine("Got : " + got);
Console.Error.WriteLine("Expected: " + o2);
}
Assert.AreEqual(o2, got);
}
}
}