public void Setup()
 {
     _dictionary = new GenericDictionaryImpl <string, string>
     {
         { "item1", "oh" }, { "item2", "hai" }
     };
     _adapter = GenericDictionaryAdapter.Create(_dictionary);
 }
Exemple #2
0
        public void should_add_nodes(
            object dictionary, NodeType nodeType, string value1, int value2)
        {
            var parent = CreateNode(dictionary);

            parent.Add("item1", nodeType, Metadata.Empty, x => x.Value = value1);
            parent.Add("item2", nodeType, Metadata.Empty, x => x.Value = value2);
            var backingDictionary = GenericDictionaryAdapter.Create(dictionary);

            backingDictionary.Count.ShouldEqual(2);
            backingDictionary["item1"].ShouldEqual(value1);
            backingDictionary["item2"].ShouldEqual(value2.ToString());
        }
Exemple #3
0
        public void should_enumerate_nodes_backed_by_generic_dictionary(
            object dictionary, NodeType nodeType)
        {
            var nonGenericDictionary     = GenericDictionaryAdapter.Create(dictionary);
            Func <string, object> getKey = x => nonGenericDictionary
                                           .Keys.Cast <object>().First(y => y.ToString() == x);

            var children = CreateNode(dictionary, mode: Mode.Serialize).Cast <NodeBase>().ToList();

            children.ShouldTotal(2);

            var child = children.First();

            child.NodeType.ShouldEqual(nodeType);
            child.Name.ShouldEqual("oh");
            child.Value.ShouldEqual(nonGenericDictionary[getKey("oh")]);

            child = children.Skip(1).First();
            child.NodeType.ShouldEqual(nodeType);
            child.Name.ShouldEqual("hai");
            child.Value.ShouldEqual(nonGenericDictionary[getKey("hai")]);
        }
 public void should_fail_if_not_a_dictionary()
 {
     Assert.Throws <ArgumentException>(() => GenericDictionaryAdapter.Create(new object()));
 }
        public void should_return_object_if_it_implements_idictionary()
        {
            var dictionary = new Dictionary <string, string>();

            GenericDictionaryAdapter.Create(dictionary).ShouldBeSameAs(dictionary);
        }