New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds test coverage for non generated features #48
Changes from 12 commits
b084eb9
4432856
99ad685
3d48511
02bb596
8194739
7a1b8c0
85e906e
8d8e40e
a5c63f8
db1ec44
7c05bdf
c8b4e07
e6c7b91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,4 +28,24 @@ jobs: | |
run: dotnet build --no-incremental /p:SignAssembly=true /p:AssemblyOriginatorKeyFile=../key.snk | ||
|
||
- name: Test SDK | ||
run: dotnet test | ||
run: dotnet test --configuration Release --verbosity normal --collect:"XPlat Code Coverage" --results-directory ./coverage -p:ExcludeByFile="**/GitHub/**/*.cs" | ||
|
||
- name: Code Coverage Report | ||
uses: irongut/CodeCoverageSummary@v1.3.0 | ||
with: | ||
filename: coverage/**/coverage.cobertura.xml | ||
badge: true | ||
fail_below_min: false | ||
format: markdown | ||
hide_branch_rate: false | ||
hide_complexity: true | ||
indicators: true | ||
output: both | ||
thresholds: '60 80' | ||
|
||
- name: Add Coverage PR Comment | ||
uses: marocchino/sticky-pull-request-comment@v2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm also curious about this choice, since many other options exist here, like https://github.com/thollander/actions-comment-pull-request. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As with the above - this was the favored implementation and streamlined option. I'm not sure I am 100% sold on having a PR comment with coverage details - this is really try on the shoe and see if it fits. I am most likely going to pull this out and leave it as reporting in the CI step and leave bubbling up the results for another PR. |
||
if: github.event_name == 'pull_request' | ||
with: | ||
recreate: true | ||
path: code-coverage-results.md |
This file was deleted.
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); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
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); | ||
} | ||
|
||
// ChainHandlersCollectionAndGetFirstLink | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the purpose of this comment and the below one on line 58? Are they going to be expanded upon? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah this needs to be cleaned up - I began grouping tests and this was just a remark to keep things ordered for me. |
||
[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); | ||
} | ||
|
||
|
||
// GetDefaultHttpMessageHandler | ||
[Fact] | ||
public void GetDefaultHttpMessageHandler_Returns_NonNullHttpMessageHandler() | ||
{ | ||
var handler = ClientFactory.GetDefaultHttpMessageHandler(); | ||
Assert.NotNull(handler); | ||
} | ||
|
||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mind explaining why you've gone with this tool? I haven't heard of it before and I'm curious what the alternatives and tradeoffs were.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure... it was the most streamlined, most starred, I would've liked it to be more recently maintained - some other implementations had gists, repos, and accounts tied to it so while I was evaluating different tooling and trying to decide if we even want to do something like this - it seemed to be the most reasonable option.