mirror of https://github.com/abpframework/abp.git
2 changed files with 56 additions and 0 deletions
@ -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); |
|||
} |
|||
} |
|||
@ -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<string, int> _values; |
|||
|
|||
public TestCounter() |
|||
{ |
|||
_values = new Dictionary<string, int>(); |
|||
} |
|||
|
|||
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); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue