Пример #1
0
        public void ErrorDeserializingListHandled()
        {
            string json = @"[
  {
    ""Name"": ""Jim"",
    ""BirthDate"": ""\/Date(978048000000)\/"",
    ""LastModified"": ""\/Date(978048000000)\/""
  },
  {
    ""Name"": ""Jim"",
    ""BirthDate"": ""\/Date(978048000000)\/"",
    ""LastModified"": ""\/Date(978048000000)\/""
  }
]";

            var possibleMsgs = new[]
            {
                "[1] - Error message for member 1 = An item with the same key has already been added.",
                "[1] - Error message for member 1 = An element with the same key already exists in the dictionary.", // mono
                "[1] - Error message for member 1 = An item with the same key has already been added. Key: Jim"      // netcore
            };
            VersionKeyedCollection c = JsonConvert.DeserializeObject <VersionKeyedCollection>(json);

            Assert.AreEqual(1, c.Count);
            Assert.AreEqual(1, c.Messages.Count);

            Console.WriteLine(c.Messages[0]);
            Assert.IsTrue(possibleMsgs.Any(m => m == c.Messages[0]), "Expected One of: " + Environment.NewLine + string.Join(Environment.NewLine, possibleMsgs) + Environment.NewLine + "Was: " + Environment.NewLine + c.Messages[0]);
        }
Пример #2
0
        public void ErrorSerializingListHandled()
        {
            VersionKeyedCollection c = new VersionKeyedCollection();

            c.Add(new Person
            {
                Name         = "Jim",
                BirthDate    = new DateTime(2000, 12, 29, 0, 0, 0, DateTimeKind.Utc),
                LastModified = new DateTime(2000, 12, 29, 0, 0, 0, DateTimeKind.Utc)
            });
            c.Add(new Person
            {
                Name         = "Jimbo",
                BirthDate    = new DateTime(2000, 12, 29, 0, 0, 0, DateTimeKind.Utc),
                LastModified = new DateTime(2000, 12, 29, 0, 0, 0, DateTimeKind.Utc)
            });
            c.Add(new Person
            {
                Name         = "Jimmy",
                BirthDate    = new DateTime(2000, 12, 29, 0, 0, 0, DateTimeKind.Utc),
                LastModified = new DateTime(2000, 12, 29, 0, 0, 0, DateTimeKind.Utc)
            });
            c.Add(new Person
            {
                Name         = "Jim Bean",
                BirthDate    = new DateTime(2000, 12, 29, 0, 0, 0, DateTimeKind.Utc),
                LastModified = new DateTime(2000, 12, 29, 0, 0, 0, DateTimeKind.Utc)
            });

            string json = JsonConvert.SerializeObject(c, Formatting.Indented);

            Assert.AreEqual(@"[
  {
    ""Name"": ""Jimbo"",
    ""BirthDate"": ""\/Date(978048000000)\/"",
    ""LastModified"": ""\/Date(978048000000)\/""
  },
  {
    ""Name"": ""Jim Bean"",
    ""BirthDate"": ""\/Date(978048000000)\/"",
    ""LastModified"": ""\/Date(978048000000)\/""
  }
]", json);

            Assert.AreEqual(2, c.Messages.Count);
            Assert.AreEqual("Error message for member 0 = Index even: 0", c.Messages[0]);
            Assert.AreEqual("Error message for member 2 = Index even: 2", c.Messages[1]);
        }
    public void ErrorSerializingListHandled()
    {
      VersionKeyedCollection c = new VersionKeyedCollection();
      c.Add(new Person
      {
        Name = "Jim",
        BirthDate = new DateTime(2000, 12, 29, 0, 0, 0, DateTimeKind.Utc),
        LastModified = new DateTime(2000, 12, 29, 0, 0, 0, DateTimeKind.Utc)
      });
      c.Add(new Person
      {
        Name = "Jimbo",
        BirthDate = new DateTime(2000, 12, 29, 0, 0, 0, DateTimeKind.Utc),
        LastModified = new DateTime(2000, 12, 29, 0, 0, 0, DateTimeKind.Utc)
      });
      c.Add(new Person
      {
        Name = "Jimmy",
        BirthDate = new DateTime(2000, 12, 29, 0, 0, 0, DateTimeKind.Utc),
        LastModified = new DateTime(2000, 12, 29, 0, 0, 0, DateTimeKind.Utc)
      });
      c.Add(new Person
      {
        Name = "Jim Bean",
        BirthDate = new DateTime(2000, 12, 29, 0, 0, 0, DateTimeKind.Utc),
        LastModified = new DateTime(2000, 12, 29, 0, 0, 0, DateTimeKind.Utc)
      });

      string json = JsonConvert.SerializeObject(c, Formatting.Indented);

      Assert.AreEqual(@"[
  {
    ""Name"": ""Jimbo"",
    ""BirthDate"": ""\/Date(978048000000)\/"",
    ""LastModified"": ""\/Date(978048000000)\/""
  },
  {
    ""Name"": ""Jim Bean"",
    ""BirthDate"": ""\/Date(978048000000)\/"",
    ""LastModified"": ""\/Date(978048000000)\/""
  }
]", json);

      Assert.AreEqual(2, c.Messages.Count);
      Assert.AreEqual("Error message for member 0 = Index even: 0", c.Messages[0]);
      Assert.AreEqual("Error message for member 2 = Index even: 2", c.Messages[1]);
    }
        public void ErrorDeserializingListHandled()
        {
            string json = @"[
  {
    ""Name"": ""Jim"",
    ""BirthDate"": ""\/Date(978048000000)\/"",
    ""LastModified"": ""\/Date(978048000000)\/""
  },
  {
    ""Name"": ""Jim"",
    ""BirthDate"": ""\/Date(978048000000)\/"",
    ""LastModified"": ""\/Date(978048000000)\/""
  }
]";

            VersionKeyedCollection c = JsonConvert.DeserializeObject <VersionKeyedCollection>(json);

            Assert.AreEqual(1, c.Count);
            Assert.AreEqual(1, c.Messages.Count);
            Assert.AreEqual("[1] - Error message for member 1 = An item with the same key has already been added.", c.Messages[0]);
        }