DateTime deserialization in redis

I have a simple test that I am performing to ensure the registered ICacheClient is working correctly. For an MemoryCacheClient the test passes. However with a Redis ICacheClient the test fails.

Test Class

    public class CacheTest
    {
        public CacheTest()
        {
            Date = DateTime.Now;
            Title = "This is a test";
            i = 10001;
        }

        public bool Check(CacheTest orig)
        {
            if (orig == null)
            {
                return false;
            }

            if (DateTime.Compare(orig.Date, Date) != 0)
                return false;

            if (orig.Title != Title)
                return false;

            if (orig.i != i)
                return false;

            return true;
        }

        public DateTime Date { get; set; }
        public string Title { get; set; }
        public int i { get; set; }
    }

The test:

                string cacheKey = CacheHelper.CreateKey("test");
                Cache.Remove(cacheKey);
                var ct = new CacheTest();
                if (!Cache.Add<CacheTest>(cacheKey, ct))
                {
                    return new TestResponse() { Description = "Cache did not add properly", WasSuccessful = false };
                }
                else
                {
                    var result = Cache.Get<CacheTest>(cacheKey);
                    if (result.Check(ct))
                        tests += "Cache Online. ";
                    else
                    {
                        return new TestResponse() { Description = "Cache did not deserialize properly", WasSuccessful = false };
                    }
                }

The check for the DateTime fails.

Date.Ticks
636048233401150000
orig.Date.Ticks
636048233401153475

Why is precision being lost?

The Cache doesn’t get serialized in MemoryCacheClient it just keeps it in memory, it would get serialized in all other Caching providers. It may be a Time Zone issue, do you have any JsConfig configuration? and what is the DateKind of the deserialized date?

Only JsConfig setting:
JsConfig.ExcludeTypeInfo = true;

Date.Kind: local
orig.Date.Kind: local

Just had a look, the issue is just a precision issue with serializing dates which by default serializes using Unix Time ms, so any additional precision beyond that is discarded. These dates are equivalent minus sub ms fractions:

new DateTime().AddTicks(636048233401150000).ToString("O").Print();
new DateTime().AddTicks(636048233401153475).ToString("O").Print();

Which prints:

2016-07-22T22:29:00.1150000
2016-07-22T22:29:00.1153475

To keep the precision you can switch to an alternative date format like, e.g:

JsConfig.DateHandler = DateHandler.ISO8601;