Skip to content

Commit a4c3458

Browse files
committed
SEBWIN-1058: Fixed assertion paradigm changes in unit tests.
1 parent 340dfbf commit a4c3458

File tree

14 files changed

+63
-92
lines changed

14 files changed

+63
-92
lines changed

SafeExamBrowser.Browser.UnitTests/Filters/RequestFilterTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ public void MustReturnDefaultWithoutRules()
102102
}
103103

104104
[TestMethod]
105-
[ExpectedException(typeof(NotImplementedException))]
106105
public void MustNotAllowUnsupportedResult()
107106
{
108107
var rule = new Mock<IRule>();
109108

110109
rule.SetupGet(r => r.Result).Returns((FilterResult) (-1));
111-
sut.Load(rule.Object);
110+
111+
Assert.ThrowsExactly<NotImplementedException>(() => sut.Load(rule.Object));
112112
}
113113
}
114114
}

SafeExamBrowser.Browser.UnitTests/Filters/RuleFactoryTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ public void MustCreateCorrectRules()
3333
}
3434

3535
[TestMethod]
36-
[ExpectedException(typeof(NotImplementedException))]
3736
public void MustNotAllowUnsupportedFilterType()
3837
{
39-
sut.CreateRule((FilterRuleType) (-1));
38+
Assert.ThrowsExactly<NotImplementedException>(() => sut.CreateRule((FilterRuleType) (-1)));
4039
}
4140
}
4241
}

SafeExamBrowser.Browser.UnitTests/Filters/Rules/RegexRuleTests.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,15 @@ public void MustInitializeResult()
5151
}
5252

5353
[TestMethod]
54-
[ExpectedException(typeof(ArgumentNullException))]
5554
public void MustNotAllowUndefinedExpression()
5655
{
57-
sut.Initialize(new FilterRuleSettings());
56+
Assert.ThrowsExactly<ArgumentNullException>(() => sut.Initialize(new FilterRuleSettings()));
5857
}
5958

6059
[TestMethod]
61-
[ExpectedException(typeof(ArgumentException))]
6260
public void MustValidateExpression()
6361
{
64-
sut.Initialize(new FilterRuleSettings { Expression = "ç+\"}%&*/(+)=?{=*+¦]@#°§]`?´^¨'°[¬|¢" });
62+
Assert.ThrowsExactly<ArgumentException>(() => sut.Initialize(new FilterRuleSettings { Expression = "ç+\"}%&*/(+)=?{=*+¦]@#°§]`?´^¨'°[¬|¢" }));
6563
}
6664
}
6765
}

SafeExamBrowser.Browser.UnitTests/Filters/Rules/SimplifiedRuleTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@ public void MustInitializeResult()
5151
}
5252

5353
[TestMethod]
54-
[ExpectedException(typeof(ArgumentNullException))]
5554
public void MustNotAllowUndefinedExpression()
5655
{
57-
sut.Initialize(new FilterRuleSettings());
56+
Assert.ThrowsExactly<ArgumentNullException>(() => sut.Initialize(new FilterRuleSettings()));
5857
}
5958

6059
[TestMethod]
@@ -73,7 +72,7 @@ public void MustValidateExpression()
7372

7473
foreach (var expression in invalid)
7574
{
76-
Assert.ThrowsException<ArgumentException>(() => sut.Initialize(new FilterRuleSettings { Expression = expression }));
75+
Assert.ThrowsExactly<ArgumentException>(() => sut.Initialize(new FilterRuleSettings { Expression = expression }));
7776
}
7877
}
7978

SafeExamBrowser.Communication.UnitTests/Hosts/BaseHostTests.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,11 @@ public void MustCorrectlyStartHost()
5353
}
5454

5555
[TestMethod]
56-
[ExpectedException(typeof(CommunicationException))]
5756
public void MustCorrectlyHandleStartupException()
5857
{
5958
hostObject.Setup(h => h.Open()).Throws<Exception>();
6059

61-
sut.Start();
60+
Assert.ThrowsExactly<CommunicationException>(() => sut.Start());
6261
}
6362

6463
[TestMethod]
@@ -71,13 +70,12 @@ public void MustCorrectlyStopHost()
7170
}
7271

7372
[TestMethod]
74-
[ExpectedException(typeof(CommunicationException))]
7573
public void MustCorrectlyHandleShutdownException()
7674
{
7775
hostObject.Setup(h => h.Close()).Throws<Exception>();
78-
7976
sut.Start();
80-
sut.Stop();
77+
78+
Assert.ThrowsExactly<CommunicationException>(() => sut.Stop());
8179
}
8280

8381
[TestMethod]

SafeExamBrowser.Communication.UnitTests/Proxies/BaseProxyTests.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,12 @@ public void MustFailToDisconnectIfChannelNotOpen()
171171
}
172172

173173
[TestMethod]
174-
[ExpectedException(typeof(InvalidOperationException))]
175174
public void MustFailToSendIfNotConnected()
176175
{
177-
sut.Send(new Mock<Message>().Object);
176+
Assert.ThrowsExactly<InvalidOperationException>(() => sut.Send(new Mock<Message>().Object));
178177
}
179178

180179
[TestMethod]
181-
[ExpectedException(typeof(InvalidOperationException))]
182180
public void MustFailToSendIfChannelNotOpen()
183181
{
184182
var proxy = new Mock<IProxyObject>();
@@ -195,14 +193,14 @@ public void MustFailToSendIfChannelNotOpen()
195193
var token = Guid.NewGuid();
196194

197195
sut.Connect(token);
198-
sut.Send(new Mock<Message>().Object);
196+
197+
Assert.ThrowsExactly<InvalidOperationException>(() => sut.Send(new Mock<Message>().Object));
199198
}
200199

201200
[TestMethod]
202-
[ExpectedException(typeof(ArgumentNullException))]
203201
public void MustNotAllowSendingNull()
204202
{
205-
sut.Send(null);
203+
Assert.ThrowsExactly<ArgumentNullException>(() => sut.Send(null));
206204
}
207205

208206
[TestMethod]

SafeExamBrowser.Configuration.UnitTests/Cryptography/KeyGeneratorTests.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,15 @@ public void Initialize()
3636
}
3737

3838
[TestMethod]
39-
[ExpectedException(typeof(Exception), AllowDerivedTypes = true)]
4039
public void CalculateBrowserExamKeyHash_MustFailWithoutUrl()
4140
{
42-
sut.CalculateBrowserExamKeyHash(default, default, default);
41+
Assert.Throws<Exception>(() => sut.CalculateBrowserExamKeyHash(default, default, default));
4342
}
4443

4544
[TestMethod]
46-
[ExpectedException(typeof(Exception), AllowDerivedTypes = true)]
4745
public void CalculateConfigurationKeyHash_MustFailWithoutUrl()
4846
{
49-
sut.CalculateConfigurationKeyHash(default, default);
47+
Assert.Throws<Exception>(() => sut.CalculateConfigurationKeyHash(default, default));
5048
}
5149

5250
[TestMethod]

SafeExamBrowser.Configuration.UnitTests/SubStreamTests.cs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,56 +132,49 @@ public void MustSeekCorrectly()
132132
}
133133

134134
[TestMethod]
135-
[ExpectedException(typeof(ArgumentException))]
136135
public void MustNotAllowNonReadableStream()
137136
{
138137
stream.SetupGet(s => s.CanRead).Returns(false);
139138

140-
new SubStream(stream.Object, 0, 0);
139+
Assert.ThrowsExactly<ArgumentException>(() => new SubStream(stream.Object, 0, 0));
141140
}
142141

143142
[TestMethod]
144-
[ExpectedException(typeof(ArgumentException))]
145143
public void MustNotAllowNonSeekableStream()
146144
{
147145
stream.SetupGet(s => s.CanSeek).Returns(false);
148146

149-
new SubStream(stream.Object, 0, 0);
147+
Assert.ThrowsExactly<ArgumentException>(() => new SubStream(stream.Object, 0, 0));
150148
}
151149

152150
[TestMethod]
153-
[ExpectedException(typeof(ArgumentOutOfRangeException))]
154151
public void MustNotAllowOffsetSmallerThanZero()
155152
{
156-
new SubStream(stream.Object, -1, 100);
153+
Assert.ThrowsExactly<ArgumentOutOfRangeException>(() => new SubStream(stream.Object, -1, 100));
157154
}
158155

159156
[TestMethod]
160-
[ExpectedException(typeof(ArgumentOutOfRangeException))]
161157
public void MustNotAllowLengthSmallerThanOne()
162158
{
163-
new SubStream(stream.Object, 100, 0);
159+
Assert.ThrowsExactly<ArgumentOutOfRangeException>(() => new SubStream(stream.Object, 100, 0));
164160
}
165161

166162
[TestMethod]
167-
[ExpectedException(typeof(NotSupportedException))]
168163
public void MustNotSupportFlushing()
169164
{
170-
new SubStream(stream.Object, 100, 100).Flush();
165+
Assert.ThrowsExactly<NotSupportedException>(() => new SubStream(stream.Object, 100, 100).Flush());
171166
}
172167

173168
[TestMethod]
174-
[ExpectedException(typeof(NotSupportedException))]
175169
public void MustNotSupportChangingLength()
176170
{
177-
new SubStream(stream.Object, 100, 100).SetLength(100);
171+
Assert.ThrowsExactly<NotSupportedException>(() => new SubStream(stream.Object, 100, 100).SetLength(100));
178172
}
179173

180174
[TestMethod]
181-
[ExpectedException(typeof(NotSupportedException))]
182175
public void MustNotSupportWriting()
183176
{
184-
new SubStream(stream.Object, 100, 100).Write(new byte[0], 0, 0);
177+
Assert.ThrowsExactly<NotSupportedException>(() => new SubStream(stream.Object, 100, 100).Write(new byte[0], 0, 0));
185178
}
186179
}
187180
}

SafeExamBrowser.Core.UnitTests/Operations/LazyInitializationOperationTests.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ IOperation initialize()
3636
initialized = true;
3737

3838
return operationMock.Object;
39-
}
40-
;
39+
};
4140

4241
var sut = new LazyInitializationOperation(initialize);
4342

@@ -47,18 +46,16 @@ IOperation initialize()
4746
}
4847

4948
[TestMethod]
50-
[ExpectedException(typeof(NullReferenceException))]
5149
public void MustNotInstantiateOperationOnRevert()
5250
{
5351
IOperation initialize()
5452
{
5553
return operationMock.Object;
56-
}
57-
;
54+
};
5855

5956
var sut = new LazyInitializationOperation(initialize);
6057

61-
sut.Revert();
58+
Assert.ThrowsExactly<NullReferenceException>(() => sut.Revert());
6259
}
6360

6461
[TestMethod]
@@ -67,8 +64,7 @@ public void MustReturnCorrectOperationResult()
6764
IOperation initialize()
6865
{
6966
return operationMock.Object;
70-
}
71-
;
67+
};
7268

7369
operationMock.Setup(o => o.Perform()).Returns(OperationResult.Success);
7470
operationMock.Setup(o => o.Revert()).Returns(OperationResult.Failed);
@@ -87,8 +83,7 @@ public void MustCorrectlyHandleEventSubscription()
8783
IOperation initialize()
8884
{
8985
return operationMock.Object;
90-
}
91-
;
86+
};
9287

9388
var statusChanged = 0;
9489
var statusChangedHandler = new StatusChangedEventHandler(t => statusChanged++);
@@ -130,8 +125,7 @@ IOperation initialize()
130125
}
131126

132127
return new Mock<IOperation>().Object;
133-
}
134-
;
128+
};
135129

136130
var sut = new LazyInitializationOperation(initialize);
137131

SafeExamBrowser.I18n.UnitTests/XmlTextResourceTests.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,14 @@ public void MustCorrectlyLoadData()
3535
}
3636

3737
[TestMethod]
38-
[ExpectedException(typeof(XmlException))]
3938
public void MustFailWithInvalidData()
4039
{
4140
var location = Assembly.GetAssembly(typeof(XmlTextResourceTests)).Location;
4241
var path = $@"{Path.GetDirectoryName(location)}\Text_Invalid.txt";
4342
var stream = new FileStream(path, FileMode.Open, FileAccess.Read);
4443
var sut = new XmlTextResource(stream);
4544

46-
sut.LoadText();
45+
Assert.ThrowsExactly<XmlException>(() => sut.LoadText());
4746
}
4847

4948
[TestMethod]
@@ -75,10 +74,9 @@ public void MustNeverSetNullValue()
7574
}
7675

7776
[TestMethod]
78-
[ExpectedException(typeof(ArgumentNullException))]
7977
public void MustNotAcceptNullAsPath()
8078
{
81-
new XmlTextResource(null);
79+
Assert.ThrowsExactly<ArgumentNullException>(() => new XmlTextResource(null));
8280
}
8381

8482
[TestMethod]

0 commit comments

Comments
 (0)