Skip to content

Commit 658f015

Browse files
committed
Change tests for BinaryFormatterTranscoder
1 parent 26857ac commit 658f015

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

MemcachedTest/MemcachedClientTest.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,27 @@ public abstract class MemcachedClientTest
1919
private static readonly Enyim.Caching.ILog log = Enyim.Caching.LogManager.GetLogger(typeof(MemcachedClientTest));
2020
public const string TestObjectKey = "Hello_World";
2121

22-
protected virtual MemcachedClient GetClient(MemcachedProtocol protocol = MemcachedProtocol.Binary)
22+
protected virtual MemcachedClient GetClient(MemcachedProtocol protocol = MemcachedProtocol.Binary, bool useBinaryFormatterTranscoder = false)
2323
{
2424
IServiceCollection services = new ServiceCollection();
2525
services.AddEnyimMemcached(options =>
2626
{
2727
options.AddServer("memcached", 11211);
2828
options.Protocol = protocol;
29+
if (useBinaryFormatterTranscoder)
30+
{
31+
options.Transcoder = "BinaryFormatterTranscoder";
32+
}
2933
});
30-
services.AddLogging();
34+
services.AddLogging(builder => builder.SetMinimumLevel(LogLevel.Error).AddConsole());
35+
3136
IServiceProvider serviceProvider = services.BuildServiceProvider();
3237
var client = serviceProvider.GetService<IMemcachedClient>() as MemcachedClient;
3338
client.Remove("VALUE");
3439
return client;
3540
}
3641

42+
[Serializable]// This attribute is for BinaryFormatterTranscoder
3743
public class TestData
3844
{
3945
public TestData() { }
@@ -60,6 +66,11 @@ public async Task StoreObjectTest()
6066
{
6167
Assert.True(await client.StoreAsync(StoreMode.Set, TestObjectKey, td, DateTime.Now.AddSeconds(5)));
6268
}
69+
70+
using (MemcachedClient client = GetClient(MemcachedProtocol.Binary, true))
71+
{
72+
Assert.True(await client.StoreAsync(StoreMode.Set, TestObjectKey, td, DateTime.Now.AddSeconds(5)));
73+
}
6374
}
6475

6576
[Fact]
@@ -83,6 +94,18 @@ public void GetObjectTest()
8394
Assert.Equal(td2.FieldC, 19810619);
8495
Assert.True(td2.FieldD, "Object was corrupted.");
8596
}
97+
98+
using (MemcachedClient client = GetClient(MemcachedProtocol.Binary, true))
99+
{
100+
Assert.True(client.Store(StoreMode.Set, TestObjectKey, td), "Initialization failed.");
101+
TestData td2 = client.Get<TestData>(TestObjectKey);
102+
103+
Assert.NotNull(td2);
104+
Assert.Equal(td2.FieldA, "Hello");
105+
Assert.Equal(td2.FieldB, "World");
106+
Assert.Equal(td2.FieldC, 19810619);
107+
Assert.True(td2.FieldD, "Object was corrupted.");
108+
}
86109
}
87110

88111
[Fact]

MemcachedTest/MemcachedTest.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<ItemGroup>
77
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.0" />
88
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.0" />
9+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.0.0" />
910
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
1011
<PackageReference Include="xunit" Version="2.3.0-beta3-build3705" />
1112
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta3-build3705" />

0 commit comments

Comments
 (0)