Skip to content

Commit

Permalink
Refactor to make tests re-useable for different CacheProvider types
Browse files Browse the repository at this point in the history
  • Loading branch information
reisenberger committed Jan 26, 2019
1 parent a853a22 commit 62eab65
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ namespace Polly.Caching.Distributed.Specs.Integration
{
public abstract class CacheRoundTripSpecsBase
{
protected CacheRoundTripSpecsBase(ICachePolicyFactory cachePolicyFactory)
{
CachePolicyFactory = cachePolicyFactory;
}

protected ICachePolicyFactory CachePolicyFactory { get; }

protected const string OperationKey = "SomeOperationKey";

public abstract Task Should_roundtrip_this_variant_of<TResult>(TResult testValue);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#if !NETCOREAPP1_1

using System;
using System;
using System.Threading.Tasks;
using FluentAssertions;

namespace Polly.Caching.Distributed.Specs.Integration
{
public abstract class CacheRoundTripSpecsSyncBase<TCache> : CacheRoundTripSpecsBase
{
protected CacheRoundTripSpecsSyncBase(ICachePolicyFactory cachePolicyFactory) : base(cachePolicyFactory)
{
}

public override Task Should_roundtrip_this_variant_of<TResult>(TResult testValue)
{
// Arrange
Expand Down Expand Up @@ -47,6 +49,4 @@ public override Task Should_roundtrip_this_variant_of<TResult>(TResult testValue
return Task.CompletedTask;
}
}
}

#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

namespace Polly.Caching.Distributed.Specs.Integration
{
public class CacheRoundTripSpecs_NetStandardIDistributedCacheProvider_Async_ByteArray : CacheRoundTripSpecsAsyncBase<byte[]> { }
public class CacheRoundTripSpecs_NetStandardIDistributedCacheProvider_Async_ByteArray : CacheRoundTripSpecsAsyncBase<byte[]> {

public CacheRoundTripSpecs_NetStandardIDistributedCacheProvider_Async_ByteArray() : base(new MemoryDistributedCachePolicyFactory())
{
}
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

namespace Polly.Caching.Distributed.Specs.Integration
{
public class CacheRoundTripSpecs_NetStandardIDistributedCacheProvider_Async_String : CacheRoundTripSpecsAsyncBase<string> { }
public class CacheRoundTripSpecs_NetStandardIDistributedCacheProvider_Async_String : CacheRoundTripSpecsAsyncBase<string> {
public CacheRoundTripSpecs_NetStandardIDistributedCacheProvider_Async_String() : base(new MemoryDistributedCachePolicyFactory())
{
}
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

namespace Polly.Caching.Distributed.Specs.Integration
{
public class CacheRoundTripSpecs_NetStandardIDistributedCacheProvider_Sync_ByteArray : CacheRoundTripSpecsSyncBase<byte[]> { }
public class CacheRoundTripSpecs_NetStandardIDistributedCacheProvider_Sync_ByteArray : CacheRoundTripSpecsSyncBase<byte[]> {
public CacheRoundTripSpecs_NetStandardIDistributedCacheProvider_Sync_ByteArray() : base(new MemoryDistributedCachePolicyFactory())
{
}
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

namespace Polly.Caching.Distributed.Specs.Integration
{
public class CacheRoundTripSpecs_NetStandardIDistributedCacheProvider_Sync_String : CacheRoundTripSpecsSyncBase<string> { }
public class CacheRoundTripSpecs_NetStandardIDistributedCacheProvider_Sync_String : CacheRoundTripSpecsSyncBase<string> {
public CacheRoundTripSpecs_NetStandardIDistributedCacheProvider_Sync_String() : base(new MemoryDistributedCachePolicyFactory())
{
}
}
}

#endif
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#if !NETCOREAPP1_1

using System;
using System;
using System.Threading;
using System.Threading.Tasks;
using FluentAssertions;
Expand All @@ -9,6 +7,10 @@ namespace Polly.Caching.Distributed.Specs.Integration
{
public abstract class CacheRoundTripSpecsAsyncBase<TCache> : CacheRoundTripSpecsBase
{
protected CacheRoundTripSpecsAsyncBase(ICachePolicyFactory cachePolicyFactory) : base(cachePolicyFactory)
{
}

public override async Task Should_roundtrip_this_variant_of<TResult>(TResult testValue)
{
// Arrange
Expand Down Expand Up @@ -46,6 +48,4 @@ public override async Task Should_roundtrip_this_variant_of<TResult>(TResult tes
underlyingDelegateExecuteCount.Should().Be(1);
}
}
}

#endif
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Polly.Caching.Distributed.Specs.Integration
{
public interface ICachePolicyFactory
{
(ISyncCacheProvider<TResult>, ISyncPolicy<TResult>) CreateSyncCachePolicy<TCache, TResult>();
(IAsyncCacheProvider<TResult>, IAsyncPolicy<TResult>) CreateAsyncCachePolicy<TCache, TResult>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

namespace Polly.Caching.Distributed.Specs.Integration
{
public class CachePolicyFactory
public class MemoryDistributedCachePolicyFactory : ICachePolicyFactory
{
public static (ISyncCacheProvider<TResult>, ISyncPolicy<TResult>) CreateSyncCachePolicy<TCache, TResult>()
public (ISyncCacheProvider<TResult>, ISyncPolicy<TResult>) CreateSyncCachePolicy<TCache, TResult>()
{
var memoryIDistributedCache = new MemoryDistributedCache(Options.Create(new MemoryDistributedCacheOptions()));
ISyncCacheProvider<TResult> memoryIDistributedCacheProvider;
Expand All @@ -32,7 +32,7 @@ public static (ISyncCacheProvider<TResult>, ISyncPolicy<TResult>) CreateSyncCach
return (memoryIDistributedCacheProvider, policy);
}

public static (IAsyncCacheProvider<TResult>, IAsyncPolicy<TResult>) CreateAsyncCachePolicy<TCache, TResult>()
public (IAsyncCacheProvider<TResult>, IAsyncPolicy<TResult>) CreateAsyncCachePolicy<TCache, TResult>()
{
var memoryIDistributedCache = new MemoryDistributedCache(Options.Create(new MemoryDistributedCacheOptions()));
IAsyncCacheProvider<TResult> memoryIDistributedCacheProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Integration\ByteArraySerializer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Integration\CachePolicyFactory.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Integration\MemoryDistributedCachePolicyFactory.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Integration\CacheRoundTripSpecsAsyncBase.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Integration\CacheRoundTripSpecsBase.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Integration\CacheRoundTripSpecsSyncBase.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Integration\CacheRoundTripSpecs_NetStandardIDistributedCacheProvider_Async_ByteArray.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Integration\CacheRoundTripSpecs_NetStandardIDistributedCacheProvider_Async_String.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Integration\CacheRoundTripSpecs_NetStandardIDistributedCacheProvider_Sync_ByteArray.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Integration\CacheRoundTripSpecs_NetStandardIDistributedCacheProvider_Sync_String.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Integration\ICachePolicyFactory.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Unit\CacheProviderHelperTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Unit\NetStandardIDistributedCacheByteArrayProviderSpecs.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Unit\NetStandardIDistributedCacheStringProviderSpecs.cs" />
Expand Down

0 comments on commit 62eab65

Please sign in to comment.