public void CompletedEvent() { // Arrange bool premature = true; bool eventFired = false; OutstandingAsyncOperations ops = new OutstandingAsyncOperations(); ops.Completed += (sender, eventArgs) => { if (premature) { Assert.Fail("Event fired too early!"); } if (eventFired) { Assert.Fail("Event fired multiple times."); } Assert.AreEqual(ops, sender); Assert.AreEqual(eventArgs, EventArgs.Empty); eventFired = true; }; // Act & assert ops.Increment(); // should not fire event (will throw exception) premature = false; ops.Decrement(); // should fire event Assert.IsTrue(eventFired); ops.Increment(); // should not fire event (will throw exception) }
public void CountStartsAtZero() { // Arrange OutstandingAsyncOperations ops = new OutstandingAsyncOperations(); // Act & assert Assert.AreEqual(0, ops.Count); }
public void IncrementWithNoArguments() { // Arrange OutstandingAsyncOperations ops = new OutstandingAsyncOperations(); // Act int returned = ops.Increment(); int newCount = ops.Count; // Assert Assert.AreEqual(1, returned); Assert.AreEqual(1, newCount); }
public void DecrementWithIntegerArgument() { // Arrange OutstandingAsyncOperations ops = new OutstandingAsyncOperations(); // Act int returned = ops.Decrement(3); int newCount = ops.Count; // Assert Assert.AreEqual(-3, returned); Assert.AreEqual(-3, newCount); }