public ConcurrentPolicyGateTest() { var store = new Mock <IQosCounterStore>(MockBehavior.Strict); store .Setup(s => s.TryAddAsync("k", It.IsAny <long>(), It.IsAny <long>(), null)) .ReturnsAsync <string, long, long, TimeSpan?, IQosCounterStore, CounterStoreAddResult>((key, increment, maxCount, period) => { var success = false; if (_counter + increment <= maxCount) { _counter += increment; success = true; } return(new CounterStoreAddResult() { Success = success, NewCounter = _counter }); }); store .Setup(s => s.AddAsync("k", It.IsAny <long>(), null)) .ReturnsAsync <string, long, TimeSpan?, IQosCounterStore, long>((key, increment, period) => { _counter += increment; return(_counter); }); _counterStore = store.Object; }
public ConcurrentPolicyGate(IQosCounterStore store, int maxCount) { if (maxCount <= 0) { throw new ArgumentOutOfRangeException(nameof(maxCount)); } _store = store; _maxCount = maxCount; }
public RateLimitPolicyGate(IQosCounterStore store, TimeSpan period, int maxCount) { if (period.Ticks <= 0) { throw new ArgumentOutOfRangeException(nameof(period)); } if (maxCount <= 0) { throw new ArgumentOutOfRangeException(nameof(maxCount)); } _store = store; _period = period; _maxCount = maxCount; }
public QuotaPolicyGateTest() { var store = new Mock <IQosCounterStore>(MockBehavior.Strict); store .Setup(s => s.GetAsync("k")) .ReturnsAsync <string, IQosCounterStore, long>(key => { return(_counter); }); store .Setup(s => s.AddAsync("k", It.IsAny <long>(), It.IsAny <TimeSpan?>())) .ReturnsAsync <string, long, TimeSpan?, IQosCounterStore, long>((key, increment, period) => { _counter += increment; return(_counter); }); _counterStore = store.Object; }