public async Task IdempotencyServiceShouldNotEnumurateValuesThatAreRemoved1() { ISendIdempotencyService <int, TestClass> simpleIdempotencyService = new SendIdempotencyService <int, TestClass>(3); await simpleIdempotencyService.Add(1, new TestClass(42)); await simpleIdempotencyService.Add(2, new TestClass(43)); await simpleIdempotencyService.Add(3, new TestClass(44)); List <TestClass> values = new List <TestClass>(); bool firstIteration = true; foreach (var item in simpleIdempotencyService.GetValues()) { values.Add(item); if (firstIteration) { firstIteration = false; simpleIdempotencyService.Remove(2, out _); } } Assert.AreEqual(2, values.Count); Assert.IsTrue(values.Any(x => x.Value == 42)); Assert.IsTrue(values.Any(x => x.Value == 44)); Assert.IsFalse(values.Any(x => x.Value == 43)); }
public async Task IdempotencyServiceShouldBlockAfterPacketLimitExceeds() { ISendIdempotencyService <int, TestClass> simpleIdempotencyService = new SendIdempotencyService <int, TestClass>(2); await simpleIdempotencyService.Add(1, new TestClass(42)); await simpleIdempotencyService.Add(2, new TestClass(43)); bool taskCompleted = simpleIdempotencyService.Add(3, new TestClass(44)).Wait(2 * 1000); Assert.IsTrue(!taskCompleted); }
public async Task IdempotencyServiceShouldUnblockAfterPacketLimitIsNoLongerExceeded() { ISendIdempotencyService <int, TestClass> simpleIdempotencyService = new SendIdempotencyService <int, TestClass>(2); await simpleIdempotencyService.Add(1, new TestClass(42)); await simpleIdempotencyService.Add(2, new TestClass(43)); Task <bool> thirdAdd = Task.Run(() => simpleIdempotencyService.Add(3, new TestClass(44)).Wait(5 * 1000)); simpleIdempotencyService.Remove(1, out _); Assert.IsTrue(await thirdAdd); }
public async Task IdempotencyServiceShouldEnumurateValues() { ISendIdempotencyService <int, TestClass> simpleIdempotencyService = new SendIdempotencyService <int, TestClass>(2); await simpleIdempotencyService.Add(1, new TestClass(42)); await simpleIdempotencyService.Add(2, new TestClass(43)); List <TestClass> values = simpleIdempotencyService.GetValues().ToList(); Assert.AreEqual(2, values.Count); Assert.IsTrue(values.Any(x => x.Value == 42)); Assert.IsTrue(values.Any(x => x.Value == 43)); }
public async Task IdempotencyServiceShouldRemoveValueBasedOnKey() { ISendIdempotencyService <int, TestClass> simpleIdempotencyService = new SendIdempotencyService <int, TestClass>(2); await simpleIdempotencyService.Add(1, new TestClass(42)); Assert.IsTrue(simpleIdempotencyService.Remove(1, out TestClass value)); Assert.AreEqual(42, value.Value); }
public async Task IdempotencyServiceShouldBeAbleToAddData() { ISendIdempotencyService <int, TestClass> simpleIdempotencyService = new SendIdempotencyService <int, TestClass>(10); TestClass testClass = new TestClass(42); bool result = await simpleIdempotencyService.Add(1, testClass); Assert.IsTrue(result); }