public async Task TryGetValueAsyncTest()
        {
            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())
            {
                Assert.IsFalse((await d.TryGetValueAsync(tx, 1, LockMode.Default)).HasValue);
                Assert.IsTrue(await d.TryAddAsync(tx, 1, "One"));

                using (var tx2 = _stateManager.CreateTransaction())
                {
                    await Assert.ThrowsExceptionAsync <TimeoutException>(
                        async() =>
                    {
                        await d.TryGetValueAsync(tx2, 1, LockMode.Default, timeout: TimeSpan.FromMilliseconds(20));
                    }
                        );
                }
                await tx.CommitAsync();

                Assert.AreEqual("One", change.Added);
            }
        }
        public async Task TryUpdateAsyncTest()
        {
            DictionaryChangedEvent <int, string>         change = null;
            TransactedConcurrentDictionary <int, string> d      = new TransactedConcurrentDictionary <int, string>(
                new Uri("test://mocks", UriKind.Absolute),
                (s, e) =>
            {
                change = e;
            }
                );

            using (var tx = _stateManager.CreateTransaction())
            {
                Assert.IsFalse((await d.TryUpdateAsync(tx, 1, "Two", "One")));
                Assert.IsTrue(await d.TryAddAsync(tx, 1, "One"));

                using (var tx2 = _stateManager.CreateTransaction())
                {
                    await Assert.ThrowsExceptionAsync <TimeoutException>(
                        async() =>
                    {
                        await d.TryRemoveAsync(tx2, 1, timeout: TimeSpan.FromMilliseconds(20));
                    }
                        );
                }
                await tx.CommitAsync();

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

            using (var tx = _stateManager.CreateTransaction())
            {
                Assert.IsFalse((await d.TryUpdateAsync(tx, 1, "Three", "Two")));

                using (_stateManager.CreateTransaction())
                {
                    Assert.IsTrue((await d.TryUpdateAsync(tx, 1, "Two", "One")));
                }
                await tx.CommitAsync();

                Assert.AreEqual("Two", change.Added);
            }
        }
        public async Task TryAddAsyncTest()
        {
            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())
            {
                Assert.IsTrue(await d.TryAddAsync(tx, 1, "One"));
                Assert.IsFalse(await d.TryAddAsync(tx, 1, "Two"));

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

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

            using (var tx = _stateManager.CreateTransaction())
            {
                Assert.IsFalse(await d.TryAddAsync(tx, 1, "Three"));
                Assert.IsTrue(await d.TryAddAsync(tx, 4, "Four"));
                Assert.IsTrue(await d.TryAddAsync(tx, 5, "Five"));
                await tx.CommitAsync();
            }

            Assert.AreEqual(3, await GetCount(d));
            Assert.AreEqual("One", (await GetValue(d, 1)).Value);
            Assert.AreEqual("Four", (await GetValue(d, 4)).Value);
            Assert.AreEqual("Five", (await GetValue(d, 5)).Value);
        }