Exemple #1
0
        public void CakeMailDateTimeConverter_WriteJson_Throws_exception_when_content_is_not_boolean()
        {
            // Arrange
            var converter = new CakeMailDateTimeConverter();
            var value     = "This is not a DateTime value";

            var sb = new StringBuilder();

            using (var sw = new StringWriter(sb))
            {
                using (var jsonWriter = new JsonTextWriter(sw))
                {
                    // Act
                    Should.Throw <Exception>(() => converter.WriteJson(jsonWriter, value, null));

                    // Assert
                    // Nothing to assert, since 'WriteJson' will throw an exception
                }
            }
        }
Exemple #2
0
        public void CakeMailDateTimeConverter_WriteJson_Successfully_writes_datetime()
        {
            // Arrange
            var converter = new CakeMailDateTimeConverter();
            var value     = new DateTime(2015, 3, 24, 12, 30, 11, 99, DateTimeKind.Utc);
            var expected  = "\"2015-03-24 12:30:11\"";

            var sb = new StringBuilder();

            using (var sw = new StringWriter(sb))
            {
                using (var jsonWriter = new JsonTextWriter(sw))
                {
                    // Act
                    converter.WriteJson(jsonWriter, value, null);

                    // Assert
                    sb.ToString().ShouldBe(expected);
                }
            }
        }