예제 #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); });
            }
        }
예제 #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); });
            }
        }
예제 #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();
     }
 }
예제 #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();
     }
 }
예제 #5
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); });
            }
        }
예제 #6
0
        public void TestMultipleCounters()
        {
            using (UsageCounter counter = new UsageCounter("some global name"))
            {
                counter.Increment();
                counter.TotalCount(delegate(int count) { Assert.AreEqual(1, count); });
            }

            //Someone has to hold onto at least one counter, or all will be cleared
            using (UsageCounter counter = new UsageCounter("some global name"))
                counter.TotalCount(delegate(int count) { Assert.AreEqual(0, count); });
        }
예제 #7
0
        public void TestMultipleCounters()
        {
            using (UsageCounter counter = new UsageCounter("some global name"))
            {
                counter.Increment();
                counter.TotalCount(delegate(int count) { Assert.AreEqual(1, count); });
            }

            //Someone has to hold onto at least one counter, or all will be cleared
            using (UsageCounter counter = new UsageCounter("some global name"))
                counter.TotalCount(delegate(int count) { Assert.AreEqual(0, count); });
        }
예제 #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); });
            }
        }