public static void SaveLastCutoff(string tableName, string configurationName, DateTime cutoff)
 {
     // Write the new cutoff as long as it's not still the default one
     if (cutoff.Year > (DateTime.UtcNow.Year - 19))
     {
         TextSerializer.Write(cutoff, String.Format(CutoffLocationFormatString, tableName, configurationName));
     }
 }
Пример #2
0
        public void Write_Should_use_context_marshalling_for_object()
        {
            using Stream stream = new MemoryStream();

            using TextSerializationContext context = new TextSerializationContext()
                                                     .Marshal <int, string>(i => $"value {i}");

            TextSerializer.Write <object>(stream, 42, context);

            stream.Position = 0;

            object copy = Read <object>(stream);

            Check.That(copy).IsInstanceOf <string>().And.IsEqualTo("value 42");
        }
Пример #3
0
        public void Write_Should_use_context_marshalling_When_same_type()
        {
            using Stream stream = new MemoryStream();

            using TextSerializationContext context = new TextSerializationContext()
                                                     .Marshal <int, int>(_ => 1337);

            TextSerializer.Write(stream, 42, context);

            stream.Position = 0;

            int copy = Read <int>(stream);

            Check.That(copy).IsEqualTo(1337);
        }
Пример #4
0
        public void Write_Should_use_context_marshalling_When_sub_field()
        {
            using Stream stream = new MemoryStream();

            using TextSerializationContext context = new TextSerializationContext()
                                                     .Marshal <int, int>(i => i * 2);

            TextSerializer.Write(stream, new Point(1, 2), context);

            stream.Position = 0;

            Point copy = Read <Point>(stream);

            Check.That(copy).IsEqualTo(new Point(2, 4));
        }
Пример #5
0
        public void TextSerializer_DateTime()
        {
            // Verify regular round trip
            DateTime now = DateTime.Now;

            TextSerializer.Write(now, "Sample.txt");
            DateTime roundTripped = TextSerializer.ReadDateTime("Sample.txt", DateTime.MinValue);

            Assert.AreEqual(now.Ticks, roundTripped.Ticks);

            // Verify default returned for missing files
            Assert.AreEqual(DateTime.MinValue.Ticks, TextSerializer.ReadDateTime("Missing.txt", DateTime.MinValue).Ticks);

            // Verify default returned for non DateTime values
            TextSerializer.Write("Not a DateTime", "WrongFormat.txt");
            Assert.AreEqual(DateTime.MinValue.Ticks, TextSerializer.ReadDateTime("WrongFormat.txt", DateTime.MinValue).Ticks);
        }
Пример #6
0
 protected override void Write <T>(Stream stream, T obj) => TextSerializer.Write(stream, obj);
Пример #7
0
 public void TextSerializer_String()
 {
     TextSerializer.Write("Sample Value", "Sample.txt");
     Assert.AreEqual("Sample Value", TextSerializer.ReadString("Sample.txt", "Default Value"));
     Assert.AreEqual("Default Value", TextSerializer.ReadString("Missing.txt", "Default Value"));
 }