From df2916570adca9e0502a6e01e49fb7a51c67c74e Mon Sep 17 00:00:00 2001 From: d4n Date: Mon, 24 Jun 2024 21:57:32 -0500 Subject: [PATCH] Use raw string literals --- src/Apis/Bing/BingVisualSearch.cs | 2 +- src/Services/BotListService.cs | 4 ++-- tests/Fergun.Tests/Apis/WolframAlphaTests.cs | 2 +- tests/Fergun.Tests/Apis/YandexImageSearchTests.cs | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Apis/Bing/BingVisualSearch.cs b/src/Apis/Bing/BingVisualSearch.cs index c7f37e2..e582462 100644 --- a/src/Apis/Bing/BingVisualSearch.cs +++ b/src/Apis/Bing/BingVisualSearch.cs @@ -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" } diff --git a/src/Services/BotListService.cs b/src/Services/BotListService.cs index 59a13f6..621d0f7 100644 --- a/src/Services/BotListService.cs +++ b/src/Services/BotListService.cs @@ -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) @@ -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) diff --git a/tests/Fergun.Tests/Apis/WolframAlphaTests.cs b/tests/Fergun.Tests/Apis/WolframAlphaTests.cs index 17f1259..72b42c6 100644 --- a/tests/Fergun.Tests/Apis/WolframAlphaTests.cs +++ b/tests/Fergun.Tests/Apis/WolframAlphaTests.cs @@ -184,7 +184,7 @@ public void ArrayOrObjectConverter_Throws_Exceptions() public static TheoryData> ArrayOrObjectConverterData() { - const string json = "{\"text\":\"Error message\"}"; + const string json = """{"text":"Error message"}"""; var suggestions = new[] { new WolframAlphaWarning("Error message") }; return new TheoryData> diff --git a/tests/Fergun.Tests/Apis/YandexImageSearchTests.cs b/tests/Fergun.Tests/Apis/YandexImageSearchTests.cs index c3685ce..d8b78ec 100644 --- a/tests/Fergun.Tests/Apis/YandexImageSearchTests.cs +++ b/tests/Fergun.Tests/Apis/YandexImageSearchTests.cs @@ -57,8 +57,8 @@ public async Task OcrAsync_Throws_YandexException_If_Captcha_Is_Present() .Protected() .As() .SetupSequence(x => x.SendAsync(It.IsAny(), It.IsAny())) - .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)); @@ -92,7 +92,7 @@ public async Task ReverseImageSearchAsync_Throws_YandexException_If_Captcha_Is_P .Protected() .As() .SetupSequence(x => x.SendAsync(It.IsAny(), It.IsAny())) - .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)); @@ -130,7 +130,7 @@ public void YandexException_Has_Expected_Values() } [Theory] - [InlineData("\"{title:"a"}\"", "{title:\"a\"}")] + [InlineData("\"{title:"a"}\"", """{title:"a"}""")] [InlineData("\"D&D\"", "D&D")] public void HtmlEncodingConverter_Returns_Expected_Values(string encodedString, string decodedString) {