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?