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