示例#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 CountStartsAtZero()
        {
            // Arrange
            OutstandingAsyncOperations ops = new OutstandingAsyncOperations();

            // Act & assert
            Assert.AreEqual(0, ops.Count);
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }