Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
maint: Adds test coverage for non generated features (#48)
* adds auth tests * adds coverage for handlers * code formatting clean up * adds coverage * updates build tast to output coverage * cleans up dev notes * updates workflow to filter out generated files * reworks file filters for exclusions * adds coverage badging and PR comment * reworks to use xplat format * new results file * disabled fail below min * clean up left over dev comments * run coverage and display in CI only
- Loading branch information
Showing
13 changed files
with
139 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using GitHub.Octokit.Authentication; | ||
using Microsoft.Kiota.Abstractions; | ||
using Xunit; | ||
|
||
public class TokenAuthenticationProviderTests | ||
{ | ||
private const string ValidClientId = "validClientId"; | ||
private const string ValidToken = "validToken"; | ||
private TokenAuthenticationProvider _provider; | ||
|
||
public TokenAuthenticationProviderTests() | ||
{ | ||
_provider = new TokenAuthenticationProvider(ValidClientId, ValidToken); | ||
} | ||
|
||
[Fact] | ||
public void Constructor_ThrowsException_WhenClientIdIsEmpty() | ||
{ | ||
Assert.Throws<ArgumentException>(() => new TokenAuthenticationProvider("", ValidToken)); | ||
} | ||
|
||
[Fact] | ||
public void Constructor_ThrowsException_WhenTokenIsEmpty() | ||
{ | ||
Assert.Throws<ArgumentException>(() => new TokenAuthenticationProvider(ValidClientId, "")); | ||
} | ||
|
||
[Fact] | ||
public async Task AuthenticateRequestAsync_ThrowsException_WhenRequestIsNull() | ||
{ | ||
await Assert.ThrowsAsync<ArgumentNullException>(() => _provider.AuthenticateRequestAsync(null, null)); | ||
} | ||
|
||
[Fact] | ||
public async Task AuthenticateRequestAsync_AddsAuthorizationHeader_WhenRequestIsValid() | ||
{ | ||
var request = new RequestInformation(); | ||
await _provider.AuthenticateRequestAsync(request); | ||
var headerToken = request.Headers["Authorization"].FirstOrDefault<string>(); | ||
|
||
Assert.True(request.Headers.ContainsKey("Authorization")); | ||
Assert.Equal($"Bearer {ValidToken}", headerToken); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using GitHub.Octokit.Client; | ||
using GitHub.Octokit.Client.Middleware; | ||
using Xunit; | ||
|
||
|
||
public class TestHandler1 : DelegatingHandler { } | ||
public class TestHandler2 : DelegatingHandler { } | ||
|
||
public class ClientFactoryTests | ||
{ | ||
|
||
[Fact] | ||
public void Creates_Client_With_Default_Timeout() | ||
{ | ||
var clientFactory = ClientFactory.Create(); | ||
Assert.Equal(TimeSpan.FromSeconds(100), clientFactory.Timeout); | ||
} | ||
|
||
[Fact] | ||
public void Creates_Client_Persists_Set_Timeout() | ||
{ | ||
var clientFactory = ClientFactory.Create(); | ||
clientFactory.Timeout = TimeSpan.FromSeconds(5); | ||
Assert.Equal(TimeSpan.FromSeconds(5), clientFactory.Timeout); | ||
} | ||
|
||
[Fact] | ||
public void Create_Returns_NonNullHttpClient() | ||
{ | ||
HttpMessageHandler handler = new HttpClientHandler(); | ||
var client = ClientFactory.Create(handler); | ||
Assert.NotNull(client); | ||
} | ||
|
||
[Fact] | ||
public void CreateDefaultHandlers_Returns_Expected_Handlers() | ||
{ | ||
var handlers = ClientFactory.CreateDefaultHandlers(); | ||
Assert.Contains(handlers, h => h is APIVersionHandler); | ||
Assert.Contains(handlers, h => h is UserAgentHandler); | ||
} | ||
|
||
[Fact] | ||
public void ChainHandlersCollectionAndGetFirstLink_ChainsHandlersCorrectly() | ||
{ | ||
var handlers = new DelegatingHandler[] | ||
{ | ||
new TestHandler1(), | ||
new TestHandler2() | ||
}; | ||
var firstHandler = ClientFactory.ChainHandlersCollectionAndGetFirstLink(null, handlers); | ||
Assert.IsType<TestHandler1>(firstHandler); | ||
Assert.IsType<TestHandler2>(firstHandler.InnerHandler); | ||
} | ||
|
||
[Fact] | ||
public void GetDefaultHttpMessageHandler_Returns_NonNullHttpMessageHandler() | ||
{ | ||
var handler = ClientFactory.GetDefaultHttpMessageHandler(); | ||
Assert.NotNull(handler); | ||
} | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.