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 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> /// Starts the RPC listener for this instance, if this is the first RPC server instance the process /// starts listening on the registered protocols. /// </summary> public void StartListening() { if (_isListening) { return; } _listenerCount.Increment(ServerListen, _maxCalls); _isListening = true; }
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 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); }); } }
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 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); }); } }