55using Microsoft . Extensions . DependencyInjection ;
66using Newtonsoft . Json ;
77using System ;
8+ using System . Threading . Tasks ;
89using System . Xml . Linq ;
910using Xunit ;
1011
1112namespace EasyCaching . UnitTests . CachingTests
1213{
13- public class EtcdCachingProviderTest : BaseCachingProviderTest
14+ public class EtcdCachingProviderTest // : BaseCachingProviderTest
1415 {
1516 private readonly string ProviderName = "EtcdTest" ;
16-
17+ private readonly IEasyCachingProvider _provider ;
1718
1819 public EtcdCachingProviderTest ( )
1920 {
20- _defaultTs = TimeSpan . FromSeconds ( 30 ) ;
21- }
22-
23- protected override IEasyCachingProvider CreateCachingProvider ( Action < BaseProviderOptions > additionalSetup )
24- {
25- IServiceCollection services = getServiceCollection ( ) ;
21+ // _defaultTs = TimeSpan.FromSeconds(30);
22+ var services = getServiceCollection ( ) ;
2623 IServiceProvider serviceProvider = services . BuildServiceProvider ( ) ;
27- return serviceProvider . GetService < IEasyCachingProvider > ( ) ;
24+ _provider = serviceProvider . GetService < IEasyCachingProvider > ( ) ;
2825 }
2926
27+ //protected override IEasyCachingProvider CreateCachingProvider(Action<BaseProviderOptions> additionalSetup)
28+ //{
29+ // IServiceCollection services = getServiceCollection();
30+ // IServiceProvider serviceProvider = services.BuildServiceProvider();
31+ // return serviceProvider.GetService<IEasyCachingProvider>();
32+ //}
33+
3034 private IServiceCollection getServiceCollection ( )
3135 {
3236 IServiceCollection services = new ServiceCollection ( ) ;
3337 services . AddEasyCaching ( option =>
3438 option . UseEtcd ( options =>
3539 {
36- options . Address = "http://127.0.0.1:2379 " ;
40+ options . Address = "http://121.196.220.148:12379 " ;
3741 options . Timeout = 30000 ;
3842 options . SerializerName = "json" ;
3943 } , ProviderName ) . WithJson ( jsonSerializerSettingsConfigure : x =>
@@ -50,10 +54,32 @@ public void Set_And_Get_Should_Succeed()
5054 {
5155 _provider . Set < string > ( "abc" , "123" , TimeSpan . FromSeconds ( 60 ) ) ;
5256 var val = _provider . Get < string > ( "abc" ) ;
53- Assert . True ( val . HasValue ) ;
5457 Assert . Equal ( "123" , val . Value ) ;
5558 }
5659
60+ [ Fact ]
61+ public async Task SetAsync_And_GetAsync_Should_Succeed ( )
62+ {
63+ await _provider . SetAsync < string > ( "abcd" , "1234" , TimeSpan . FromSeconds ( 60 ) ) ;
64+ var val = await _provider . GetAsync < string > ( "abcd" ) ;
65+ Assert . True ( val . HasValue ) ;
66+ Assert . Equal ( "1234" , val . Value ) ;
67+ }
68+
69+ [ Fact ]
70+ public void Remove_Should_Succeed ( )
71+ {
72+ _provider . Set < string > ( "abcf" , "123" , TimeSpan . FromSeconds ( 60 ) ) ;
73+ _provider . Remove ( "abcf" ) ;
74+ }
75+
76+ [ Fact ]
77+ public async Task RemoveAsync_Should_Succeed ( )
78+ {
79+ await _provider . SetAsync < string > ( "abcf" , "123" , TimeSpan . FromSeconds ( 60 ) ) ;
80+ await _provider . RemoveAsync ( "abcf" ) ;
81+ }
82+
5783
5884 [ Fact ]
5985 public void Use_Configuration_Options_Should_Succeed ( )
@@ -66,11 +92,5 @@ public void Use_Configuration_Options_Should_Succeed()
6692 Assert . Equal ( ProviderName , dbProvider . ProviderName ) ;
6793 }
6894
69- [ Fact ]
70- protected override void GetByPrefix_Should_Succeed ( )
71- {
72-
73- }
74-
7595 }
7696}
0 commit comments