Skip to content

Commit

Permalink
Run csharpier formatter on all cs files.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnml1135 committed Jan 15, 2024
1 parent 4426945 commit b1eb2c1
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 81 deletions.
11 changes: 5 additions & 6 deletions src/SIL.DataAccess/IMongoDataAccessConfiguratorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ public static IMongoDataAccessConfigurator AddRepository<T>(
});
}

configurator.Services.AddScoped<IRepository<T>>(
sp =>
CreateRepository(
sp.GetRequiredService<IMongoDataAccessContext>(),
sp.GetRequiredService<IMongoDatabase>().GetCollection<T>(collectionName)
)
configurator.Services.AddScoped<IRepository<T>>(sp =>
CreateRepository(
sp.GetRequiredService<IMongoDataAccessContext>(),
sp.GetRequiredService<IMongoDatabase>().GetCollection<T>(collectionName)
)
);
return configurator;
}
Expand Down
7 changes: 3 additions & 4 deletions src/SIL.DataAccess/IServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ Action<IMongoDataAccessConfigurator> configure
clientSettings.ClusterConfigurator = cb => cb.Subscribe(new DiagnosticsActivityEventSubscriber());
clientSettings.LinqProvider = LinqProvider.V2;
services.AddSingleton<IMongoClient>(sp => new MongoClient(clientSettings));
services.AddSingleton(
sp =>
sp.GetRequiredService<IMongoClient>()
.GetDatabase(sp.GetRequiredService<IOptions<MongoDataAccessOptions>>().Value.Url.DatabaseName)
services.AddSingleton(sp =>
sp.GetRequiredService<IMongoClient>()
.GetDatabase(sp.GetRequiredService<IOptions<MongoDataAccessOptions>>().Value.Url.DatabaseName)
);
services.TryAddScoped<IMongoDataAccessContext, MongoDataAccessContext>();
services.AddScoped<IDataAccessContext>(sp => sp.GetRequiredService<IMongoDataAccessContext>());
Expand Down
12 changes: 8 additions & 4 deletions src/SIL.DataAccess/MongoRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,18 @@ public async Task<ISubscription<T>> SubscribeAsync(
BsonDocument result;
if (_context.Session is not null)
{
result = await _collection.Database
.RunCommandAsync<BsonDocument>(_context.Session, findCommand, cancellationToken: cancellationToken)
result = await _collection
.Database.RunCommandAsync<BsonDocument>(
_context.Session,
findCommand,
cancellationToken: cancellationToken
)
.ConfigureAwait(false);
}
else
{
result = await _collection.Database
.RunCommandAsync<BsonDocument>(findCommand, cancellationToken: cancellationToken)
result = await _collection
.Database.RunCommandAsync<BsonDocument>(findCommand, cancellationToken: cancellationToken)
.ConfigureAwait(false);
}
BsonDocument? initialEntityDoc = result["cursor"]["firstBatch"].AsBsonArray.FirstOrDefault()?.AsBsonDocument;
Expand Down
2 changes: 1 addition & 1 deletion src/SIL.DataAccess/Usings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
global using MongoDB.Bson.Serialization;
global using MongoDB.Bson.Serialization.Conventions;
global using MongoDB.Bson.Serialization.Serializers;
global using MongoDB.Driver.Core.Extensions.DiagnosticSources;
global using MongoDB.Driver;
global using MongoDB.Driver.Core.Extensions.DiagnosticSources;
global using MongoDB.Driver.Linq;
global using Nito.AsyncEx;
global using SIL.DataAccess;
Expand Down
33 changes: 16 additions & 17 deletions src/Serval.ApiServer/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,23 @@ public void ConfigureServices(IServiceCollection services)
.AddWebhooks();
services.AddTransient<IUrlService, UrlService>();

services.AddHangfire(
c =>
c.SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
.UseSimpleAssemblyNameTypeSerializer()
.UseRecommendedSerializerSettings()
.UseMongoStorage(
Configuration.GetConnectionString("Hangfire"),
new MongoStorageOptions
services.AddHangfire(c =>
c.SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
.UseSimpleAssemblyNameTypeSerializer()
.UseRecommendedSerializerSettings()
.UseMongoStorage(
Configuration.GetConnectionString("Hangfire"),
new MongoStorageOptions
{
MigrationOptions = new MongoMigrationOptions
{
MigrationOptions = new MongoMigrationOptions
{
MigrationStrategy = new MigrateMongoMigrationStrategy(),
BackupStrategy = new CollectionMongoBackupStrategy()
},
CheckConnection = true,
CheckQueuedJobsStrategy = CheckQueuedJobsStrategy.TailNotificationsCollection
}
)
MigrationStrategy = new MigrateMongoMigrationStrategy(),
BackupStrategy = new CollectionMongoBackupStrategy()
},
CheckConnection = true,
CheckQueuedJobsStrategy = CheckQueuedJobsStrategy.TailNotificationsCollection
}
)
);
services.AddHangfireServer();

Expand Down
6 changes: 3 additions & 3 deletions src/Serval.Grpc/Utils/WriteGrpcHealthCheckResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static HealthCheckResponse Generate(HealthReport healthReport)
{
healthCheckResultData.Add(entry.Key, $"{entry.Value.Status}: {entry.Value.Description ?? ""}");
if ((entry.Value.Exception?.ToString() ?? "") != "")
if(healthCheckResultException is null)
if (healthCheckResultException is null)
healthCheckResultException = $"{entry.Key}: {entry.Value.Exception}";
else
healthCheckResultException += $"\n{entry.Key}: {entry.Value.Exception}";
Expand All @@ -27,5 +27,5 @@ public static HealthCheckResponse Generate(HealthReport healthReport)
healthCheckReponse.Data.Add(entry.Key, entry.Value);
}
return healthCheckReponse;
}
}
}
}
4 changes: 2 additions & 2 deletions src/Serval.Shared/Usings.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
global using Grpc.Core;
global using System.Text;
global using System.Text;
global using System.Text.Json;
global using System.Text.Json.Serialization;
global using Grpc.Core;
global using Microsoft.AspNetCore.Authorization;
global using Microsoft.AspNetCore.Http;
global using Microsoft.AspNetCore.Mvc;
Expand Down
4 changes: 2 additions & 2 deletions src/Serval.Translation/Services/EngineService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ public Task DeleteAllCorpusFilesAsync(string dataFileId, CancellationToken cance
{
return Entities.UpdateAllAsync(
e =>
e.Corpora.Any(
c => c.SourceFiles.Any(f => f.Id == dataFileId) || c.TargetFiles.Any(f => f.Id == dataFileId)
e.Corpora.Any(c =>
c.SourceFiles.Any(f => f.Id == dataFileId) || c.TargetFiles.Any(f => f.Id == dataFileId)
),
u =>
u.RemoveAll(e => e.Corpora[ArrayPosition.All].SourceFiles, f => f.Id == dataFileId)
Expand Down
8 changes: 4 additions & 4 deletions src/Serval.Webhooks/Configuration/IServalBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ public static class IServalBuilderExtensions
{
public static IServalBuilder AddWebhooks(this IServalBuilder builder)
{
builder.Services
.AddHttpClient<WebhookJob>()
.AddTransientHttpErrorPolicy(
b => b.WaitAndRetryAsync(3, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)))
builder
.Services.AddHttpClient<WebhookJob>()
.AddTransientHttpErrorPolicy(b =>
b.WaitAndRetryAsync(3, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)))
);
builder.Services.AddScoped<IWebhookService, WebhookService>();
return builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,27 @@ protected override void ConfigureWebHost(IWebHostBuilder builder)
})
.AddScheme<AuthenticationSchemeOptions, TestAuthHandler>("TestScheme", options => { });

services.Configure<MongoDataAccessOptions>(
options => options.Url = new MongoUrl("mongodb://localhost:27017/serval_test")
services.Configure<MongoDataAccessOptions>(options =>
options.Url = new MongoUrl("mongodb://localhost:27017/serval_test")
);

services.AddHangfire(
c =>
c.SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
.UseSimpleAssemblyNameTypeSerializer()
.UseRecommendedSerializerSettings()
.UseMongoStorage(
"mongodb://localhost:27017/serval_test_jobs",
new MongoStorageOptions
services.AddHangfire(c =>
c.SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
.UseSimpleAssemblyNameTypeSerializer()
.UseRecommendedSerializerSettings()
.UseMongoStorage(
"mongodb://localhost:27017/serval_test_jobs",
new MongoStorageOptions
{
MigrationOptions = new MongoMigrationOptions
{
MigrationOptions = new MongoMigrationOptions
{
MigrationStrategy = new MigrateMongoMigrationStrategy(),
BackupStrategy = new CollectionMongoBackupStrategy()
},
CheckConnection = true,
CheckQueuedJobsStrategy = CheckQueuedJobsStrategy.TailNotificationsCollection
}
)
MigrationStrategy = new MigrateMongoMigrationStrategy(),
BackupStrategy = new CollectionMongoBackupStrategy()
},
CheckConnection = true,
CheckQueuedJobsStrategy = CheckQueuedJobsStrategy.TailNotificationsCollection
}
)
);
});
}
Expand Down
22 changes: 14 additions & 8 deletions tests/Serval.ApiServer.IntegrationTests/TranslationEngineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,7 @@ await _env.Builds.InsertAsync(
);
break;
case 409:
_env.EchoClient
.TranslateAsync(Arg.Any<TranslateRequest>(), null, null, Arg.Any<CancellationToken>())
_env.EchoClient.TranslateAsync(Arg.Any<TranslateRequest>(), null, null, Arg.Any<CancellationToken>())
.Returns(CreateAsyncUnaryCall<TranslateResponse>(StatusCode.Aborted));
ex = Assert.ThrowsAsync<ServalApiException>(async () =>
{
Expand Down Expand Up @@ -356,8 +355,7 @@ await _env.Builds.InsertAsync(
);
break;
case 409:
_env.EchoClient
.TranslateAsync(Arg.Any<TranslateRequest>(), null, null, Arg.Any<CancellationToken>())
_env.EchoClient.TranslateAsync(Arg.Any<TranslateRequest>(), null, null, Arg.Any<CancellationToken>())
.Returns(CreateAsyncUnaryCall<TranslateResponse>(StatusCode.Aborted));
ex = Assert.ThrowsAsync<ServalApiException>(async () =>
{
Expand Down Expand Up @@ -407,8 +405,12 @@ await _env.Builds.InsertAsync(
});
break;
case 409:
_env.EchoClient
.GetWordGraphAsync(Arg.Any<GetWordGraphRequest>(), null, null, Arg.Any<CancellationToken>())
_env.EchoClient.GetWordGraphAsync(
Arg.Any<GetWordGraphRequest>(),
null,
null,
Arg.Any<CancellationToken>()
)
.Returns(CreateAsyncUnaryCall<GetWordGraphResponse>(StatusCode.Aborted));
ex = Assert.ThrowsAsync<ServalApiException>(async () =>
{
Expand Down Expand Up @@ -459,8 +461,12 @@ await _env.Builds.InsertAsync(
await client.TrainSegmentAsync(engineId, sp);
break;
case 409:
_env.EchoClient
.TrainSegmentPairAsync(Arg.Any<TrainSegmentPairRequest>(), null, null, Arg.Any<CancellationToken>())
_env.EchoClient.TrainSegmentPairAsync(
Arg.Any<TrainSegmentPairRequest>(),
null,
null,
Arg.Any<CancellationToken>()
)
.Returns(CreateAsyncUnaryCall<Empty>(StatusCode.Aborted));
ex = Assert.ThrowsAsync<ServalApiException>(async () =>
{
Expand Down
1 change: 0 additions & 1 deletion tests/Serval.ApiServer.IntegrationTests/Usings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
global using NUnit.Framework;
global using Serval.Client;
global using Serval.Shared.Controllers;
global using Serval.Shared.Contracts;
global using Serval.Translation.Models;
global using SIL.DataAccess;
global using SIL.ObjectModel;
4 changes: 2 additions & 2 deletions tests/Serval.E2ETests/ServalApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ await _helperClient.AddTextCorpusToEngine(
WordGraph result = await _helperClient.translationEnginesClient.GetWordGraphAsync(smtEngineId, "verdad");
Assert.That(result.SourceTokens, Has.Count.EqualTo(1));
Assert.That(
result.Arcs
.Where(arc => arc != null && arc.Confidences != null)!
result
.Arcs.Where(arc => arc != null && arc.Confidences != null)!
.MaxBy(arc => arc.Confidences.Average())!
.TargetTokens.All(tk => tk == "truth"),
"Best translation should have been 'truth'but returned word graph: \n{0}",
Expand Down
4 changes: 2 additions & 2 deletions tests/Serval.E2ETests/Usings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
global using System.Text.Json;
global using System.IO.Compression;
global using System.Text.Json;
global using NUnit.Framework;
global using Serval.Client;
global using System.IO.Compression;
9 changes: 3 additions & 6 deletions tests/Serval.Webhooks.Tests/Services/WebhookJobTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public async Task RunAsync_MatchingHook()
Events = new List<WebhookEvent> { WebhookEvent.TranslationBuildStarted }
}
);
env.MockHttp
.Expect("https://test.client.com/hook")
env.MockHttp.Expect("https://test.client.com/hook")
.WithHeaders(
"X-Hub-Signature-256",
"sha256=8EC2360A34811845884D8FCE03866EA8FAD9429AAA9E6247D7A817AD2E170B8F"
Expand Down Expand Up @@ -81,8 +80,7 @@ public void RunAsync_RequestTimeout()
Events = new List<WebhookEvent> { WebhookEvent.TranslationBuildStarted }
}
);
env.MockHttp
.Expect("https://test.client.com/hook")
env.MockHttp.Expect("https://test.client.com/hook")
.WithHeaders(
"X-Hub-Signature-256",
"sha256=8EC2360A34811845884D8FCE03866EA8FAD9429AAA9E6247D7A817AD2E170B8F"
Expand Down Expand Up @@ -111,8 +109,7 @@ public void RunAsync_Exception()
Events = new List<WebhookEvent> { WebhookEvent.TranslationBuildStarted }
}
);
env.MockHttp
.Expect("https://test.client.com/hook")
env.MockHttp.Expect("https://test.client.com/hook")
.WithHeaders(
"X-Hub-Signature-256",
"sha256=8EC2360A34811845884D8FCE03866EA8FAD9429AAA9E6247D7A817AD2E170B8F"
Expand Down

0 comments on commit b1eb2c1

Please sign in to comment.