Browse Source

Added test counter.

pull/625/head
Halil ibrahim Kalkan 8 years ago
parent
commit
faa014220a
  1. 13
      framework/src/Volo.Abp.TestBase/Volo/Abp/Testing/Utils/ITestCounter.cs
  2. 43
      framework/src/Volo.Abp.TestBase/Volo/Abp/Testing/Utils/TestCounter.cs

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

43
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<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