public void MultipleDifferences()
        {
            var expected = new SampleDictionary
            {
                Properties = new Dictionary <string, object>
                {
                    ["A"] = 1,
                    ["B"] = 2,
                    ["C"] = 1
                }
            };

            var candidate = new SampleDictionary
            {
                Properties = new Dictionary <string, object>
                {
                    ["A"] = 1,
                    ["B"] = 1,
                    ["D"] = 1
                }
            };

            var ex = Assert.Throws <PropertyCheckException>(() => Check(expected, candidate));

            Assert.That(ex.Message, Is.EqualTo("SampleDictionary.Properties differences...\r\nB: Expected:<2>. Actual:<1>\r\nC: Expected:<1>. Actual:<null>\r\nD: Expected:<null>. Actual:<1>\r\n"), "Message differs");
        }
        public void SerializeTest()
        {
            // []
            {
                var dictionary = new SampleDictionary();
                dictionary["key"] = new Hoge(1, "user1");
                Assert.AreEqual("{\"keys\":[\"key\"],\"values\":[{\"Id\":1,\"Name\":\"user1\"}]}", JsonUtility.ToJson(dictionary));
            }

            // Add
            {
                var dictionary = new SampleDictionary();
                dictionary.Add("key", new Hoge(1, "user1"));
                Assert.AreEqual("{\"keys\":[\"key\"],\"values\":[{\"Id\":1,\"Name\":\"user1\"}]}", JsonUtility.ToJson(dictionary));
            }

            // Add
            {
                var dictionary = new SampleDictionary();
                dictionary.Add(new KeyValuePair <string, Hoge>("key", new Hoge(1, "user1")));
                Assert.AreEqual("{\"keys\":[\"key\"],\"values\":[{\"Id\":1,\"Name\":\"user1\"}]}", JsonUtility.ToJson(dictionary));
            }

            // Clear
            {
                var dictionary = new SampleDictionary();
                dictionary.Add("key", new Hoge(1, "user1"));
                Assert.AreEqual("{\"keys\":[\"key\"],\"values\":[{\"Id\":1,\"Name\":\"user1\"}]}", JsonUtility.ToJson(dictionary));
            }

            // Remove
            {
                var dictionary = new SampleDictionary();
                var entity     = new Hoge(1, "user1");
                dictionary.Add("key", entity);
                dictionary.Remove(new KeyValuePair <string, Hoge>("key", entity));
                Assert.AreEqual("{\"keys\":[],\"values\":[]}", JsonUtility.ToJson(dictionary));
            }

            // new
            {
                var dictionary = new SampleDictionary(
                    new Dictionary <string, Hoge> {
                    {
                        "key1", new Hoge(1, "user1")
                    }, {
                        "key2", new Hoge(2, "user2")
                    }
                });

                Assert.AreEqual(
                    "{" +
                    "\"keys\":[\"key1\",\"key2\"]," +
                    "\"values\":[{\"Id\":1,\"Name\":\"user1\"},{\"Id\":2,\"Name\":\"user2\"}]" +
                    "}",
                    JsonUtility.ToJson(dictionary)
                    );
            }
        }
        public void EqualityComparer_Ctor_Uses_Equality_Comparer()
        {
            _Dictionary = new SampleDictionary(StringComparer.OrdinalIgnoreCase);

            _Dictionary["aa"] = 1;
            _Dictionary["Aa"] = 2;

            Assert.AreEqual(1, _Dictionary.Count);
            Assert.AreEqual(2, _Dictionary["AA"]);
        }
        public void Clear_Resets_Dictionary()
        {
            _Dictionary = new SampleDictionary(new Dictionary <string, int?>()
            {
                ["a"] = 48,
                ["b"] = 886,
            });

            _Dictionary.Clear();

            Assert.AreEqual(0, _Dictionary.Count);
            Assert.AreEqual(1, _Dictionary.ResetCount);
        }
        public void Indexed_Set_Update_Assigns_Value()
        {
            _Dictionary = new SampleDictionary(new Dictionary <string, int?>()
            {
                ["a"] = 3
            });
            _Dictionary["a"] = 9;

            Assert.AreEqual(1, _Dictionary.AssignedCount);
            Assert.AreEqual("a", _Dictionary.AssignedKey);
            Assert.AreEqual(9, _Dictionary.AssignedValue);
            Assert.AreEqual(9, _Dictionary["a"]);
        }
        public void Wrapped_Ctor_Wraps_Existing_Dictionary()
        {
            var wrapped = new Dictionary <string, int?>();

            _Dictionary = new SampleDictionary(wrapped);

            _Dictionary["a"] = 8;

            Assert.AreEqual(1, _Dictionary.Count);
            Assert.AreEqual(8, _Dictionary["a"]);

            Assert.AreEqual(1, wrapped.Count);
            Assert.AreEqual(8, wrapped["a"]);
        }
        public void Remove_Removes_KeyValuePair()
        {
            _Dictionary = new SampleDictionary(new Dictionary <string, int?>()
            {
                ["a"] = 48,
            });

            var actual = _Dictionary.Remove(new KeyValuePair <string, int?>("a", 48));

            Assert.AreEqual(true, actual);
            Assert.IsFalse(_Dictionary.ContainsKey("a"));
            Assert.AreEqual(1, _Dictionary.RemovedCount);
            Assert.AreEqual("a", _Dictionary.RemovedKey);
        }
        public void NullCandidate()
        {
            var expected = new SampleDictionary
            {
                Properties = new Dictionary <string, object>()
            };

            var candidate = new SampleDictionary
            {
                Properties = null
            };

            var ex = Assert.Throws <PropertyCheckException>(() => Check(expected, candidate));

            Assert.That(ex.Message, Is.EqualTo("SampleDictionary.Properties: Expected:<not null>. Actual:<null>"), "Message differs");
        }
        public void TryGetValue_Tries_To_Get_Value()
        {
            _Dictionary = new SampleDictionary(new Dictionary <string, int?>()
            {
                ["a"] = 48,
            });

            var notFoundOutcome = _Dictionary.TryGetValue("b", out var notFoundValue);

            Assert.AreEqual(false, notFoundOutcome);
            Assert.AreEqual(default(int?), notFoundValue);

            var foundOutcome = _Dictionary.TryGetValue("a", out var foundValue);

            Assert.AreEqual(true, foundOutcome);
            Assert.AreEqual(48, foundValue);
        }
        public void MissingValueCandidate()
        {
            var expected = new SampleDictionary
            {
                Properties = new Dictionary <string, object>
                {
                    ["A"] = 1
                }
            };

            var candidate = new SampleDictionary
            {
                Properties = new Dictionary <string, object>()
            };

            var ex = Assert.Throws <PropertyCheckException>(() => Check(expected, candidate));

            Assert.That(ex.Message, Is.EqualTo("SampleDictionary.Properties differences...\r\nA: Expected:<1>. Actual:<null>\r\n"), "Message differs");
        }
 public void TestInitialise()
 {
     _Dictionary = new SampleDictionary();
 }