Skip to content

Commit

Permalink
Use raw string literals
Browse files Browse the repository at this point in the history
  • Loading branch information
d4n3436 committed Jun 25, 2024
1 parent 561fd99 commit df29165
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Apis/Bing/BingVisualSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void Dispose()

private static HttpRequestMessage BuildRequest(string url, string invokedSkill, BingSafeSearchLevel safeSearch = BingSafeSearchLevel.Moderate, string? language = null)
{
string jsonRequest = $"{{\"imageInfo\":{{\"url\":\"{url}\",\"source\":\"Url\"}},\"knowledgeRequest\":{{\"invokedSkills\":[\"{invokedSkill}\"]}}}}";
string jsonRequest = $$"""{"imageInfo":{"url":"{{url}}","source":"Url"},"knowledgeRequest":{"invokedSkills":["{{invokedSkill}}"]}}""";
var content = new MultipartFormDataContent
{
{ new StringContent(jsonRequest), "knowledgeRequest" }
Expand Down
4 changes: 2 additions & 2 deletions src/Services/BotListService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
Method = HttpMethod.Post,
RequestUri = new Uri($"https://top.gg/api/bots/{_discordClient.CurrentUser.Id}/stats"),
Content = new StringContent($"{{\"server_count\": {serverCount},\"shard_count\":{shardCount}}}", Encoding.UTF8, "application/json"),
Content = new StringContent($$"""{"server_count":{{serverCount}},"shard_count":{{shardCount}}}""", Encoding.UTF8, "application/json"),
Headers =
{
Authorization = new AuthenticationHeaderValue(token)
Expand All @@ -151,7 +151,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
Method = HttpMethod.Post,
RequestUri = new Uri($"https://discord.bots.gg/api/v1/bots/{_discordClient.CurrentUser.Id}/stats"),
Content = new StringContent($"{{\"guildCount\": {serverCount},\"shardCount\":{shardCount}}}", Encoding.UTF8, "application/json"),
Content = new StringContent($$"""{"guildCount":{{serverCount}},"shardCount":{{shardCount}}}""", Encoding.UTF8, "application/json"),
Headers =
{
Authorization = new AuthenticationHeaderValue(token)
Expand Down
2 changes: 1 addition & 1 deletion tests/Fergun.Tests/Apis/WolframAlphaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public void ArrayOrObjectConverter_Throws_Exceptions()

public static TheoryData<string, IReadOnlyList<WolframAlphaWarning>> ArrayOrObjectConverterData()
{
const string json = "{\"text\":\"Error message\"}";
const string json = """{"text":"Error message"}""";
var suggestions = new[] { new WolframAlphaWarning("Error message") };

return new TheoryData<string, IReadOnlyList<WolframAlphaWarning>>
Expand Down
8 changes: 4 additions & 4 deletions tests/Fergun.Tests/Apis/YandexImageSearchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public async Task OcrAsync_Throws_YandexException_If_Captcha_Is_Present()
.Protected()
.As<HttpClient>()
.SetupSequence(x => x.SendAsync(It.IsAny<HttpRequestMessage>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("{\"image_id\":\"test\",\"image_shard\":0}") })
.ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("{\"type\":\"captcha\"}") });
.ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("""{"image_id":"test","image_shard":0}""") })
.ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("""{"type":"captcha"}""") });

var yandexImageSearch = new YandexImageSearch(new HttpClient(messageHandlerMock.Object));

Expand Down Expand Up @@ -92,7 +92,7 @@ public async Task ReverseImageSearchAsync_Throws_YandexException_If_Captcha_Is_P
.Protected()
.As<HttpClient>()
.SetupSequence(x => x.SendAsync(It.IsAny<HttpRequestMessage>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("{\"type\":\"captcha\"}") });
.ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("""{"type":"captcha"}""") });

var yandexImageSearch = new YandexImageSearch(new HttpClient(messageHandlerMock.Object));

Expand Down Expand Up @@ -130,7 +130,7 @@ public void YandexException_Has_Expected_Values()
}

[Theory]
[InlineData("\"{title:&quot;a&quot;}\"", "{title:\"a\"}")]
[InlineData("\"{title:&quot;a&quot;}\"", """{title:"a"}""")]
[InlineData("\"D&amp;D\"", "D&D")]
public void HtmlEncodingConverter_Returns_Expected_Values(string encodedString, string decodedString)
{
Expand Down

0 comments on commit df29165

Please sign in to comment.