diff --git a/framework/src/Volo.Abp.TestBase/Volo/Abp/Testing/Utils/ITestCounter.cs b/framework/src/Volo.Abp.TestBase/Volo/Abp/Testing/Utils/ITestCounter.cs new file mode 100644 index 0000000000..2764dcb24e --- /dev/null +++ b/framework/src/Volo.Abp.TestBase/Volo/Abp/Testing/Utils/ITestCounter.cs @@ -0,0 +1,13 @@ +namespace Volo.Abp.Testing.Utils +{ + public interface ITestCounter + { + int Add(string name, int count); + + int Decrement(string name); + + int Increment(string name); + + int GetValue(string name); + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.TestBase/Volo/Abp/Testing/Utils/TestCounter.cs b/framework/src/Volo.Abp.TestBase/Volo/Abp/Testing/Utils/TestCounter.cs new file mode 100644 index 0000000000..651a16836e --- /dev/null +++ b/framework/src/Volo.Abp.TestBase/Volo/Abp/Testing/Utils/TestCounter.cs @@ -0,0 +1,43 @@ +using System.Collections.Generic; +using Volo.Abp.DependencyInjection; + +namespace Volo.Abp.Testing.Utils +{ + public class TestCounter : ITestCounter, ISingletonDependency + { + private readonly Dictionary _values; + + public TestCounter() + { + _values = new Dictionary(); + } + + public int Increment(string name) + { + return Add(name, 1); + } + + public int Decrement(string name) + { + return Add(name, -1); + } + + public int Add(string name, int count) + { + lock (_values) + { + var newValue = _values.GetOrDefault(name) + count; + _values[name] = newValue; + return newValue; + } + } + + public int GetValue(string name) + { + lock (_values) + { + return _values.GetOrDefault(name); + } + } + } +}