public void GetAccessTest() { var service = new WeChatService(); service.Setup(wechat, TimeSpan.FromSeconds(0)); var accessToken = service.GetAccessToken(testAppId, testAppSecret); Assert.AreEqual(accessToken, testAccessToken); }
private static IWeChatServices GetWeChatServices(IServiceProvider services) { IWeChatServices wechat = null; #if net40 var httpContext = HttpContext.Current; if (httpContext != null) { wechat = httpContext.Items[ContextKey_WeChatService] as IWeChatServices; } #endif if (services != null) { wechat = TryGetService <IWeChatServices>(services); } if (wechat == null) { var wechatProvider = new Providers.TencentWeChat(); wechat = new Services.Impl.WeChatService(); wechat.Setup(wechatProvider, DefaultCacheDuration); } return(wechat); }
public void ApiInvokingCouldReachLimitation() { var service = new WeChatService(); wechat = new WeChatWithApiLimitation(1); service.Setup(wechat, TimeSpan.FromSeconds(0)); service.GetAccessToken("dummy_appid", "dummy_secret"); service.GetAccessToken("dummy_appid", "dummy_secret"); }
public void GetWeChatServiceWithProvider() { var service = new WeChatService(); wechat = new WeChatWithApiLimitation(2); service.Setup(wechat, TimeSpan.FromSeconds(0)); var accessToken = service.GetAccessToken("dummy_appid", "dummy_secret"); Assert.IsTrue(accessToken.StartsWith("access_token_for_dummy_appid")); Assert.AreNotSame(accessToken.StartsWith("access_token_for_dummy_appid"), accessToken); var jsTicket = service.GetTicket("my_access_token"); Assert.IsTrue(jsTicket.StartsWith("jsticket_my_access_token")); Assert.AreNotSame(service.GetTicket("my_access_token"), jsTicket); }
private static IWeChatServices GetWeChatServices(){ IWeChatServices wechat = null; var httpContext = HttpContext.Current; if (httpContext != null) { wechat = httpContext.Items[ ContextKey_WeChatService] as IWeChatServices; } if (wechat == null) { var wechatProvider = new Providers.TencentWeChat(); wechat = new Services.Impl.WeChatService(); wechat.Setup(wechatProvider, DefaultCacheDuration); } return wechat; }
public void ApiInvokingLimitationIsSeperatedOverAppIdsAndAccessTokens() { var service = new WeChatService(); wechat = new WeChatWithApiLimitation(1); service.Setup(wechat, TimeSpan.FromSeconds(0)); service.GetAccessToken("dummy_appid", "dummy_secret"); service.GetAccessToken("another_dummy_appid", "dummy_secret"); service.GetTicket("my_access_token"); service.GetTicket("another_my_access_token"); }
public void GetAccessTestByEmptyAppSecret() { var service = new WeChatService(); service.GetAccessToken(testAppId, string.Empty); }
public void CacheInWeChatServiceCouldExpire() { var service = new WeChatService(); wechat = new WeChatWithApiLimitation(1); service.Setup(wechat, TimeSpan.FromSeconds(1)); service.GetAccessToken("dummy_appid", "dummy_secret"); Thread.Sleep(2000); service.GetAccessToken("dummy_appid", "dummy_secret"); }
public void WeChatServiceCanCache() { var service = new WeChatService(); wechat = new WeChatWithApiLimitation(1); service.Setup(wechat, TimeSpan.FromSeconds(1)); var accessToken1 = service.GetAccessToken("dummy_appid", "dummy_secret"); var accessToken2 = service.GetAccessToken("dummy_appid", "dummy_secret"); Assert.AreEqual(accessToken1, accessToken2); }