Skip to content

Commit

Permalink
fix: restore Post's public API accepting HttpClient (#2777)
Browse files Browse the repository at this point in the history
* fix: restore Post's public API accepting HttpClient

Fixes the error:

```
error CS1503: Argument 3: cannot convert from 'System.Net.Http.HttpClient' to 'Microsoft.CodeAnalysis.Sarif.HttpClientWrapper'
```

which was introduced by an inadvertant public signature change in #2772

NB: The return type change from `Task<bool>` to `Task<(bool, string)>`
was intentional and is left in tact.

* fix type confusion
  • Loading branch information
rwoll committed Feb 9, 2024
1 parent ea17e3c commit f268632
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
15 changes: 14 additions & 1 deletion src/Sarif/Core/SarifLog.cs
Expand Up @@ -78,6 +78,14 @@ public static SarifLog Load(Stream source, bool deferred = false)
/// <param name="httpClient"></param>
/// <returns>If the SarifLog has been posted successfully.</returns>
public static async Task<(bool, string)> Post(Uri postUri,
string filePath,
IFileSystem fileSystem,
HttpClient httpClient)
{
return await Post(postUri, filePath, fileSystem, new HttpClientWrapper(httpClient));
}

internal static async Task<(bool, string)> Post(Uri postUri,
string filePath,
IFileSystem fileSystem,
HttpClientWrapper httpClient)
Expand Down Expand Up @@ -126,7 +134,12 @@ public static SarifLog Load(Stream source, bool deferred = false)
/// <param name="postUri"></param>
/// <param name="stream"></param>
/// <param name="httpClient"></param>
public static async Task<HttpResponseMessage> Post(Uri postUri, Stream stream, HttpClientWrapper httpClient)
public static async Task<HttpResponseMessage> Post(Uri postUri, Stream stream, HttpClient httpClient)
{
return await Post(postUri, stream, new HttpClientWrapper(httpClient));
}

internal static async Task<HttpResponseMessage> Post(Uri postUri, Stream stream, HttpClientWrapper httpClient)
{
if (postUri == null)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Test.UnitTests.Sarif/Core/SarifLogTests.cs
Expand Up @@ -230,7 +230,7 @@ public async Task SarifLog_PostStream_WithInvalidParameters_ShouldThrowArgumentN
{
await SarifLog.Post(new Uri("https://github.com/microsoft/sarif-sdk"),
new MemoryStream(),
null);
(HttpClientWrapper)null);
});
}

Expand All @@ -245,7 +245,7 @@ public async Task SarifLog_PostFile_WithInvalidParameters_ShouldThrowException()
await SarifLog.Post(postUri: null,
filePath,
fileSystem.Object,
httpClient: null);
httpClient: (HttpClientWrapper)null);
});

filePath = "SomeFile.txt";
Expand All @@ -258,7 +258,7 @@ public async Task SarifLog_PostFile_WithInvalidParameters_ShouldThrowException()
await SarifLog.Post(postUri: null,
filePath,
fileSystem.Object,
httpClient: null);
httpClient: (HttpClientWrapper)null);
});
}

Expand All @@ -283,7 +283,7 @@ public async Task SarifLog_PostFile_PostTests()
(bool, string) logPosted = await SarifLog.Post(postUri,
filePath,
fileSystem.Object,
httpClient: null);
httpClient: (HttpClientWrapper)null);
logPosted.Item1.Should().BeFalse("with no results or notifications");
logPosted.Item2.Should().Contain("was skipped");

Expand Down

0 comments on commit f268632

Please sign in to comment.