From dc7716077f3d98fb16cac949e6ce057cb5af9e4e Mon Sep 17 00:00:00 2001 From: Cole Brown Date: Wed, 11 Aug 2021 18:09:30 -0700 Subject: [PATCH] Unit test fixes. Bumped UnitTests to netcoreapp5.0 Nuked Microsoft.SourceLink.GitHub and GitVersionTask as they were causing build errors I didn't want to sort. Fixed 3 of 12 failing unit tests. - SerializableCacheItemPolicy was not serializing its time, only date. - SerializableCacheItemPolicy was messing up its expiration date when deserializing due to the SlidingExpiration setter. --- .../FileCache.UnitTests.csproj | 4 ++-- src/FileCache/FileCache.csproj | 16 ++++++++-------- src/FileCache/SerializableCacheItemPolicy.cs | 5 +++-- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/FileCache.UnitTests/FileCache.UnitTests.csproj b/src/FileCache.UnitTests/FileCache.UnitTests.csproj index 2743690..5ffe0f1 100644 --- a/src/FileCache.UnitTests/FileCache.UnitTests.csproj +++ b/src/FileCache.UnitTests/FileCache.UnitTests.csproj @@ -1,6 +1,6 @@  - net452;netcoreapp2.0 + net452;netcoreapp5.0 false true true @@ -31,4 +31,4 @@ - \ No newline at end of file + diff --git a/src/FileCache/FileCache.csproj b/src/FileCache/FileCache.csproj index d1fd45b..5a22820 100644 --- a/src/FileCache/FileCache.csproj +++ b/src/FileCache/FileCache.csproj @@ -1,7 +1,7 @@  net45;net48;netstandard2.0;netstandard2.1 - false + false cache objectcache System.Runtime.Caching.ObjectCache Apache-2.0 Adam Carter @@ -28,12 +28,12 @@ Auto - - - - All - - + + + + + + @@ -100,4 +100,4 @@ 2.0.0 - \ No newline at end of file + diff --git a/src/FileCache/SerializableCacheItemPolicy.cs b/src/FileCache/SerializableCacheItemPolicy.cs index a93f864..eb3979b 100644 --- a/src/FileCache/SerializableCacheItemPolicy.cs +++ b/src/FileCache/SerializableCacheItemPolicy.cs @@ -66,7 +66,7 @@ public void Serialize(BinaryWriter writer) { writer.Write(CACHE_VERSION); - writer.Write(AbsoluteExpiration.Date.ToBinary()); + writer.Write(AbsoluteExpiration.DateTime.ToBinary()); writer.Write(AbsoluteExpiration.Offset.TotalMilliseconds); writer.Write(SlidingExpiration.TotalMilliseconds); @@ -100,7 +100,8 @@ public static SerializableCacheItemPolicy Deserialize(BinaryReader reader, long return new SerializableCacheItemPolicy { AbsoluteExpiration = new DateTimeOffset(DateTime.FromBinary(reader.ReadInt64()), TimeSpan.FromMilliseconds(reader.ReadDouble())), - SlidingExpiration = TimeSpan.FromMilliseconds(reader.ReadDouble()), + // Don't clobber absolute by using sliding's setter; set the private value instead. + _slidingExpiration = TimeSpan.FromMilliseconds(reader.ReadDouble()), Key = reader.ReadString(), }; }