forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperationCounterTest.cs
More file actions
113 lines (93 loc) · 2.95 KB
/
Copy pathOperationCounterTest.cs
File metadata and controls
113 lines (93 loc) · 2.95 KB
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
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.TestCommon;
namespace System.Web.Mvc.Async.Test
{
public class OperationCounterTest
{
[Fact]
public void CompletedEvent()
{
// Arrange
bool premature = true;
bool eventFired = false;
OperationCounter ops = new OperationCounter();
ops.Completed += (sender, eventArgs) =>
{
if (premature)
{
Assert.True(false, "Event fired too early!");
}
if (eventFired)
{
Assert.True(false, "Event fired multiple times.");
}
Assert.Equal(ops, sender);
Assert.Equal(eventArgs, EventArgs.Empty);
eventFired = true;
};
// Act & assert
ops.Increment(); // should not fire event (will throw exception)
premature = false;
ops.Decrement(); // should fire event
Assert.True(eventFired);
ops.Increment(); // should not fire event (will throw exception)
}
[Fact]
public void CountStartsAtZero()
{
// Arrange
OperationCounter ops = new OperationCounter();
// Act & assert
Assert.Equal(0, ops.Count);
}
[Fact]
public void DecrementWithIntegerArgument()
{
// Arrange
OperationCounter ops = new OperationCounter();
// Act
int returned = ops.Decrement(3);
int newCount = ops.Count;
// Assert
Assert.Equal(-3, returned);
Assert.Equal(-3, newCount);
}
[Fact]
public void DecrementWithNoArguments()
{
// Arrange
OperationCounter ops = new OperationCounter();
// Act
int returned = ops.Decrement();
int newCount = ops.Count;
// Assert
Assert.Equal(-1, returned);
Assert.Equal(-1, newCount);
}
[Fact]
public void IncrementWithIntegerArgument()
{
// Arrange
OperationCounter ops = new OperationCounter();
// Act
int returned = ops.Increment(3);
int newCount = ops.Count;
// Assert
Assert.Equal(3, returned);
Assert.Equal(3, newCount);
}
[Fact]
public void IncrementWithNoArguments()
{
// Arrange
OperationCounter ops = new OperationCounter();
// Act
int returned = ops.Increment();
int newCount = ops.Count;
// Assert
Assert.Equal(1, returned);
Assert.Equal(1, newCount);
}
}
}