Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Commit 7f5045e

Browse files
committed
Fixed Redis cache extension and tests
1 parent a879001 commit 7f5045e

File tree

3 files changed

+53
-20
lines changed

3 files changed

+53
-20
lines changed

src/Microsoft.Framework.Caching.Redis/CachingServiceExtensions.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33

44
using Microsoft.Framework.Caching.Distributed;
55
using Microsoft.Framework.Caching.Redis;
6+
using Microsoft.Framework.DependencyInjection.Extensions;
7+
using Microsoft.Framework.Internal;
8+
69
namespace Microsoft.Framework.DependencyInjection
710
{
811
public static class CachingServicesExtensions
912
{
10-
public static IServiceCollection AddRedisCache(this IServiceCollection collection)
13+
public static IServiceCollection AddRedisCache([NotNull] this IServiceCollection collection)
1114
{
1215
collection.AddOptions();
1316
collection.TryAdd(ServiceDescriptor.Singleton<IDistributedCache, RedisCache>());

test/Microsoft.Framework.Caching.Redis.Tests/CacheServiceExtensionsTests.cs

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
using System;
55
using System.IO;
66
using System.Linq;
7+
using System.Threading.Tasks;
78
using Microsoft.Framework.Caching.Distributed;
89
using Microsoft.Framework.DependencyInjection;
910
using Xunit;
11+
1012
namespace Microsoft.Framework.Caching.Redis
1113
{
1214
public class CacheServiceExtensionsTests
1315
{
14-
15-
1616
[Fact]
17-
public void AddRedisCache_RegistersDistributedCacheAsTransient()
17+
public void AddRedisCache_RegistersDistributedCacheAsSingleton()
1818
{
1919
// Arrange
2020
var services = new ServiceCollection();
@@ -26,7 +26,7 @@ public void AddRedisCache_RegistersDistributedCacheAsTransient()
2626
var distributedCache = services.FirstOrDefault(desc => desc.ServiceType == typeof(IDistributedCache));
2727

2828
Assert.NotNull(distributedCache);
29-
Assert.Equal(ServiceLifetime.Transient, distributedCache.Lifetime);
29+
Assert.Equal(ServiceLifetime.Singleton, distributedCache.Lifetime);
3030
}
3131

3232
[Fact]
@@ -37,7 +37,7 @@ public void AddRedisCache_DoesNotReplaceUserRegisteredServices()
3737
services.AddScoped<IDistributedCache, TestDistributedCache>();
3838

3939
// Act
40-
services.AddCaching();
40+
services.AddRedisCache();
4141

4242
// Assert
4343
var serviceProvider = services.BuildServiceProvider();
@@ -49,25 +49,54 @@ public void AddRedisCache_DoesNotReplaceUserRegisteredServices()
4949
Assert.IsType<TestDistributedCache>(serviceProvider.GetRequiredService<IDistributedCache>());
5050
}
5151

52-
5352
private class TestDistributedCache : IDistributedCache
5453
{
5554
public void Connect()
5655
{
5756
throw new NotImplementedException();
5857
}
5958

59+
public Task ConnectAsync()
60+
{
61+
throw new NotImplementedException();
62+
}
63+
64+
public byte[] Get(string key)
65+
{
66+
throw new NotImplementedException();
67+
}
68+
69+
public Task<byte[]> GetAsync(string key)
70+
{
71+
throw new NotImplementedException();
72+
}
73+
6074
public void Refresh(string key)
6175
{
6276
throw new NotImplementedException();
6377
}
6478

79+
public Task RefreshAsync(string key)
80+
{
81+
throw new NotImplementedException();
82+
}
83+
6584
public void Remove(string key)
6685
{
6786
throw new NotImplementedException();
6887
}
6988

70-
public Stream Set(string key, object state, Action<ICacheContext> create)
89+
public Task RemoveAsync(string key)
90+
{
91+
throw new NotImplementedException();
92+
}
93+
94+
public void Set(string key, byte[] value, DistributedCacheEntryOptions options)
95+
{
96+
throw new NotImplementedException();
97+
}
98+
99+
public Task SetAsync(string key, byte[] value, DistributedCacheEntryOptions options)
71100
{
72101
throw new NotImplementedException();
73102
}
Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
2-
"dependencies": {
3-
"Microsoft.AspNet.Testing": "1.0.0-*",
4-
"Microsoft.Framework.Caching.Redis": "1.0.0-*",
5-
"Microsoft.Framework.DependencyInjection": "1.0.0-*",
6-
"xunit.runner.dnx": "2.1.0-*"
7-
},
8-
"commands": {
9-
"test": "xunit.runner.dnx"
10-
},
11-
"frameworks": {
12-
"dnx451": { }
13-
}
2+
"dependencies": {
3+
"Microsoft.AspNet.Testing": "1.0.0-*",
4+
"Microsoft.Framework.Caching.Redis": "1.0.0-*",
5+
"Microsoft.Framework.DependencyInjection": "1.0.0-*",
6+
"xunit": "2.1.0-*",
7+
"xunit.runner.dnx": "2.1.0-*"
8+
},
9+
"commands": {
10+
"test": "xunit.runner.dnx"
11+
},
12+
"frameworks": {
13+
"dnx451": { }
14+
}
1415
}

0 commit comments

Comments
 (0)