public void Basics_Empty()
        {
            var d = new TransactionalDictionary <int, int>();

            Assert.IsFalse(d.ContainsKey(0));
            Assert.IsFalse(d.ContainsKey(1));
            Assert.IsFalse(d.ContainsKey(2));

            Assert.IsFalse(d.TryGetValue(0, out _));
            Assert.IsFalse(d.TryGetValue(1, out _));
            Assert.IsFalse(d.TryGetValue(2, out _));

            Assert.ThrowsException <KeyNotFoundException>(() => _ = d[0]);
            Assert.ThrowsException <KeyNotFoundException>(() => _ = d[1]);
            Assert.ThrowsException <KeyNotFoundException>(() => _ = d[2]);

            Assert.IsFalse(d.Any());

            Assert.IsFalse(d.Remove(0));
            Assert.IsFalse(d.Remove(1));
            Assert.IsFalse(d.Remove(2));
        }
        public void Basics_Remove()
        {
            var d = new TransactionalDictionary <int, int>
            {
                { 42, 43 } // Add
            };

            Assert.IsTrue(d.Remove(42));

            Assert.IsFalse(d.ContainsKey(42));

            Assert.IsFalse(d.TryGetValue(42, out var _));

            Assert.ThrowsException <KeyNotFoundException>(() => _ = d[42]);

            Assert.IsFalse(d.Any());
        }
        private static void AssertEqual <K, V>(Dictionary <K, V> expected, TransactionalDictionary <K, V> actual)
        {
            Assert.IsTrue(expected.OrderBy(kv => kv.Key).SequenceEqual(actual.OrderBy(kv => kv.Key)));

            foreach (var kv in expected)
            {
                var key   = kv.Key;
                var value = kv.Value;

                Assert.IsTrue(actual.ContainsKey(key));

                Assert.IsTrue(actual.TryGetValue(key, out var v));
                Assert.AreEqual(value, v);

                Assert.AreEqual(value, actual[key]);
            }
        }
        public void Basics_Assign()
        {
            var d = new TransactionalDictionary <int, int>
            {
                [42] = 43 // indexer assignment
            };

            Assert.ThrowsException <InvalidOperationException>(() => d.Add(42, -1));

            Assert.IsTrue(d.ContainsKey(42));

            Assert.IsTrue(d.TryGetValue(42, out var x));
            Assert.AreEqual(43, x);

            Assert.AreEqual(43, d[42]);

            Assert.IsTrue(d.SequenceEqual(new[] { new KeyValuePair <int, int>(42, 43) }));
        }