Added test counter.

pull/625/head
Halil ibrahim Kalkan 6 years ago
parent 40ea123451
commit faa014220a

@ -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…
Cancel
Save