Skip to content

Commit 94ad7be

Browse files
committed
chore: Format library code
1 parent 6ca6350 commit 94ad7be

File tree

7 files changed

+68
-59
lines changed

7 files changed

+68
-59
lines changed

DeepL/Internal/DeepLHttpClient.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ public static HttpClientAndDisposeFlag CreateDefaultHttpClient(
126126
perRetryConnectionTimeout,
127127
maximumNetworkRetries);
128128
return new HttpClientAndDisposeFlag {
129-
DisposeClient = true, HttpClient = new HttpClient(handler) { Timeout = overallConnectionTimeout }
129+
DisposeClient = true,
130+
HttpClient = new HttpClient(handler) { Timeout = overallConnectionTimeout }
130131
};
131132
}
132133

@@ -203,9 +204,9 @@ public async Task<HttpResponseMessage> ApiGetAsync(
203204
queryParams.Select(pair => $"{Uri.EscapeDataString(pair.Key)}={Uri.EscapeDataString(pair.Value)}"));
204205

205206
using var requestMessage = new HttpRequestMessage {
206-
RequestUri = new Uri(_serverUrl, relativeUri + queryString),
207-
Method = HttpMethod.Get,
208-
Headers = { Accept = { new MediaTypeWithQualityHeaderValue(acceptHeader ?? "application/json") } }
207+
RequestUri = new Uri(_serverUrl, relativeUri + queryString),
208+
Method = HttpMethod.Get,
209+
Headers = { Accept = { new MediaTypeWithQualityHeaderValue(acceptHeader ?? "application/json") } }
209210
};
210211
return await ApiCallAsync(requestMessage, cancellationToken);
211212
}
@@ -217,7 +218,8 @@ public async Task<HttpResponseMessage> ApiGetAsync(
217218
/// <exception cref="ConnectionException">If any failure occurs while sending the request.</exception>
218219
public async Task<HttpResponseMessage> ApiDeleteAsync(string relativeUri, CancellationToken cancellationToken) {
219220
using var requestMessage = new HttpRequestMessage {
220-
RequestUri = new Uri(_serverUrl, relativeUri), Method = HttpMethod.Delete
221+
RequestUri = new Uri(_serverUrl, relativeUri),
222+
Method = HttpMethod.Delete
221223
};
222224
return await ApiCallAsync(requestMessage, cancellationToken);
223225
}
@@ -233,9 +235,9 @@ public async Task<HttpResponseMessage> ApiPostAsync(
233235
CancellationToken cancellationToken,
234236
IEnumerable<(string Key, string Value)>? bodyParams = null) {
235237
using var requestMessage = new HttpRequestMessage {
236-
RequestUri = new Uri(_serverUrl, relativeUri),
237-
Method = HttpMethod.Post,
238-
Content = bodyParams != null
238+
RequestUri = new Uri(_serverUrl, relativeUri),
239+
Method = HttpMethod.Post,
240+
Content = bodyParams != null
239241
? new LargeFormUrlEncodedContent(
240242
bodyParams.Select(pair => new KeyValuePair<string, string>(pair.Key, pair.Value)))
241243
: null
@@ -265,10 +267,10 @@ public async Task<HttpResponseMessage> ApiUploadAsync(
265267
content.Add(new StreamContent(file), "file", fileName);
266268

267269
using var requestMessage = new HttpRequestMessage {
268-
RequestUri = new Uri(_serverUrl, relativeUri),
269-
Method = HttpMethod.Post,
270-
Content = content,
271-
Headers = { Accept = { new MediaTypeWithQualityHeaderValue("application/json") } }
270+
RequestUri = new Uri(_serverUrl, relativeUri),
271+
Method = HttpMethod.Post,
272+
Content = content,
273+
Headers = { Accept = { new MediaTypeWithQualityHeaderValue("application/json") } }
272274
};
273275
return await ApiCallAsync(requestMessage, cancellationToken);
274276
}

DeepL/ModelType.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ public static class ModelTypeExtensions {
3535
/// <exception cref="ArgumentOutOfRangeException">If an unknown enum value is passed.</exception>
3636
public static string ToApiValue(this ModelType modelType) {
3737
return modelType switch {
38-
ModelType.PreferQualityOptimized => "prefer_quality_optimized",
39-
ModelType.LatencyOptimized => "latency_optimized",
40-
ModelType.QualityOptimized => "quality_optimized",
41-
_ => throw new ArgumentOutOfRangeException(nameof(modelType), modelType, "Unrecognized model type value")
38+
ModelType.PreferQualityOptimized => "prefer_quality_optimized",
39+
ModelType.LatencyOptimized => "latency_optimized",
40+
ModelType.QualityOptimized => "quality_optimized",
41+
_ => throw new ArgumentOutOfRangeException(nameof(modelType), modelType, "Unrecognized model type value")
4242
};
4343
}
4444
}

DeepL/Translator.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 DeepL SE (https://www.deepl.com)
1+
// Copyright 2022 DeepL SE (https://www.deepl.com)
22
// Use of this source code is governed by an MIT
33
// license that can be found in the LICENSE file.
44

@@ -572,7 +572,8 @@ await TranslateDocumentAsync(
572572
}
573573

574574
throw;
575-
} if (willMinify) {
575+
}
576+
if (willMinify) {
576577
outputFile.Dispose();
577578
// Translated minified file is at `outputFileName`. Reinsert media (deminify) before returning
578579
minifier.DeminifyDocument(outputFileInfo.FullName, outputFileInfo.FullName, true);
@@ -872,8 +873,8 @@ await _client.ApiGetAsync("/v2/languages", cancellationToken, queryParams)
872873
private String ConstructUserAgentString(bool sendPlatformInfo = true, AppInfo? appInfo = null) {
873874
var platformInfoString = $"deepl-dotnet/{Version()}";
874875
if (sendPlatformInfo) {
875-
var osDescription = System.Runtime.InteropServices.RuntimeInformation.OSDescription;
876-
var clrVersion = Environment.Version.ToString();
876+
var osDescription = System.Runtime.InteropServices.RuntimeInformation.OSDescription;
877+
var clrVersion = Environment.Version.ToString();
877878
platformInfoString += $" ({osDescription}) dotnet-clr/{clrVersion}";
878879
}
879880
if (appInfo != null) {

DeepLTests/GeneralTest.cs

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ public async Task TestDefaultUserAgentHeader() {
4646
var translator = new Translator(
4747
AuthKey,
4848
new TranslatorOptions {
49-
ClientFactory = () =>
50-
new HttpClientAndDisposeFlag { HttpClient = new HttpClient(mockHandler), DisposeClient = true, }
49+
ClientFactory = () =>
50+
new HttpClientAndDisposeFlag { HttpClient = new HttpClient(mockHandler), DisposeClient = true, }
5151
});
5252
var usage = await translator.GetUsageAsync();
5353
Assert.Single(mockHandler.requests);
@@ -63,9 +63,9 @@ public async Task TestOptInUserAgentHeader() {
6363
var translator = new Translator(
6464
AuthKey,
6565
new TranslatorOptions {
66-
sendPlatformInfo = true,
67-
ClientFactory = () =>
68-
new HttpClientAndDisposeFlag { HttpClient = new HttpClient(mockHandler), DisposeClient = true, }
66+
sendPlatformInfo = true,
67+
ClientFactory = () =>
68+
new HttpClientAndDisposeFlag { HttpClient = new HttpClient(mockHandler), DisposeClient = true, }
6969
});
7070
var usage = await translator.GetUsageAsync();
7171
Assert.Single(mockHandler.requests);
@@ -81,9 +81,9 @@ public async Task TestOptOutUserAgentHeader() {
8181
var translator = new Translator(
8282
AuthKey,
8383
new TranslatorOptions {
84-
sendPlatformInfo = false,
85-
ClientFactory = () =>
86-
new HttpClientAndDisposeFlag { HttpClient = new HttpClient(mockHandler), DisposeClient = true, }
84+
sendPlatformInfo = false,
85+
ClientFactory = () =>
86+
new HttpClientAndDisposeFlag { HttpClient = new HttpClient(mockHandler), DisposeClient = true, }
8787
});
8888
var usage = await translator.GetUsageAsync();
8989
Assert.Single(mockHandler.requests);
@@ -99,10 +99,10 @@ public async Task TestDefaultUserAgentHeaderWithAppInfo() {
9999
var translator = new Translator(
100100
AuthKey,
101101
new TranslatorOptions {
102-
sendPlatformInfo = true,
103-
appInfo = new AppInfo { AppName = "my-dotnet-test-app", AppVersion = "1.2.3" },
104-
ClientFactory = () =>
105-
new HttpClientAndDisposeFlag { HttpClient = new HttpClient(mockHandler), DisposeClient = true, }
102+
sendPlatformInfo = true,
103+
appInfo = new AppInfo { AppName = "my-dotnet-test-app", AppVersion = "1.2.3" },
104+
ClientFactory = () =>
105+
new HttpClientAndDisposeFlag { HttpClient = new HttpClient(mockHandler), DisposeClient = true, }
106106
});
107107
var usage = await translator.GetUsageAsync();
108108
Assert.Single(mockHandler.requests);
@@ -119,10 +119,10 @@ public async Task TestOptInUserAgentHeaderWithAppInfo() {
119119
var translator = new Translator(
120120
AuthKey,
121121
new TranslatorOptions {
122-
sendPlatformInfo = true,
123-
appInfo = new AppInfo { AppName = "my-dotnet-test-app", AppVersion = "1.2.3" },
124-
ClientFactory = () =>
125-
new HttpClientAndDisposeFlag { HttpClient = new HttpClient(mockHandler), DisposeClient = true, }
122+
sendPlatformInfo = true,
123+
appInfo = new AppInfo { AppName = "my-dotnet-test-app", AppVersion = "1.2.3" },
124+
ClientFactory = () =>
125+
new HttpClientAndDisposeFlag { HttpClient = new HttpClient(mockHandler), DisposeClient = true, }
126126
});
127127
var usage = await translator.GetUsageAsync();
128128
Assert.Single(mockHandler.requests);
@@ -139,10 +139,10 @@ public async Task TestOptOutUserAgentHeaderWithAppInfo() {
139139
var translator = new Translator(
140140
AuthKey,
141141
new TranslatorOptions {
142-
sendPlatformInfo = false,
143-
appInfo = new AppInfo { AppName = "my-dotnet-test-app", AppVersion = "1.2.3" },
144-
ClientFactory = () =>
145-
new HttpClientAndDisposeFlag { HttpClient = new HttpClient(mockHandler), DisposeClient = true, }
142+
sendPlatformInfo = false,
143+
appInfo = new AppInfo { AppName = "my-dotnet-test-app", AppVersion = "1.2.3" },
144+
ClientFactory = () =>
145+
new HttpClientAndDisposeFlag { HttpClient = new HttpClient(mockHandler), DisposeClient = true, }
146146
});
147147
var usage = await translator.GetUsageAsync();
148148
Assert.Single(mockHandler.requests);
@@ -248,13 +248,14 @@ public async Task TestProxyUsage() {
248248
nameof(TestUsageNoResponse),
249249
new SessionOptions { ExpectProxy = true },
250250
new TranslatorOptions {
251-
ServerUrl = ServerUrl,
252-
ClientFactory =
251+
ServerUrl = ServerUrl,
252+
ClientFactory =
253253
() => {
254254
var handler = new HttpClientHandler() { Proxy = new WebProxy(ProxyUrl), UseProxy = true, };
255255

256256
return new HttpClientAndDisposeFlag {
257-
HttpClient = new HttpClient(handler), DisposeClient = true,
257+
HttpClient = new HttpClient(handler),
258+
DisposeClient = true,
258259
};
259260
}
260261
});
@@ -269,7 +270,8 @@ public async Task TestUsageNoResponse() {
269270
nameof(TestUsageNoResponse),
270271
new SessionOptions { NoResponse = 2 },
271272
new TranslatorOptions {
272-
PerRetryConnectionTimeout = TimeSpan.FromMilliseconds(1), MaximumNetworkRetries = 0
273+
PerRetryConnectionTimeout = TimeSpan.FromMilliseconds(1),
274+
MaximumNetworkRetries = 0
273275
});
274276

275277
await Assert.ThrowsAsync<ConnectionException>(() => translator.GetUsageAsync());
@@ -343,7 +345,9 @@ public async Task TestUsageTeamDocumentLimit() {
343345
var translator = CreateTestTranslatorWithMockSession(
344346
nameof(TestUsageOverrun),
345347
new SessionOptions {
346-
InitCharacterLimit = 0, InitDocumentLimit = 0, InitTeamDocumentLimit = teamDocumentLimit
348+
InitCharacterLimit = 0,
349+
InitDocumentLimit = 0,
350+
InitTeamDocumentLimit = teamDocumentLimit
347351
},
348352
randomAuthKey: true);
349353

DeepLTests/RephraseTextTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ public async Task TestBusinessStyle() {
4141
private void checkSanityOfImprovements(
4242
string inputText,
4343
WriteResult result,
44-
string expectedSourceLangUppercase="EN",
45-
string expectedTargetLangUppercase="EN-US",
46-
float epsilon=0.2f) {
44+
string expectedSourceLangUppercase = "EN",
45+
string expectedTargetLangUppercase = "EN-US",
46+
float epsilon = 0.2f) {
4747
Assert.Equal(expectedSourceLangUppercase, result.DetectedSourceLanguageCode.ToUpper());
4848
Assert.Equal(expectedTargetLangUppercase, result.TargetLanguageCode.ToUpper());
49-
var ratio = ((float) result.Text.Length) / inputText.Length;
49+
var ratio = ((float)result.Text.Length) / inputText.Length;
5050
Assert.True(1 / (1.0 + epsilon) <= ratio, $"Rephrased text is too short compared to input text.\n{inputText}\n{result.Text}");
5151
Assert.True(ratio <= (1.0 + epsilon), $"Rephrased text is too long compared to input text.\n{inputText}\n{result.Text}");
5252
}

DeepLTests/TranslateDocumentTest.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ public async Task TestTranslateDocumentWithRetry() {
6363
nameof(TestTranslateDocumentWithRetry),
6464
new SessionOptions { NoResponse = 1 },
6565
new TranslatorOptions {
66-
PerRetryConnectionTimeout = TimeSpan.FromSeconds(1),
67-
OverallConnectionTimeout = TimeSpan.FromSeconds(10)
66+
PerRetryConnectionTimeout = TimeSpan.FromSeconds(1),
67+
OverallConnectionTimeout = TimeSpan.FromSeconds(10)
6868
});
6969
var outputDocumentPath = OutputDocumentPath();
7070

@@ -81,7 +81,8 @@ public async Task TestTranslateDocumentWithWaiting() {
8181
var translator = CreateTestTranslatorWithMockSession(
8282
nameof(TestTranslateDocumentWithWaiting),
8383
new SessionOptions {
84-
DocumentQueueTime = TimeSpan.FromSeconds(2), DocumentTranslateTime = TimeSpan.FromSeconds(2)
84+
DocumentQueueTime = TimeSpan.FromSeconds(2),
85+
DocumentTranslateTime = TimeSpan.FromSeconds(2)
8586
});
8687
var outputDocumentPath = OutputDocumentPath();
8788
await translator.TranslateDocumentAsync(
@@ -248,7 +249,8 @@ public async Task TestTranslateDocumentRequestFields() {
248249
var translator = CreateTestTranslatorWithMockSession(
249250
nameof(TestTranslateDocumentRequestFields),
250251
new SessionOptions {
251-
DocumentQueueTime = TimeSpan.FromSeconds(2), DocumentTranslateTime = TimeSpan.FromSeconds(2)
252+
DocumentQueueTime = TimeSpan.FromSeconds(2),
253+
DocumentTranslateTime = TimeSpan.FromSeconds(2)
252254
});
253255
var exampleDocumentPath = ExampleDocumentPath();
254256

DeepLTests/TranslateTextTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public async Task TestTranslateWithModelType(ModelType modelType, string expecte
3232
ExampleText("en"),
3333
null,
3434
LanguageCode.German,
35-
new TextTranslateOptions{ModelType = modelType});
35+
new TextTranslateOptions { ModelType = modelType });
3636
Assert.Equal(expectedModelTypeUsed, result.ModelTypeUsed);
3737
}
3838

@@ -259,11 +259,11 @@ public async Task TestTagHandlingXml() {
259259
null,
260260
"DE",
261261
new TextTranslateOptions {
262-
TagHandling = "xml",
263-
OutlineDetection = false,
264-
NonSplittingTags = { "span" },
265-
SplittingTags = { "title", "par" },
266-
IgnoreTags = { "raw" }
262+
TagHandling = "xml",
263+
OutlineDetection = false,
264+
NonSplittingTags = { "span" },
265+
SplittingTags = { "title", "par" },
266+
IgnoreTags = { "raw" }
267267
});
268268
Assert.Contains("<raw>This sentence will not be translated.</raw>", result.Text);
269269
Assert.Matches("<title>.*Der Titel.*</title>", result.Text);

0 commit comments

Comments
 (0)