Skip to content

Commit

Permalink
Bugfix for #192, forgot to check for Default expiration mode in confi…
Browse files Browse the repository at this point in the history
…guration builder validation check
  • Loading branch information
MichaCo committed Nov 18, 2017
1 parent 9837d40 commit b6479c8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
5 changes: 3 additions & 2 deletions src/CacheManager.Core/Configuration/ConfigurationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,8 @@ public ConfigurationBuilderCacheHandlePart EnableStatistics()
/// <seealso cref="ExpirationMode"/>
public ConfigurationBuilderCacheHandlePart WithExpiration(ExpirationMode expirationMode, TimeSpan timeout)
{
if (expirationMode != ExpirationMode.None && timeout == TimeSpan.Zero)
// fixed #192 (was missing check for "Default" mode)
if (expirationMode != ExpirationMode.None && expirationMode != ExpirationMode.Default && timeout == TimeSpan.Zero)
{
throw new InvalidOperationException("If expiration mode is not set to 'None', timeout cannot be zero.");
}
Expand Down Expand Up @@ -798,4 +799,4 @@ public ICacheManagerConfiguration Build()
return Configuration;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
<PackageReference Include="FluentAssertions" Version="4.19.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<PackageReference Include="FluentAssertions" Version="4.19.4" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
</ItemGroup>

<ItemGroup>
Expand All @@ -37,5 +37,4 @@
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
<DefineConstants>$(DefineConstants);NETCOREAPP</DefineConstants>
</PropertyGroup>

</Project>
</Project>
8 changes: 4 additions & 4 deletions test/CacheManager.Tests/CacheManager.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
<PackageReference Include="FluentAssertions" Version="4.19.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<PackageReference Include="FluentAssertions" Version="4.19.4" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
Expand Down
21 changes: 19 additions & 2 deletions test/CacheManager.Tests/CacheManagerExpirationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ public void Redis_ExpirationTimeoutLimit()
// act/assert
using (cache)
{
Action act = ()=> cache.Add(new CacheItem<object>(key, key, ExpirationMode.Absolute, timeout));
Action act = () => cache.Add(new CacheItem<object>(key, key, ExpirationMode.Absolute, timeout));

act.ShouldThrow<ArgumentException>().WithMessage("*not supported*");
}
Expand Down Expand Up @@ -1030,6 +1030,23 @@ public void CacheItem_WithNoExpiration()
absolute.ExpirationTimeout.Should().BeCloseTo(default(TimeSpan));
}

/// <summary>
/// Issue #192
/// </summary>
[Fact]
public void Configuration_AllowsZeroForDefaultExpiration()
{
var expirationMode = ExpirationMode.Default;
var timeout = TimeSpan.Zero;

Action act = () => CacheFactory.Build<string>(
s => s
.WithDictionaryHandle()
.WithExpiration(expirationMode, timeout));

act.ShouldNotThrow();
}

#if !NETCOREAPP

[Fact]
Expand Down Expand Up @@ -1242,4 +1259,4 @@ private static async Task TestRemoveExpiration(int timeoutMillis, Func<string, b
}
}
}
}
}

0 comments on commit b6479c8

Please sign in to comment.