public async Task ClearAsyncTest()
        {
            DictionaryChange change = null;
            TransactedConcurrentDictionary <int, string> d = new TransactedConcurrentDictionary <int, string>(
                new Uri("test://mocks", UriKind.Absolute),
                (c) =>
            {
                change = c;
                return(true);
            }
                );

            using (var tx = _stateManager.CreateTransaction())
            {
                await d.AddAsync(tx, 1, "One");

                await tx.CommitAsync();

                Assert.AreEqual(1, await GetCount(d));
            }

            change = null;
            await d.ClearAsync();

            Assert.AreEqual(0, await GetCount(d));
            Assert.IsNull(change);
        }
        public async Task ContainsKeyAsyncTest()
        {
            DictionaryChange change = null;
            TransactedConcurrentDictionary <int, string> d = new TransactedConcurrentDictionary <int, string>(
                new Uri("test://mocks", UriKind.Absolute),
                (c) =>
            {
                change = c;
                return(true);
            }
                );

            using (var tx = _stateManager.CreateTransaction())
            {
                await d.AddAsync(tx, 1, "One");

                await Assert.ThrowsExceptionAsync <TimeoutException>(
                    async() =>
                {
                    await ContainsKey(d, 1, TimeSpan.FromMilliseconds(20));
                }
                    );

                await tx.CommitAsync();

                Assert.IsTrue(await ContainsKey(d, 1));
            }
        }
        public async Task AddAsyncTest()
        {
            DictionaryChange change = null;
            TransactedConcurrentDictionary <int, string> d = new TransactedConcurrentDictionary <int, string>(
                new Uri("test://mocks", UriKind.Absolute),
                (c) =>
            {
                change = c;
                return(true);
            }
                );

            using (var tx = _stateManager.CreateTransaction())
            {
                await d.AddAsync(tx, 1, "One");

                await Assert.ThrowsExceptionAsync <ArgumentException>(
                    async() =>
                {
                    await d.AddAsync(tx, 1, "Two");
                }
                    );

                Assert.IsNull(change);

                using (var tx2 = _stateManager.CreateTransaction())
                {
                    await Assert.ThrowsExceptionAsync <TimeoutException>(
                        async() =>
                    {
                        await d.AddAsync(tx2, 1, "Three", TimeSpan.FromMilliseconds(20));
                    }
                        );
                }

                Assert.IsNull(change);

                await tx.CommitAsync();
            }

            Assert.AreEqual("One", change.Added);
            Assert.IsNull(change.Removed);

            Assert.AreEqual("One", (await GetValue(d, 1)).Value);
        }
        public async Task SetAsyncTest()
        {
            DictionaryChange change = null;
            TransactedConcurrentDictionary <int, string> d = new TransactedConcurrentDictionary <int, string>(
                new Uri("test://mocks", UriKind.Absolute),
                (c) =>
            {
                change = c;
                return(true);
            }
                );

            using (var tx = _stateManager.CreateTransaction())
            {
                await Assert.ThrowsExceptionAsync <ArgumentException>(
                    async() =>
                {
                    await d.SetAsync(tx, 1, "One");
                }
                    );

                await d.AddAsync(tx, 2, "Two");

                await tx.CommitAsync();
            }

            using (var tx = _stateManager.CreateTransaction())
            {
                await d.SetAsync(tx, 2, "Three");

                await tx.CommitAsync();

                Assert.AreEqual("Two", change.Removed);
                Assert.AreEqual("Three", change.Added);
            }

            Assert.AreEqual(1, await GetCount(d));
        }
        public async Task SetAsyncTest()
        {
            DictionaryChange change = null;
            TransactedConcurrentDictionary <int, string> d = new TransactedConcurrentDictionary <int, string>(
                new Uri("test://mocks", UriKind.Absolute),
                (c) =>
            {
                change = c;
                return(true);
            }
                );

            using (var tx = _stateManager.CreateTransaction())
            {
                await d.SetAsync(tx, 1, "Zero");
            }
            using (var tx = _stateManager.CreateTransaction())
            {
                ConditionalValue <string> value = await d.TryGetValueAsync(tx, 1, LockMode.Default);

                Assert.IsFalse(value.HasValue);
            }

            using (var tx = _stateManager.CreateTransaction())
            {
                await d.SetAsync(tx, 1, "One");

                await tx.CommitAsync();

                Assert.AreEqual("One", change.Added);
                Assert.AreEqual(null, change.Removed);
            }

            using (var tx = _stateManager.CreateTransaction())
            {
                await d.SetAsync(tx, 1, "Two");
            }
            using (var tx = _stateManager.CreateTransaction())
            {
                ConditionalValue <string> value = await d.TryGetValueAsync(tx, 1, LockMode.Default);

                Assert.AreEqual("One", value.Value);
            }

            using (var tx = _stateManager.CreateTransaction())
            {
                await d.AddAsync(tx, 2, "Two");

                await tx.CommitAsync();
            }

            using (var tx = _stateManager.CreateTransaction())
            {
                await d.SetAsync(tx, 2, "Three");

                await tx.CommitAsync();

                Assert.AreEqual("Two", change.Removed);
                Assert.AreEqual("Three", change.Added);
            }

            Assert.AreEqual(2, await GetCount(d));
        }