Skip to content

Commit

Permalink
Merge pull request #52 from cole-brown/feature/remove-BinaryFormatter
Browse files Browse the repository at this point in the history
Feature/remove-BinaryFormatter
  • Loading branch information
acarteas authored Sep 7, 2021
2 parents 8caa3f9 + 59e1222 commit 4828ee0
Show file tree
Hide file tree
Showing 9 changed files with 433 additions and 135 deletions.
18 changes: 11 additions & 7 deletions src/FileCache.UnitTests/FileCache.UnitTests.csproj
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net452;netcoreapp2.0</TargetFrameworks>
<TargetFrameworks>netcoreapp5.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.0.0" />
<PackageReference Include="MSTest.TestFramework" Version="2.0.0" />
<PackageReference Include="FluentAssertions" Version="5.9.0" />

<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.5" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.5" />
<PackageReference Include="FluentAssertions" Version="6.1.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp5.0'">
<Reference Include="System.Runtime.Caching" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net40' ">
<Reference Include="System.Runtime.Caching" />
</ItemGroup>
Expand All @@ -28,7 +30,9 @@
<ProjectReference Include="..\FileCache\FileCache.csproj" />
</ItemGroup>

<!-- VisualStudio creates this when it notices a project includes tests. It tells VisualStudio to open the Test Explorer package. -->
<!-- Not sure if just VS or also VSCode... -->
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
</Project>
</Project>
49 changes: 49 additions & 0 deletions src/FileCache.UnitTests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Unit-Testing FileCache
------------------------

This will tell dotnet to build FileCache and run all of the tests.

``` shell
cd /path/to/FileCache/src/FileCache.UnitTests
dotnet test FileCache.UnitTests.csproj
```

Unit-Test Suites
----------------

There are two test suites:

1. FileCacheTest.cs
- These tests use the BasicFileCacheManager when running various unit-tests.

1. HashedFileCache.cs
- These tests are similar, but use the HashedFileCacheManager.


WSL2 Warning!
----------------

Sometimes a WSL operating system's time can get out-of-sync with the actual time (see [this](https://github.com/microsoft/WSL/issues/4114)). If it's out of sync enough, some tests can fail if Windows is ultimately in charge of file stats like Last Accessed Time. This happens if your FileCache repo is on a Windows drive (i.e. something under /mnt/c, /mnt/d, etc).

For example, FileCache.FlushRegionTest will fail with this error when your WSL'd Linux OS is 1 minute in the past:

```
Failed FlushRegionTest [1 s]
Error Message:
Expected result2 to be <null>, but found "Value2".
Stack Trace:
at FluentAssertions.Execution.LateBoundTestFramework.Throw(String message)
at FluentAssertions.Execution.TestFrameworkProvider.Throw(String message)
at FluentAssertions.Execution.DefaultAssertionStrategy.HandleFailure(String message)
at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc)
at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc)
at FluentAssertions.Execution.AssertionScope.FailWith(String message, Object[] args)
at FluentAssertions.Primitives.ReferenceTypeAssertions`2.BeNull(String because, Object[] becauseArgs)
at FC.UnitTests.FileCacheTest.FlushRegionTest() in /mnt/path/to/FileCache/src/FileCache.UnitTests/FileCacheTest.cs:line 266
```

To fix, you can try:
`sudo hwclock -s`

If that doesn't work, you'll probably have to shutdown and restart the VMs:
`wsl --shutdown`
6 changes: 2 additions & 4 deletions src/FileCache/BasicFileCacheManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace System.Runtime.Caching
public class BasicFileCacheManager : FileCacheManager
{
/// <summary>
/// Returns a list of keys for a given region.
/// Returns a list of keys for a given region.
/// </summary>
/// <param name="regionName"></param>
/// <returns></returns>
Expand All @@ -33,7 +33,7 @@ public override IEnumerable<string> GetKeys(string regionName = null)
}

/// <summary>
/// Builds a string that will place the specified file name within the appropriate
/// Builds a string that will place the specified file name within the appropriate
/// cache and workspace folder.
/// </summary>
/// <param name="FileName"></param>
Expand Down Expand Up @@ -74,7 +74,5 @@ public override string GetPolicyPath(string key, string regionName = null)
}
return filePath;
}


}
}
Loading

0 comments on commit 4828ee0

Please sign in to comment.