Esempio n. 1
0
        public async Task GetTokenAsync_WhenFirstRequestFails_ShouldCallPostTwice()
        {
            var fixtures = new HmrcAuthTokenBrokerTestFixtures()
                           .WithInitialTaskResult(() => throw new HttpRequestException("Initial token request has failed"));

            var svc = fixtures.CreateHmrcAuthTokenBroker();

            var accessToken = await svc.GetTokenAsync();

            fixtures.OAuthTokenServiceMock.Verify(ots => ots.GetAccessToken(It.IsAny <string>()), Times.Exactly(2));
        }
Esempio n. 2
0
        public async Task GetTokenAsync_InitialRequestFails_ShouldStillGoOnToGetToken()
        {
            var fixtures = new HmrcAuthTokenBrokerTestFixtures()
                           .WithInitialTaskResult(() => throw new HttpRequestException("Initial token request has failed"));

            var svc = fixtures.CreateHmrcAuthTokenBroker();

            var accessToken = await svc.GetTokenAsync();

            Assert.IsNotNull(accessToken);
        }
Esempio n. 3
0
        public async Task GetTokenAsync_WhenFirstSucceeds_ShouldReturnExpectedToken()
        {
            var accessToken  = Guid.NewGuid().ToString();
            var refreshToken = Guid.NewGuid().ToString();

            var fixtures = new HmrcAuthTokenBrokerTestFixtures()
                           .WithInitialTaskResult(() => new OAuthAccessToken
            {
                AccessToken  = accessToken,
                RefreshToken = refreshToken
            });

            var svc = fixtures.CreateHmrcAuthTokenBroker();

            var token = await svc.GetTokenAsync();

            Assert.AreEqual(accessToken, token.AccessToken, "Access token is not the expected value");
            Assert.AreEqual(refreshToken, token.RefreshToken, "Refresh token is not the expected value");
        }