Skip to content

Commit

Permalink
Unit test fixes.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cole-brown committed Aug 12, 2021
1 parent 82ff59b commit dc77160
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/FileCache.UnitTests/FileCache.UnitTests.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net452;netcoreapp2.0</TargetFrameworks>
<TargetFrameworks>net452;netcoreapp5.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
Expand Down Expand Up @@ -31,4 +31,4 @@
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
</Project>
</Project>
16 changes: 8 additions & 8 deletions src/FileCache/FileCache.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net45;net48;netstandard2.0;netstandard2.1</TargetFrameworks>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageTags>cache objectcache System.Runtime.Caching.ObjectCache</PackageTags>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<Authors>Adam Carter</Authors>
Expand All @@ -28,12 +28,12 @@
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-*" PrivateAssets="All" />
<PackageReference Include="GitVersionTask" Version="5.3.2">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
</ItemGroup>
<!-- <ItemGroup> -->
<!-- <PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-*" PrivateAssets="All" /> -->
<!-- <PackageReference Include="GitVersionTask" Version="5.3.2"> -->
<!-- <PrivateAssets>All</PrivateAssets> -->
<!-- </PackageReference> -->
<!-- </ItemGroup> -->

<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
<Reference Include="System.Runtime.Caching" />
Expand Down Expand Up @@ -100,4 +100,4 @@
<Version>2.0.0</Version>
</PackageReference>
</ItemGroup>
</Project>
</Project>
5 changes: 3 additions & 2 deletions src/FileCache/SerializableCacheItemPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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(),
};
}
Expand Down

0 comments on commit dc77160

Please sign in to comment.