Exemple #1
0
        public void DateTimeWithFormatConverter_DeserializeObject_Null()
        {
            string json = @"{'Data':null}";

            TesteConverterCustomFormat teste = JsonConvert.DeserializeObject <TesteConverterCustomFormat>(json);

            Assert.AreEqual(DateTime.MinValue, teste.Data);
        }
Exemple #2
0
        public void DateTimeWithFormatConverter_DeserializeObject_Ok()
        {
            string json = "{\"Data\":\"17-09-19 14:00:00\"}";

            TesteConverterCustomFormat teste = JsonConvert.DeserializeObject <TesteConverterCustomFormat>(json);

            var expected = "17/09/2019 14:00:00";

            Assert.AreEqual(expected, teste.Data.ToString("dd/MM/yyyy HH:mm:ss", System.Globalization.CultureInfo.CreateSpecificCulture("pt-BR")));
        }
Exemple #3
0
        public void DateTimeWithFormatConverter_UsingCustomFormat()
        {
            string formatExpected = "dd-MM-yy HH:mm:ss";

            var currentDate = DateTime.Now;

            TesteConverterCustomFormat teste = new TesteConverterCustomFormat {
                Data = currentDate
            };

            string json = JsonConvert.SerializeObject(teste);

            Assert.IsTrue(json.Contains(currentDate.ToString(formatExpected)));
        }