コード例 #1
0
        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)
        }
コード例 #2
0
        public void DecrementWithNoArguments()
        {
            // Arrange
            OutstandingAsyncOperations ops = new OutstandingAsyncOperations();

            // Act
            int returned = ops.Decrement();
            int newCount = ops.Count;

            // Assert
            Assert.AreEqual(-1, returned);
            Assert.AreEqual(-1, newCount);
        }