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)
        }
        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)
        }
        public void CountStartsAtZero() {
            // Arrange
            OperationCounter ops = new OperationCounter();

            // Act & assert
            Assert.AreEqual(0, ops.Count);
        }
        public void CountStartsAtZero()
        {
            // Arrange
            OperationCounter ops = new OperationCounter();

            // Act & assert
            Assert.Equal(0, ops.Count);
        }
예제 #5
0
 public AsyncManager(SynchronizationContext context)
 {
     _context                          = context ?? SynchronizationContextExtensions.GetSynchronizationContext();
     _parameters                       = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);
     _outstandingOperations            = new OperationCounter();
     _outstandingOperations.Completed += delegate {
         Finish();
     };
 }
        public void IncrementWithIntegerArgument() {
            // Arrange
            OperationCounter ops = new OperationCounter();

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

            // Assert
            Assert.AreEqual(3, returned);
            Assert.AreEqual(3, newCount);
        }
        public void DecrementWithNoArguments() {
            // Arrange
            OperationCounter ops = new OperationCounter();

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

            // Assert
            Assert.AreEqual(-1, returned);
            Assert.AreEqual(-1, newCount);
        }
예제 #8
0
        public override int GetHashCode()
        {
            if (_hashCode == -1 && _eventUniqueId == null)
            {
                return(base.GetHashCode());
            }
            else if (_hashCode == -1)
            {
                _hashCode = (_eventUniqueId + _eventCounter.ToString() + ":" + OperationCounter.ToString() + ":" + _eventType.ToString()).GetHashCode();
            }

            return(_hashCode);
        }
        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);
        }
        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);
        }
예제 #11
0
 public OperationCounterTest()
 {
     _counter = new OperationCounter <TimeEntry>();
 }
 public OperationCounterTest()
 {
     _counter = new OperationCounter <TimeEntry, TrackedOperation>();
 }