-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathAutoRetryTest.cs
64 lines (46 loc) · 1.2 KB
/
AutoRetryTest.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
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PostSharp.Samples.AutoRetry
{
[TestClass]
public class AutoRetryTest
{
int counter;
// Success tests: the number of failures is SMALLER than the number of retries.
[DataTestMethod]
[DataRow(0)]
[DataRow(1)]
[DataRow(2)]
public void SucceedingTest(int failures)
{
counter = 0;
TestMethod(failures);
}
// Failure tests: the number of failures is SMALLER than the number of retries.
[DataTestMethod]
[DataRow(3)]
[DataRow(4)]
[ExpectedException(typeof(TestException))]
public void FailingTest(int failures)
{
counter = 0;
TestMethod(failures);
}
[AutoRetry(MaxRetries = 3, HandledExceptions = new Type[] { typeof(TestException) }, Delay = 0)]
private void TestMethod(int failures)
{
this.counter++;
if (this.counter - 1 <= failures)
{
throw new TestException();
}
}
}
public class TestException : Exception
{
}
}