예제 #1
0
        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));
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }