Пример #1
0
        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");
        }
Пример #2
0
 public void GetAccessTest()
 {
     var service = new WeChatService();
     service.Setup(wechat, TimeSpan.FromSeconds(0));
     var accessToken = service.GetAccessToken(testAppId, testAppSecret);
     Assert.AreEqual(accessToken, testAccessToken);
 }
Пример #3
0
        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);
        }
Пример #4
0
        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");
        }
Пример #5
0
 public void GetAccessTestByEmptyAppSecret()
 {
     var service = new WeChatService();
     service.GetAccessToken(testAppId, string.Empty);
 }
Пример #6
0
        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");
        }
Пример #7
0
        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);
        }