Skip to content

Commit c009b81

Browse files
committed
Improve GetValueOrCreateAsyncTest
1 parent 29fdac5 commit c009b81

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

Enyim.Caching.Tests/MemcachedClientGetTests.cs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,35 @@ public void When_Getting_SByte_Result_Is_Successful()
102102
public async Task GetValueOrCreateAsyncTest()
103103
{
104104
var key = "GetValueOrCreateAsyncTest_" + Guid.NewGuid();
105-
await _client.GetValueOrCreateAsync(key, 10, () => GenerateValue());
106-
var cacheValue = await _client.GetValueAsync<string>(key);
107-
Assert.Equal(nameof(GetValueOrCreateAsyncTest), cacheValue);
105+
var posts1 = await _client.GetValueOrCreateAsync(
106+
key,
107+
10,
108+
async () => await GenerateValue());
109+
Assert.NotNull(posts1);
110+
111+
var posts2 = await _client.GetValueAsync<IEnumerable<BlogPost>>(key);
112+
Assert.NotNull(posts2);
113+
114+
Assert.Equal(posts1.First().Title, posts2.First().Title);
108115
}
109116

110-
private Task<string> GenerateValue()
117+
private Task<IEnumerable<BlogPost>> GenerateValue()
111118
{
112-
return Task.FromResult(nameof(GetValueOrCreateAsyncTest));
119+
var posts = new List<BlogPost>()
120+
{
121+
new BlogPost{ Title = "test title 1", Body = "test body 1" },
122+
new BlogPost{ Title = "test title 2", Body = "test body 2" }
123+
};
124+
125+
return Task.FromResult(posts.AsEnumerable());
113126
}
114127
}
128+
129+
internal class BlogPost
130+
{
131+
public string Title { get; set; }
132+
public string Body { get; set; }
133+
}
115134
}
116135

117136
#region [ License information ]

Enyim.Caching.Tests/MemcachedClientTestsBase.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ protected string GetUniqueKey(string prefix = null)
3939

4040
protected IEnumerable<string> GetUniqueKeys(string prefix = null, int max = 5)
4141
{
42-
4342
var keys = new List<string>(max);
4443
for (int i = 0; i < max; i++)
4544
{

0 commit comments

Comments
 (0)