|
9 | 9 | using Microsoft.Extensions.DependencyInjection; |
10 | 10 | using Microsoft.Extensions.Configuration; |
11 | 11 | using Microsoft.Extensions.Logging; |
| 12 | +using System.Threading.Tasks; |
12 | 13 |
|
13 | 14 | namespace Enyim.Caching.Tests |
14 | 15 | { |
15 | 16 | public abstract class MemcachedClientTestsBase |
16 | 17 | { |
17 | 18 | protected MemcachedClient _client; |
18 | 19 |
|
19 | | - public MemcachedClientTestsBase() |
| 20 | + public MemcachedClientTestsBase(Action<MemcachedClientOptions> onAddEnyimMemcached = null) |
20 | 21 | { |
21 | 22 | IServiceCollection services = new ServiceCollection(); |
22 | | - services.AddEnyimMemcached(options => options.AddServer("memcached", 11211)); |
| 23 | + services.AddEnyimMemcached(options => |
| 24 | + { |
| 25 | + options.AddServer("memcached", 11211); |
| 26 | + if (onAddEnyimMemcached != null) |
| 27 | + { |
| 28 | + onAddEnyimMemcached(options); |
| 29 | + } |
| 30 | + }); |
| 31 | + |
23 | 32 | services.AddLogging(builder => builder.SetMinimumLevel(LogLevel.Debug).AddConsole()); |
24 | 33 | IServiceProvider serviceProvider = services.BuildServiceProvider(); |
25 | 34 | _client = serviceProvider.GetService<IMemcachedClient>() as MemcachedClient; |
@@ -63,6 +72,20 @@ protected IStoreOperationResult Store(StoreMode mode = StoreMode.Set, string key |
63 | 72 | return _client.ExecuteStore(mode, key, value); |
64 | 73 | } |
65 | 74 |
|
| 75 | + protected Task<bool> StoreAsync(StoreMode mode = StoreMode.Set, string key = null, object value = null) |
| 76 | + { |
| 77 | + if (string.IsNullOrEmpty(key)) |
| 78 | + { |
| 79 | + key = GetUniqueKey("store"); |
| 80 | + } |
| 81 | + |
| 82 | + if (value == null) |
| 83 | + { |
| 84 | + value = GetRandomString(); |
| 85 | + } |
| 86 | + return _client.StoreAsync(mode, key, value, TimeSpan.MaxValue); |
| 87 | + } |
| 88 | + |
66 | 89 | protected void StoreAssertPass(IStoreOperationResult result) |
67 | 90 | { |
68 | 91 | Assert.True(result.Success, "Success was false"); |
@@ -95,6 +118,15 @@ protected void GetAssertFail(IGetOperationResult result) |
95 | 118 | Assert.Null(result.Value); |
96 | 119 | } |
97 | 120 |
|
| 121 | + protected void GetAssertFail(IGetOperationResult<object> result) |
| 122 | + { |
| 123 | + Assert.False(result.Success, "Success was true"); |
| 124 | + Assert.Equal((ulong)0, result.Cas); |
| 125 | + Assert.True(result.StatusCode > 0, "StatusCode not greater than 0"); |
| 126 | + Assert.False(result.HasValue, "HasValue was true"); |
| 127 | + Assert.Null(result.Value); |
| 128 | + } |
| 129 | + |
98 | 130 | protected void MutateAssertPass(IMutateOperationResult result, ulong expectedValue) |
99 | 131 | { |
100 | 132 | Assert.True(result.Success, "Success was false"); |
|
0 commit comments