コード例 #1
0
        public async Task SetTokenInCache()
        {
            var cacheEntry = new TestCacheEntry();
            var mockedCache = CreateEmptyMockedCache(cacheEntry);

            var tokenHelper = new TokenHelper(mockedCache.Object);
            tokenHelper._client = CreateClient();

            var token = await tokenHelper.ReadOrRetrieveToken(_settings);

            Assert.Equal("accessToken", ((TokenReply)cacheEntry.Value).access_token);
        }
コード例 #2
0
        public async Task ThrowsExceptionWhenCallFailed()
        {
            var cacheEntry = new TestCacheEntry();
            var mockedCache = CreateEmptyMockedCache(cacheEntry);

            var tokenHelper = new TokenHelper(mockedCache.Object);
            tokenHelper._client = CreateClient();

            _settings.OAuthPathAddition = "";

            await Assert.ThrowsAsync<Exception>(async () => await tokenHelper.ReadOrRetrieveToken(_settings));
        }
コード例 #3
0
        private Mock<IMemoryCache> CreateMockedCache(string key, TokenReply value, TestCacheEntry cacheEntry = null)
        {
            var mockCache = new Mock<IMemoryCache>();
            var cachedObject = value as object;

            mockCache.Setup(c => c.TryGetValue("", out cachedObject))
                .Returns(false);

            mockCache.Setup(c => c.TryGetValue(key, out cachedObject))
                .Returns(true);

            mockCache.Setup(c => c.CreateEntry(_cacheKey))
                .Returns(cacheEntry);

            return mockCache;
        }
コード例 #4
0
 private Mock<IMemoryCache> CreateEmptyMockedCache(TestCacheEntry cacheEntry = null)
 {
     return CreateMockedCache("", null, cacheEntry);
 }