Esempio n. 1
0
        public void Generic_dictionary_and_IDictionary_serialise_the_same()
        {
            JsConfig.PreferInterfaces = true;
            JsConfig.ExcludeTypeInfo  = false;
            JsConfig.ConvertObjectTypesIntoStringDictionary = false;

            var genericStringDictionary = new ContainsGenericStringDictionary {
                Container = new Dictionary <string, string>
                {
                    { "one", "header one" },
                    { "two", "header two" }
                }
            };
            var iDictionary = new ContainsIDictionary {
                Container = new Dictionary <string, string>
                {
                    { "one", "header one" },
                    { "two", "header two" }
                }
            };

            var genDict = genericStringDictionary.ToJson();
            var iDict   = iDictionary.ToJson();

            Console.WriteLine("Dictionary<string,string> --> " + genDict);
            Console.WriteLine();
            Console.WriteLine("IDictionary               --> " + iDict);

            Assert.That(genDict, Is.EqualTo(iDict));
        }
Esempio n. 2
0
        public void Generic_dictionary_round_trips_ok()
        {
            var original = new ContainsGenericStringDictionary {
                Container = new Dictionary <string, string>
                {
                    { "one", "header one" },
                    { "two", "header two" }
                }
            };

            var str = JsonSerializer.SerializeToString(original);
            var obj = JsonSerializer.DeserializeFromString <ContainsGenericStringDictionary>(str);

            Console.WriteLine(DictStr(obj.Container));
            Assert.That(DictStr(obj.Container), Is.EqualTo(DictStr(original.Container)));
        }
		public void Generic_dictionary_and_IDictionary_serialise_the_same () {
			JsConfig.PreferInterfaces = true;
			JsConfig.ExcludeTypeInfo = false;
			JsConfig.ConvertObjectTypesIntoStringDictionary = false;

			var genericStringDictionary = new ContainsGenericStringDictionary {
				Container = new Dictionary<string, string>
                {
                    {"one", "header one"},
                    {"two", "header two"}
                }
			};
			var iDictionary = new ContainsIDictionary {
				Container = new Dictionary<string, string>
                {
                    {"one", "header one"},
                    {"two", "header two"}
                }
			};

			var genDict = genericStringDictionary.ToJson();
			var iDict = iDictionary.ToJson();

			Console.WriteLine("Dictionary<string,string> --> " + genDict);
			Console.WriteLine();
			Console.WriteLine("IDictionary               --> " + iDict);

			Assert.That(genDict, Is.EqualTo(iDict));
		}
		public void Generic_dictionary_round_trips_ok () {
			var original = new ContainsGenericStringDictionary {
				Container = new Dictionary<string, string>
                {
                    {"one", "header one"},
                    {"two", "header two"}
                }
			};

			var str = JsonSerializer.SerializeToString(original);
			var obj = JsonSerializer.DeserializeFromString<ContainsGenericStringDictionary>(str);

			Console.WriteLine(DictStr(obj.Container));
			Assert.That(DictStr(obj.Container), Is.EqualTo(DictStr(original.Container)));
		}