@@ -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 ]
0 commit comments