public void SupportIsEquivalentWithDictionaries()
        {
            var dictOf3_A = new Dictionary <string, string> {
                { "aa", "AA" }, { "bb", "BB" }, { "cc", "CC" }
            };
            var dictOf3_B = new Dictionary <string, string> {
                { "cc", "CC" }, { "aa", "AA" }, { "bb", "BB" }
            };
            var dictOf2 = new Dictionary <string, string> {
                { "cc", "CC" }, { "bb", "BB" }
            };

            var dictOf2Dict_A = new Dictionary <string, Dictionary <string, string> > {
                { "key1", dictOf2 }, { "key2", dictOf3_A }
            };
            var dictOf2Dict_B = new Dictionary <string, Dictionary <string, string> > {
                { "key2", dictOf3_B }, { "key1", dictOf2 }
            };

            Check.That(dictOf2Dict_A).IsEquivalentTo(dictOf2Dict_B);
#if !DOTNET_35
            var dictOf2Dict_C = new Dictionary <string, IReadOnlyDictionary <string, string> > {
                { "key1", new RoDico(dictOf2) }, { "key2", new RoDico(dictOf3_B) }
            };

            Check.That(dictOf2Dict_A).IsEquivalentTo(dictOf2Dict_C);
            Check.That(dictOf2Dict_C).IsEquivalentTo(dictOf2Dict_B);

            var customDico = new RoDico(dictOf3_B);
            Check.That(customDico).IsEquivalentTo(dictOf3_B);
            Check.That(dictOf3_B).IsEquivalentTo(customDico);
#endif
        }
Example #2
0
        WorkWithReadonlyDictionary()
        {
            IReadOnlyDictionary <string, string> roDico = new RoDico(SimpleDico);

            Check.That(roDico).ContainsKey("demo");
            Check.That(roDico).ContainsPair("demo", "value");
            Check.ThatCode(() => Check.That(roDico).ContainsKey("missing")).IsAFailingCheckWithMessage("",
                                                                                                       "The checked enumerable does not contain the expected key.",
                                                                                                       "The checked enumerable:",
                                                                                                       "\t{[demo, value], [other, test]} (2 items)",
                                                                                                       "Expected key:",
                                                                                                       "\t[\"missing\"]");
        }
Example #3
0
        public void IsEquivalentToWorks()
        {
            var dict = new Dictionary <string, object> {
                ["foo"] = new[] { "bar", "baz" }
            };
            var expected = new Dictionary <string, object> {
                ["foo"] = new[] { "bar", "baz" }
            };

            Check.That(dict).IsEquivalentTo(expected);
            Check.That((IDictionary <string, string>)null).IsEquivalentTo((IDictionary <string, string>)null);
#if !DOTNET_20 && !DOTNET_30 && !DOTNET_35 && !DOTNET_40
            IReadOnlyDictionary <string, string> value = new RoDico(SimpleDico);
            Check.That(value).IsEqualTo(SimpleDico);
            Check.That(value).IsEquivalentTo(SimpleDico);
#endif
        }