コード例 #1
0
        public async Task GetToken_ExistingToken_DoesNotRequestNewToken()
        {
            var tvDbConnection = new JsonConnection(new TestHttpClient(), new JsonSerialiser(), _logManager);

            var token = new TvDbToken(tvDbConnection, Secrets.TvDbApiKey, _logManager);

            var token1 = await token.GetTokenAsync();

            var token2 = await token.GetTokenAsync();

            token2.IsSome.Should().BeTrue();
            token2.ValueUnsafe().Should().Be(token1.ValueUnsafe());
        }
コード例 #2
0
        public async Task GetToken_FailedRequest_ReturnsNone()
        {
            var tvDbConnection = new JsonConnection(new TestHttpClient(), new JsonSerialiser(), _logManager);

            var token = new TvDbToken(tvDbConnection, "NotValid", _logManager);

            var returnedToken = await token.GetTokenAsync();

            returnedToken.IsSome.Should().BeFalse();
        }
コード例 #3
0
        public async Task GetToken_NoExistingToken_GetsNewToken()
        {
            var tvDbConnection = new JsonConnection(new TestHttpClient(), new JsonSerialiser(), _logManager);

            var token = new TvDbToken(tvDbConnection, Secrets.TvDbApiKey, _logManager);

            var returnedToken = await token.GetTokenAsync();

            returnedToken.IsSome.Should().BeTrue();
            returnedToken.ValueUnsafe().Should().NotBeNullOrWhiteSpace();
        }
コード例 #4
0
        public async Task GetToken_ExistingToken_DoesNotRequestNewToken()
        {
            var jsonConnection = Substitute.For <IJsonConnection>();

            jsonConnection.PostAsync(Arg.Is <LoginRequest>(r =>
                                                           r.Url == "https://api.thetvdb.com/login" &&
                                                           (r.Data as LoginRequest.RequestData).ApiKey == "apiKey"), Option <string> .None)
            .Returns(new Response <LoginRequest.Response>(new LoginRequest.Response("TOKEN")));

            var token = new TvDbToken(jsonConnection, "apiKey", this.logManager);

            await token.GetTokenAsync();

            var returnedToken = await token.GetTokenAsync();

            returnedToken.IsSome.Should().BeTrue();
            returnedToken.ValueUnsafe().Should().Be("TOKEN");

            await jsonConnection.ReceivedWithAnyArgs(1).PostAsync <LoginRequest.Response>(null, Option <string> .None);
        }
コード例 #5
0
        public async Task GetToken_FailedRequest_ReturnsNone()
        {
            var jsonConnection = Substitute.For <IJsonConnection>();

            jsonConnection.PostAsync(Arg.Is <LoginRequest>(r =>
                                                           r.Url == "https://api.thetvdb.com/login" &&
                                                           (r.Data as LoginRequest.RequestData).ApiKey == "apiKey"), Option <string> .None)
            .Returns(new FailedRequest(HttpStatusCode.BadRequest, "Failed"));

            var token = new TvDbToken(jsonConnection, "apiKey", this.logManager);

            var returnedToken = await token.GetTokenAsync();

            returnedToken.IsSome.Should().BeFalse();
        }