Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(test): add interfaces for easier mocking #284

Merged
merged 11 commits into from
Jan 6, 2025
6 changes: 4 additions & 2 deletions .github/workflows/basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
dotnet-version: [ '3.1.x', '7.0.x' ]
dotnet-version: [ '8.0.x' ]
env:
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT: 1

steps:
- name: Checkout
Expand Down Expand Up @@ -48,7 +50,7 @@ jobs:
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: 7.0.x
dotnet-version: 8.0.x

- name: Test
run: dotnet test --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura
Expand Down
11 changes: 6 additions & 5 deletions src/Crowdin.Api/AI/AiApiExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
using System.Net;
using System.Threading.Tasks;

using Crowdin.Api.Core;
using JetBrains.Annotations;

using Crowdin.Api.Core;

namespace Crowdin.Api.AI
{
public class AiApiExecutor
public class AiApiExecutor : IAiApiExecutor
{
private readonly ICrowdinApiClient _apiClient;
private readonly IJsonParser _jsonParser;
Expand Down Expand Up @@ -94,9 +95,7 @@ public async Task<AiFineTuningJob> GetAiPromptFineTuningJobStatus(
CrowdinApiResult result = await _apiClient.SendGetRequest(url);
return _jsonParser.ParseResponseObject<AiFineTuningJob>(result.JsonObject);
}

#endregion


/// <summary>
/// Download AI Prompt Fine-Tuning Dataset. Documentation:
/// <a href="https://support.crowdin.com/developer/api/v2/#tag/AI/operation/api.users.ai.prompts.fine-tuning.datasets.download.get">Crowdin File Based API</a>
Expand All @@ -113,6 +112,8 @@ public async Task<DownloadLink> DownloadAiPromptFineTuningDataset(
CrowdinApiResult result = await _apiClient.SendGetRequest(url);
return _jsonParser.ParseResponseObject<DownloadLink>(result.JsonObject);
}

#endregion

#region Prompts

Expand Down
116 changes: 116 additions & 0 deletions src/Crowdin.Api/AI/IAiApiExecutor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@

using System.Collections.Generic;
using System.Threading.Tasks;

using JetBrains.Annotations;

namespace Crowdin.Api.AI
{
[PublicAPI]
public interface IAiApiExecutor
{
#region Prompt Fine-Tuning Datasets

Task<AiFineTuningDataset> GenerateAiPromptFineTuningDataset(
int? userId,
int aiPromptId,
GenerateAiPromptFineTuningDatasetRequest request);

Task<AiFineTuningDataset> GetAiPromptFineTuningDatasetGenerationStatus(
int? userId,
int aiPromptId,
string jobIdentifier);

Task<AiFineTuningJob> CreateAiPromptFineTuningJob(
int? userId,
int aiPromptId,
CreateAiPromptFineTuningJobRequest request);

Task<AiFineTuningJob> GetAiPromptFineTuningJobStatus(
int? userId,
int aiPromptId,
string jobIdentifier);

Task<DownloadLink> DownloadAiPromptFineTuningDataset(
int? userId,
int aiPromptId,
string jobIdentifier);

#endregion

#region Prompts

Task<AiPromptResource> CloneAiPrompt(int? userId, int aiPromptId, CloneAiPromptRequest request);

Task<ResponseList<AiPromptResource>> ListAiPrompts(
int? userId,
int? projectId = null,
AiPromptAction? action = null,
int limit = 25, int offset = 0);

Task<AiPromptResource> AddAiPrompt(int? userId, AddAiPromptRequest request);

Task<AiPromptCompletion> GenerateAiPromptCompletion(
int? userId,
int aiPromptId,
GenerateAiPromptCompletionRequest request);

Task<AiPromptCompletion> GetAiPromptCompletionStatus(
int? userId,
int aiPromptId,
string completionId);

Task CancelAiPromptCompletion(int? userId, int aiPromptId, string completionId);

Task<DownloadLink> DownloadAiPromptCompletion(int? userId, int aiPromptId, string completionId);

Task<AiPromptResource> GetAiPrompt(int? userId, int aiPromptId);

Task DeleteAiPrompt(int? userId, int aiPromptId);

Task<AiPromptResource> EditAiPrompt(
int? userId, int aiPromptId,
IEnumerable<AiPromptPatch> patches);

#endregion

#region Providers

Task<ResponseList<AiProviderResource>> ListAiProviders(int? userId, int limit = 25, int offset = 0);

Task<AiProviderResource> AddAiProvider(int? userId, AddAiProviderRequest request);

Task<AiProviderResource> GetAiProvider(int? userId, int aiProviderId);

Task DeleteAiProvider(int? userId, int aiProviderId);

Task<AiProviderResource> EditAiProvider(int? userId, int aiProviderId, IEnumerable<AiProviderPatch> patches);

Task<ResponseList<AiProviderModelResource>> ListAiProviderModels(int? userId, int aiProviderId);

#endregion

#region Reports

Task<AiReportGenerationStatus> GenerateAiReport(int? userId, GenerateAiReport request);

Task<AiReportGenerationStatus> CheckAiReportGenerationStatus(int? userId, string aiReportId);

Task<DownloadLink> DownloadAiReport(int? userId, string aiReportId);

#endregion

#region Settings

Task<AiSettings> GetAiSettings(int? userId);

Task<AiSettings> EditAiSettings(int? userId, IEnumerable<AiSettingsPatch> patches);

#endregion

Task<AiProxyChatCompletion> CreateAiProxyChatCompletion(
int? userId,
int aiProviderId,
IDictionary<string, object> request);
}
}
11 changes: 7 additions & 4 deletions src/Crowdin.Api/Applications/ApplicationsApiExecutor.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
using Crowdin.Api.Core;
using JetBrains.Annotations;
using Newtonsoft.Json.Linq;

using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;

using JetBrains.Annotations;
using Newtonsoft.Json.Linq;

using Crowdin.Api.Core;

namespace Crowdin.Api.Applications
{
public class ApplicationsApiExecutor
public class ApplicationsApiExecutor : IApplicationsApiExecutor
{
private readonly ICrowdinApiClient _apiClient;
private readonly IJsonParser _jsonParser;
Expand Down
35 changes: 35 additions & 0 deletions src/Crowdin.Api/Applications/IApplicationsApiExecutor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

using System.Collections.Generic;
using System.Threading.Tasks;

using JetBrains.Annotations;
using Newtonsoft.Json.Linq;

namespace Crowdin.Api.Applications
{
[PublicAPI]
public interface IApplicationsApiExecutor
{
Task<ResponseList<Application>> ListApplicationInstallations(int limit = 25, int offset = 0);

Task<Application> GetApplicationInstallation(string applicationIdentifier);

Task<Application> InstallApplication(InstallApplicationRequest request);

Task DeleteApplicationInstallation(string applicationIdentifier, bool force = false);

Task<Application> EditApplicationInstallation(
string applicationIdentifier,
IEnumerable<InstallationPatch> patches);

Task<JObject> GetApplicationData(string applicationIdentifier, string path);

Task<JObject> UpdateOrRestoreApplicationData(string applicationIdentifier, string path, object request);

Task<JObject> AddApplicationData(string applicationIdentifier, string path, object request);

Task DeleteApplicationData(string applicationIdentifier, string path);

Task<JObject> EditApplicationData(string applicationIdentifier, string path, object patches);
}
}
2 changes: 1 addition & 1 deletion src/Crowdin.Api/Branches/BranchesApiExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Crowdin.Api.Branches
{
public class BranchesApiExecutor
public class BranchesApiExecutor : IBranchesApiExecutor
{
private readonly ICrowdinApiClient _apiClient;
private readonly IJsonParser _jsonParser;
Expand Down
41 changes: 41 additions & 0 deletions src/Crowdin.Api/Branches/IBranchesApiExecutor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

using System.Collections.Generic;
using System.Threading.Tasks;

using JetBrains.Annotations;

#nullable enable

namespace Crowdin.Api.Branches
{
[PublicAPI]
public interface IBranchesApiExecutor
{
Task<Branch> GetClonedBranch(int projectId, int branchId, string cloneId);

Task<BranchCloneStatus> CloneBranch(int projectId, int branchId, CloneBranchRequest request);

Task<BranchCloneStatus> CheckBranchCloneStatus(int projectId, int branchId, string cloneId);

Task<ResponseList<Branch>> ListBranches(
int projectId,
string? name = null,
int limit = 25,
int offset = 0,
IEnumerable<SortingRule>? orderBy = null);

Task<Branch> AddBranch(int projectId, AddBranchRequest request);

Task<Branch> GetBranch(int projectId, int branchId);

Task DeleteBranch(int projectId, int branchId);

Task<Branch> EditBranch(int projectId, int branchId, IEnumerable<BranchPatch> patches);

Task<BranchMergeStatus> MergeBranch(int projectId, int branchId, MergeBranchRequest request);

Task<BranchMergeStatus> CheckBranchMergeStatus(int projectId, int branchId, string mergeId);

Task<BranchMergeSummary> GetBranchMergeSummary(int projectId, int branchId, string mergeId);
}
}
10 changes: 6 additions & 4 deletions src/Crowdin.Api/Bundles/BundlesApiExecutor.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@

using Crowdin.Api.Core;
using Crowdin.Api.SourceFiles;
using JetBrains.Annotations;
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;

using JetBrains.Annotations;

using Crowdin.Api.Core;
using Crowdin.Api.SourceFiles;

namespace Crowdin.Api.Bundles
{
public class BundlesApiExecutor
public class BundlesApiExecutor : IBundlesApiExecutor
{
private readonly ICrowdinApiClient _apiClient;
private readonly IJsonParser _jsonParser;
Expand Down
34 changes: 34 additions & 0 deletions src/Crowdin.Api/Bundles/IBundlesApiExecutor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

using System.Collections.Generic;
using System.Threading.Tasks;

using JetBrains.Annotations;

using Crowdin.Api.SourceFiles;

namespace Crowdin.Api.Bundles
{
[PublicAPI]
public interface IBundlesApiExecutor
{
Task<ResponseList<Bundle>> ListBundles(int projectId, int limit = 25, int offset = 0);

Task<ResponseList<Branch>> ListBundleBranches(int projectId, int bundleId, int limit = 25, int offset = 0);

Task<Bundle> AddBundle(int projectId, AddBundleRequest request);

Task<Bundle> GetBundle(int projectId, int bundleId);

Task DeleteBundle(int projectId, int bundleId);

Task<Bundle> EditBundle(int projectId, int bundleId, IEnumerable<BundlePatch> patches);

Task<DownloadLink> DownloadBundle(int projectId, int bundleId, string exportId);

Task<BundleExport> ExportBundle(int projectId, int bundleId);

Task<BundleExport> CheckBundleExportStatus(int projectId, int bundleId, string exportId);

Task<ResponseList<T>> BundleListFiles<T>(int projectId, int bundleId, int limit = 25, int offset = 0) where T : FileResourceBase;
}
}
9 changes: 6 additions & 3 deletions src/Crowdin.Api/Clients/ClientsApiExecutor.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using Crowdin.Api.Core;
using JetBrains.Annotations;

using System.Collections.Generic;
using System.Threading.Tasks;

using JetBrains.Annotations;

using Crowdin.Api.Core;

namespace Crowdin.Api.Clients
{
internal class ClientsApiExecutor
internal class ClientsApiExecutor : IClientsApiExecutor
{
private readonly ICrowdinApiClient _apiClient;
private readonly IJsonParser _jsonParser;
Expand Down
12 changes: 12 additions & 0 deletions src/Crowdin.Api/Clients/IClientsApiExecutor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

using System.Threading.Tasks;
using JetBrains.Annotations;

namespace Crowdin.Api.Clients
{
[PublicAPI]
public interface IClientsApiExecutor
{
Task<ResponseList<Client>> ListClients(int limit = 25, int offset = 0);
}
}
Loading
Loading