示例#1
0
        public void NullIsSerializedIntoEmptyString()
        {
            NullableDateTimeConverter converter = new NullableDateTimeConverter();
            DateTime?     date          = null;
            StringBuilder stringBuilder = new StringBuilder();

            converter.AppendToStringBuilder(stringBuilder, CultureInfo.InvariantCulture, date, null, ',');
            string serialized = stringBuilder.ToString();

            serialized.Should().Be("");
        }
示例#2
0
        public void DateTimeSerializerIsValid()
        {
            NullableDateTimeConverter converter = new NullableDateTimeConverter();
            DateTime?     date          = new DateTime(2019, 5, 4, 3, 2, 1);
            StringBuilder stringBuilder = new StringBuilder();

            converter.AppendToStringBuilder(stringBuilder, CultureInfo.InvariantCulture, date, null, ',');
            string serialized = stringBuilder.ToString();

            serialized.Should().Be("05/04/2019 03:02:01");
        }
示例#3
0
        public void CanSerializeUsingCustomDateFormat()
        {
            NullableDateTimeConverter converter = new NullableDateTimeConverter();
            DateTime?          date             = new DateTime(2019, 5, 4, 3, 2, 1);
            StringBuilder      stringBuilder    = new StringBuilder();
            CsvColumnAttribute attribute        = new CsvColumnAttribute("Date")
            {
                DateFormat = "yyyy/MMM/dd H:mm:ss"
            };

            converter.AppendToStringBuilder(stringBuilder, CultureInfo.InvariantCulture, date, attribute, ',');
            string serialized = stringBuilder.ToString();

            serialized.Should().Be("2019/May/04 3:02:01");
        }