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()); }
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(); }
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(); }
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); }
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(); }