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); }); } }
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); }); } }
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(); } }
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(); } }
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); }); } }
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); }); }
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); }); }
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); }); } }