Ejemplo n.º 1
0
        public void TestSingleCounter()
        {
            bool        bcalled;
            ThreadStart call = delegate() { bcalled = true; };

            using (UsageCounter counter = new UsageCounter("some global name"))
            {
                counter.TotalCount(delegate(int count) { Assert.AreEqual(0, count); });
                bcalled = false;
                counter.Increment(call);
                Assert.IsTrue(bcalled);
                counter.TotalCount(delegate(int count) { Assert.AreEqual(1, count); });

                bcalled = false;
                counter.Increment(call);
                Assert.IsFalse(bcalled);
                counter.TotalCount(delegate(int count) { Assert.AreEqual(2, count); });

                bcalled = false;
                counter.Decrement(call);
                Assert.IsFalse(bcalled);
                counter.TotalCount(delegate(int count) { Assert.AreEqual(1, count); });

                bcalled = false;
                counter.Decrement(call);
                Assert.IsTrue(bcalled);
                counter.TotalCount(delegate(int count) { Assert.AreEqual(0, count); });
            }
        }
Ejemplo n.º 2
0
        public void TestSingleCounter()
        {
            bool bcalled;
            ThreadStart call = delegate() { bcalled = true; };

            using (UsageCounter counter = new UsageCounter("some global name"))
            {
                counter.TotalCount(delegate(int count) { Assert.AreEqual(0, count); });
                bcalled = false;
                counter.Increment(call);
                Assert.IsTrue(bcalled);
                counter.TotalCount(delegate(int count) { Assert.AreEqual(1, count); });

                bcalled = false;
                counter.Increment(call);
                Assert.IsFalse(bcalled);
                counter.TotalCount(delegate(int count) { Assert.AreEqual(2, count); });

                bcalled = false;
                counter.Decrement(call);
                Assert.IsFalse(bcalled);
                counter.TotalCount(delegate(int count) { Assert.AreEqual(1, count); });

                bcalled = false;
                counter.Decrement(call);
                Assert.IsTrue(bcalled);
                counter.TotalCount(delegate(int count) { Assert.AreEqual(0, count); });
            }
        }
Ejemplo n.º 3
0
 public void TestTooManyDecrements()
 {
     using (UsageCounter counter = new UsageCounter("some global name"))
     {
         counter.Increment();
         counter.TotalCount(delegate(int count) { Assert.AreEqual(1, count); });
         counter.Decrement();
         counter.TotalCount(delegate(int count) { Assert.AreEqual(0, count); });
         counter.Decrement();
     }
 }
Ejemplo n.º 4
0
 public void TestTooManyDecrements()
 {
     using (UsageCounter counter = new UsageCounter("some global name"))
     {
         counter.Increment();
         counter.TotalCount(delegate(int count) { Assert.AreEqual(1, count); });
         counter.Decrement();
         counter.TotalCount(delegate(int count) { Assert.AreEqual(0, count); });
         counter.Decrement();
     }
 }
Ejemplo n.º 5
0
        public void TestEventArguments()
        {
            Value val = new Value();

            using (UsageCounter counter = new UsageCounter("some global name"))
            {
                counter.Increment(delegate(Value v) { v.Number++; }, val);
                counter.Increment(delegate(Value v) { v.Number++; }, val);
                counter.Decrement(delegate(Value v) { v.Number++; }, val);
                counter.Decrement(delegate(Value v) { v.Number++; }, val);
                Assert.AreEqual(2, val.Number);
            }
        }
Ejemplo n.º 6
0
 public void TestInstanceCount()
 {
     using (UsageCounter counter = new UsageCounter("some global name"))
     {
         Assert.AreEqual(0, counter.InstanceCount);
         counter.Increment();
         Assert.AreEqual(1, counter.InstanceCount);
         counter.Increment();
         Assert.AreEqual(2, counter.InstanceCount);
         using (UsageCounter copy = new UsageCounter("some global name"))
             Assert.AreEqual(0, copy.InstanceCount);
         counter.Decrement();
         Assert.AreEqual(1, counter.InstanceCount);
         counter.Decrement();
         Assert.AreEqual(0, counter.InstanceCount);
     }
 }
        /// <summary>
        /// Stops listening for this instance, if this is the last instance to stop listening the process
        /// stops listening on all registered protocols.
        /// </summary>
        public void StopListening()
        {
            if (!_isListening)
            {
                return;
            }

            _isListening = false;
            _listenerCount.Decrement(ServerStopListening);
        }
Ejemplo n.º 8
0
        public void TestMultipleNestedCounters()
        {
            using (UsageCounter counter = new UsageCounter("some global name"))
            {
                using (UsageCounter counter2 = new UsageCounter("some global name"))
                    counter2.Increment();
                counter.TotalCount(delegate(int count) { Assert.AreEqual(1, count); });

                using (UsageCounter counter2 = new UsageCounter("some global name"))
                {
                    counter2.TotalCount(delegate(int count) { Assert.AreEqual(1, count); });
                    counter2.Decrement();
                }
                counter.TotalCount(delegate(int count) { Assert.AreEqual(0, count); });
            }
        }
Ejemplo n.º 9
0
        public void TestInstanceCount()
        {
            using (UsageCounter counter = new UsageCounter("some global name"))
            {
                Assert.AreEqual(0, counter.InstanceCount);
                counter.Increment();
                Assert.AreEqual(1, counter.InstanceCount);
                counter.Increment();
                Assert.AreEqual(2, counter.InstanceCount);
                using (UsageCounter copy = new UsageCounter("some global name"))
                    Assert.AreEqual(0, copy.InstanceCount);
                counter.Decrement();
                Assert.AreEqual(1, counter.InstanceCount);
                counter.Decrement();
                Assert.AreEqual(0, counter.InstanceCount);
            }

        }
Ejemplo n.º 10
0
 public void TestEventArguments()
 {
     Value val = new Value();
     using (UsageCounter counter = new UsageCounter("some global name"))
     {
         counter.Increment(delegate(Value v) { v.Number++; }, val);
         counter.Increment(delegate(Value v) { v.Number++; }, val);
         counter.Decrement(delegate(Value v) { v.Number++; }, val);
         counter.Decrement(delegate(Value v) { v.Number++; }, val);
         Assert.AreEqual(2, val.Number);
     }
 }
Ejemplo n.º 11
0
        public void TestMultipleNestedCounters()
        {
            using (UsageCounter counter = new UsageCounter("some global name"))
            {
                using (UsageCounter counter2 = new UsageCounter("some global name"))
                    counter2.Increment();
                counter.TotalCount(delegate(int count) { Assert.AreEqual(1, count); });

                using (UsageCounter counter2 = new UsageCounter("some global name"))
                {
                    counter2.TotalCount(delegate(int count) { Assert.AreEqual(1, count); });
                    counter2.Decrement();
                }
                counter.TotalCount(delegate(int count) { Assert.AreEqual(0, count); });
            }
        }