Esempio n. 1
0
        public void Complex_dictionaries_round_trip()
        {
            var original = new SeveralTypesOfDictionary
            {
                GuidToInt = new Dictionary <Guid, int>
                {
                    { Guid.Empty, 10 },
                    { Guid.NewGuid(), 25 }
                },
                DateTimeTo_DictStrStr = new Dictionary <DateTime, Dictionary <string, string> > {
                    { DateTime.Today, new Dictionary <string, string> {
                          { "a", "b" }, { "c", "d" }
                      } },
                    { DateTime.Now, new Dictionary <string, string> {
                          { "a", "b" }, { "c", "d" }
                      } }
                }
            };
            // see WriteDictionary.cs line 105
            // Problems:
            //   - Int is turning into String on Deserialise
            //   - Dictionary of dictionaries is totally failing on Deserialise
            var string_a = original.ToJson();
            var copy_a   = string_a.FromJson <SeveralTypesOfDictionary>();
            var string_b = copy_a.ToJson();
            var copy_b   = string_b.FromJson <SeveralTypesOfDictionary>();

            Console.WriteLine(string_a);
            Console.WriteLine(string_b);
            Assert.That(copy_a.GuidToInt[Guid.Empty], Is.EqualTo(10), "First copy was incorrect");
            Assert.That(copy_b.GuidToInt[Guid.Empty], Is.EqualTo(10), "Second copy was incorrect");
            Assert.That(string_a, Is.EqualTo(string_b), "Serialised forms not same");
        }
		public void Complex_dictionaries_round_trip () {
			var original = new SeveralTypesOfDictionary {
				GuidToInt = new Dictionary<Guid, int>
                {
                    {Guid.Empty, 10},
                    {Guid.NewGuid(), 25}
                },
				DateTimeTo_DictStrStr = new Dictionary<DateTime, Dictionary<string, string>> {
					{DateTime.Today, new Dictionary<string, string> {{"a","b"},{"c","d"}}},
					{DateTime.Now, new Dictionary<string, string> {{"a","b"},{"c","d"}}}
				}
			};
			// see WriteDictionary.cs line 105
			// Problems:
			//   - Int is turning into String on Deserialise
			//   - Dictionary of dictionaries is totally failing on Deserialise
			var string_a = original.ToJson();
			var copy_a = string_a.FromJson<SeveralTypesOfDictionary>();
			var string_b = copy_a.ToJson();
			var copy_b = string_b.FromJson<SeveralTypesOfDictionary>();

			Console.WriteLine(string_a);
			Console.WriteLine(string_b);
			Assert.That(copy_a.GuidToInt[Guid.Empty], Is.EqualTo(10), "First copy was incorrect");
			Assert.That(copy_b.GuidToInt[Guid.Empty], Is.EqualTo(10), "Second copy was incorrect");
			Assert.That(string_a, Is.EqualTo(string_b), "Serialised forms not same");
		}