From 61df69caf5e80a88d45d5dac2b1c42be3846c7d8 Mon Sep 17 00:00:00 2001 From: Lezune Date: Tue, 11 Jun 2024 19:33:54 -0700 Subject: [PATCH 1/6] Merged relevant files from main to new branch which consists of files both associated and related to the Models/Services/Foundations/AIFiles directory --- ...FileServiceTests.Validations.RemoveById.cs | 2 +- .../AIFileServiceTests.Validations.Upload.cs | 8 +- .../Foundations/AIFiles/AIFileServiceTests.cs | 7 + .../AIFileOrchestrationServiceTests.cs | 38 ++++- .../Exceptions/AIFileDependencyException.cs | 6 - .../AIFileDependencyValidationException.cs | 6 - .../Exceptions/AIFileServiceException.cs | 6 - .../Exceptions/AIFileValidationException.cs | 6 - .../ExcessiveCallAIFileException.cs | 6 - .../FailedAIFileServiceException.cs | 6 - .../Exceptions/FailedServerAIFileException.cs | 6 - .../Exceptions/InvalidAIFileException.cs | 11 +- .../InvalidConfigurationAIFileException.cs | 6 - .../Exceptions/NotFoundAIFileException.cs | 6 - .../AIFiles/Exceptions/NullAiFileException.cs | 5 +- .../Exceptions/UnauthorizedAIFileException.cs | 6 - .../AIFiles/AIFileService.Exceptions.cs | 134 ++++++++++++++---- .../AIFiles/AIFileService.Validations.cs | 6 +- .../Foundations/AIFiles/AIFileService.cs | 4 + 19 files changed, 161 insertions(+), 114 deletions(-) diff --git a/Standard.AI.OpenAI.Tests.Unit/Services/Foundations/AIFiles/AIFileServiceTests.Validations.RemoveById.cs b/Standard.AI.OpenAI.Tests.Unit/Services/Foundations/AIFiles/AIFileServiceTests.Validations.RemoveById.cs index 5cae1f20..16465aca 100644 --- a/Standard.AI.OpenAI.Tests.Unit/Services/Foundations/AIFiles/AIFileServiceTests.Validations.RemoveById.cs +++ b/Standard.AI.OpenAI.Tests.Unit/Services/Foundations/AIFiles/AIFileServiceTests.Validations.RemoveById.cs @@ -24,7 +24,7 @@ private async Task ShouldThrowValidationExceptionOnRemoveByIdIfIdIsInvalidAsync( string invalidFileId = invalidId; var invalidFileException = - new InvalidAIFileException(); + createInvalidAIFileException(); invalidFileException.AddData( key: nameof(AIFile.Response.Id), diff --git a/Standard.AI.OpenAI.Tests.Unit/Services/Foundations/AIFiles/AIFileServiceTests.Validations.Upload.cs b/Standard.AI.OpenAI.Tests.Unit/Services/Foundations/AIFiles/AIFileServiceTests.Validations.Upload.cs index d3d570f8..559cea9e 100644 --- a/Standard.AI.OpenAI.Tests.Unit/Services/Foundations/AIFiles/AIFileServiceTests.Validations.Upload.cs +++ b/Standard.AI.OpenAI.Tests.Unit/Services/Foundations/AIFiles/AIFileServiceTests.Validations.Upload.cs @@ -19,7 +19,9 @@ private async Task ShouldThrowValidationExceptionOnUploadIfAIFileIsNull() { // given AIFile nullAIFile = null; - var nullAIFileException = new NullAIFileException(); + var nullAIFileException = + new NullAIFileException( + message: "Ai file is null."); var expectedAIFileValidationException = new AIFileValidationException( @@ -52,7 +54,7 @@ private async Task ShouldThrowValidationExceptionOnUploadIfAIFileRequestIsNull() invalidAIFile.Request = null; var invalidAIFileException = - new InvalidAIFileException(); + createInvalidAIFileException(); invalidAIFileException.AddData( key: nameof(AIFile.Request), @@ -99,7 +101,7 @@ private async Task ShouldThrowValidationExceptionOnUploadIfAIFileRequestIsInvali }; var invalidAIFileException = - new InvalidAIFileException(); + createInvalidAIFileException(); invalidAIFileException.AddData( key: nameof(AIFileRequest.Name), diff --git a/Standard.AI.OpenAI.Tests.Unit/Services/Foundations/AIFiles/AIFileServiceTests.cs b/Standard.AI.OpenAI.Tests.Unit/Services/Foundations/AIFiles/AIFileServiceTests.cs index be2f3472..821e2058 100644 --- a/Standard.AI.OpenAI.Tests.Unit/Services/Foundations/AIFiles/AIFileServiceTests.cs +++ b/Standard.AI.OpenAI.Tests.Unit/Services/Foundations/AIFiles/AIFileServiceTests.cs @@ -14,6 +14,7 @@ using Standard.AI.OpenAI.Brokers.DateTimes; using Standard.AI.OpenAI.Brokers.OpenAIs; using Standard.AI.OpenAI.Models.Services.Foundations.AIFiles; +using Standard.AI.OpenAI.Models.Services.Foundations.AIFiles.Exceptions; using Standard.AI.OpenAI.Models.Services.Foundations.ExternalAIFiles; using Standard.AI.OpenAI.Services.Foundations.AIFiles; using Tynamix.ObjectFiller; @@ -155,5 +156,11 @@ private Filler CreateAIFileFiller() return filler; } + + private static InvalidAIFileException createInvalidAIFileException() + { + return new InvalidAIFileException( + message: "Invalid AI file error occurred, fix errors and try again."); + } } } diff --git a/Standard.AI.OpenAI.Tests.Unit/Services/Orchestrations/AIFiles/AIFileOrchestrationServiceTests.cs b/Standard.AI.OpenAI.Tests.Unit/Services/Orchestrations/AIFiles/AIFileOrchestrationServiceTests.cs index cebfc9b8..ca1609c2 100644 --- a/Standard.AI.OpenAI.Tests.Unit/Services/Orchestrations/AIFiles/AIFileOrchestrationServiceTests.cs +++ b/Standard.AI.OpenAI.Tests.Unit/Services/Orchestrations/AIFiles/AIFileOrchestrationServiceTests.cs @@ -7,6 +7,7 @@ using System.IO; using System.Linq.Expressions; using KellermanSoftware.CompareNetObjects; +using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; using Moq; using Standard.AI.OpenAI.Models.Services.Foundations.AIFiles; using Standard.AI.OpenAI.Models.Services.Foundations.AIFiles.Exceptions; @@ -46,8 +47,13 @@ public static TheoryData DependencyValidationExceptions() { new LocalFileValidationException(someInnerException), new LocalFileDependencyValidationException(someInnerException), - new AIFileValidationException(someInnerException), - new AIFileDependencyValidationException(someInnerException) + + new AIFileValidationException( + message: "AI file validation error occurred, fix errors and try again.", + someInnerException), + + createAIFileDependencyValidationException( + someInnerException) }; } @@ -59,8 +65,8 @@ public static TheoryData DependencyExceptions() { new LocalFileDependencyException(someInnerException), new LocalFileServiceException(someInnerException), - new AIFileDependencyException(someInnerException), - new AIFileServiceException(someInnerException), + createAIFileDependencyException(someInnerException), + createAIFileServiceException(someInnerException), }; } @@ -70,8 +76,8 @@ public static TheoryData AIFileServiceDependencyExceptions() return new TheoryData { - new AIFileDependencyException(someInnerException), - new AIFileServiceException(someInnerException), + createAIFileDependencyException(someInnerException), + createAIFileServiceException(someInnerException), }; } @@ -141,5 +147,25 @@ private static string CreateRandomFileId() return randomId; } + + private static AIFileDependencyException createAIFileDependencyException(Xeption innerException) + { + return new AIFileDependencyException( + message: "AI file dependency error occurred, contact support.", + innerException); + } + private static AIFileServiceException createAIFileServiceException(Xeption innerException) + { + return new AIFileServiceException( + message: "AI file service error occurred, contact support.", + innerException); + } + + private static AIFileDependencyValidationException createAIFileDependencyValidationException(Xeption innerException) + { + return new AIFileDependencyValidationException( + message: "AI file dependency validation error occurred, contact support.", + innerException); + } } } \ No newline at end of file diff --git a/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/AIFileDependencyException.cs b/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/AIFileDependencyException.cs index 88224d68..bf69218b 100644 --- a/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/AIFileDependencyException.cs +++ b/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/AIFileDependencyException.cs @@ -8,12 +8,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AIFiles.Exceptions { public class AIFileDependencyException : Xeption { - public AIFileDependencyException(Xeption innerException) - : base( - message: "AI file dependency error occurred, contact support.", - innerException: innerException) - { } - public AIFileDependencyException(string message, Xeption innerException) : base(message, innerException) { } diff --git a/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/AIFileDependencyValidationException.cs b/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/AIFileDependencyValidationException.cs index 52d11d2d..3912cf18 100644 --- a/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/AIFileDependencyValidationException.cs +++ b/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/AIFileDependencyValidationException.cs @@ -8,12 +8,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AIFiles.Exceptions { public class AIFileDependencyValidationException : Xeption { - public AIFileDependencyValidationException(Xeption innerException) - : base( - message: "AI file dependency validation error occurred, contact support.", - innerException: innerException) - { } - public AIFileDependencyValidationException(string message, Xeption innerException) : base(message, innerException) { } diff --git a/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/AIFileServiceException.cs b/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/AIFileServiceException.cs index be7f0690..4a25d951 100644 --- a/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/AIFileServiceException.cs +++ b/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/AIFileServiceException.cs @@ -8,12 +8,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AIFiles.Exceptions { public class AIFileServiceException : Xeption { - public AIFileServiceException(Xeption innerException) - : base( - message: "AI file service error occurred, contact support.", - innerException: innerException) - { } - public AIFileServiceException(string message, Xeption innerException) : base(message, innerException) { } diff --git a/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/AIFileValidationException.cs b/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/AIFileValidationException.cs index ebcd202d..4d2ae442 100644 --- a/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/AIFileValidationException.cs +++ b/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/AIFileValidationException.cs @@ -8,12 +8,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AIFiles.Exceptions { public class AIFileValidationException : Xeption { - public AIFileValidationException(Xeption innerException) - : base( - message: "AI file validation error occurred, fix errors and try again.", - innerException: innerException) - { } - public AIFileValidationException(string message, Xeption innerException) : base(message, innerException) { } } diff --git a/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/ExcessiveCallAIFileException.cs b/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/ExcessiveCallAIFileException.cs index 2e39ed38..2d72ce68 100644 --- a/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/ExcessiveCallAIFileException.cs +++ b/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/ExcessiveCallAIFileException.cs @@ -9,12 +9,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AIFiles.Exceptions { public class ExcessiveCallAIFileException : Xeption { - public ExcessiveCallAIFileException(Exception innerException) - : base( - message: "Excessive call error occurred, limit your calls.", - innerException: innerException) - { } - public ExcessiveCallAIFileException(string message, Exception innerException) : base(message, innerException) { } diff --git a/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/FailedAIFileServiceException.cs b/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/FailedAIFileServiceException.cs index 36757418..9f428778 100644 --- a/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/FailedAIFileServiceException.cs +++ b/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/FailedAIFileServiceException.cs @@ -9,12 +9,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AIFiles.Exceptions { public class FailedAIFileServiceException : Xeption { - public FailedAIFileServiceException(Exception innerException) - : base( - message: "Failed AI file service error occurred, contact support.", - innerException: innerException) - { } - public FailedAIFileServiceException(string message, Exception innerException) : base(message, innerException) { } diff --git a/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/FailedServerAIFileException.cs b/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/FailedServerAIFileException.cs index ab52c002..319722b5 100644 --- a/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/FailedServerAIFileException.cs +++ b/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/FailedServerAIFileException.cs @@ -9,12 +9,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AIFiles.Exceptions { public class FailedServerAIFileException : Xeption { - public FailedServerAIFileException(Exception innerException) - : base( - message: "Failed AI file server error occurred, contact support.", - innerException: innerException) - { } - public FailedServerAIFileException(string message, Exception innerException) : base(message, innerException) { } diff --git a/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/InvalidAIFileException.cs b/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/InvalidAIFileException.cs index 70edd201..f6a2fbf9 100644 --- a/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/InvalidAIFileException.cs +++ b/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/InvalidAIFileException.cs @@ -9,15 +9,8 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AIFiles.Exceptions { public class InvalidAIFileException : Xeption { - public InvalidAIFileException() - : base( - message: "Invalid AI file error occurred, fix errors and try again.") - { } - - public InvalidAIFileException(Exception innerException) - : base( - message: "Invalid AI file error occurred, fix errors and try again.", - innerException: innerException) + public InvalidAIFileException(string message) + : base(message) { } public InvalidAIFileException(string message, Exception innerException) diff --git a/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/InvalidConfigurationAIFileException.cs b/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/InvalidConfigurationAIFileException.cs index 3d7d5251..90a25251 100644 --- a/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/InvalidConfigurationAIFileException.cs +++ b/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/InvalidConfigurationAIFileException.cs @@ -9,12 +9,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AIFiles.Exceptions { public class InvalidConfigurationAIFileException : Xeption { - public InvalidConfigurationAIFileException(Exception innerException) - : base( - message: "Invalid AI file configuration error occurred, contact support.", - innerException: innerException) - { } - public InvalidConfigurationAIFileException(string message, Exception innerException) : base(message, innerException) { } diff --git a/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/NotFoundAIFileException.cs b/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/NotFoundAIFileException.cs index ce6f7943..4084b28f 100644 --- a/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/NotFoundAIFileException.cs +++ b/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/NotFoundAIFileException.cs @@ -9,12 +9,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AIFiles.Exceptions { public class NotFoundAIFileException : Xeption { - public NotFoundAIFileException(Exception innerException) - : base( - message: "Not found AI file error occurred, fix errors and try again.", - innerException: innerException) - { } - public NotFoundAIFileException(string message, Exception innerException) : base(message: message, innerException) { } diff --git a/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/NullAiFileException.cs b/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/NullAiFileException.cs index e6010317..f5c8cb01 100644 --- a/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/NullAiFileException.cs +++ b/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/NullAiFileException.cs @@ -9,9 +9,8 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AIFiles.Exceptions { public partial class NullAIFileException : Xeption { - public NullAIFileException() - : base( - message: "Ai file is null.") + public NullAIFileException(String message) + : base(message) { } public NullAIFileException(string message, Exception innerException) diff --git a/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/UnauthorizedAIFileException.cs b/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/UnauthorizedAIFileException.cs index 5757d69e..78d6c96c 100644 --- a/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/UnauthorizedAIFileException.cs +++ b/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/UnauthorizedAIFileException.cs @@ -9,12 +9,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AIFiles.Exceptions { public class UnauthorizedAIFileException : Xeption { - public UnauthorizedAIFileException(Exception innerException) - : base( - message: "Unauthorized AI file request, fix errors and try again.", - innerException: innerException) - { } - public UnauthorizedAIFileException(string message, Exception innerException) : base(message, innerException) { } } diff --git a/Standard.AI.OpenAI/Services/Foundations/AIFiles/AIFileService.Exceptions.cs b/Standard.AI.OpenAI/Services/Foundations/AIFiles/AIFileService.Exceptions.cs index 3c901b0c..b1c59a72 100644 --- a/Standard.AI.OpenAI/Services/Foundations/AIFiles/AIFileService.Exceptions.cs +++ b/Standard.AI.OpenAI/Services/Foundations/AIFiles/AIFileService.Exceptions.cs @@ -8,6 +8,7 @@ using RESTFulSense.Exceptions; using Standard.AI.OpenAI.Models.Services.Foundations.AIFiles; using Standard.AI.OpenAI.Models.Services.Foundations.AIFiles.Exceptions; +using Xeptions; namespace Standard.AI.OpenAI.Services.Foundations.AIFiles { @@ -24,67 +25,93 @@ private async ValueTask TryCatch(ReturningAIFileFunction returningAIFile } catch (NullAIFileException nullAIFileException) { - throw new AIFileValidationException(nullAIFileException); + throw CreateAIFileValidationException( + nullAIFileException); } catch (InvalidAIFileException invalidFileException) { - throw new AIFileValidationException(invalidFileException); + throw CreateAIFileValidationException( + invalidFileException); } catch (HttpResponseUrlNotFoundException httpResponseUrlNotFoundException) { var invalidConfigurationFileException = - new InvalidConfigurationAIFileException(httpResponseUrlNotFoundException); + new InvalidConfigurationAIFileException( + message: "Invalid AI file configuration error occurred, contact support.", + httpResponseUrlNotFoundException); - throw new AIFileDependencyException(invalidConfigurationFileException); + throw CreateAIFileDependencyException( + invalidConfigurationFileException); } catch (HttpResponseUnauthorizedException httpResponseUnauthorizedException) { var unauthorizedAIFileException = - new UnauthorizedAIFileException(httpResponseUnauthorizedException); + new UnauthorizedAIFileException( + message: "Unauthorized AI file request, fix errors and try again.", + httpResponseUnauthorizedException); - throw new AIFileDependencyException(unauthorizedAIFileException); + throw CreateAIFileDependencyException( + unauthorizedAIFileException); } catch (HttpResponseForbiddenException httpResponseForbiddenException) { var unauthorizedAIFileException = - new UnauthorizedAIFileException(httpResponseForbiddenException); + new UnauthorizedAIFileException( + message: "Unauthorized AI file request, fix errors and try again.", + httpResponseForbiddenException); - throw new AIFileDependencyException(unauthorizedAIFileException); + throw CreateAIFileDependencyException( + unauthorizedAIFileException); } catch (HttpResponseNotFoundException httpResponseNotFoundException) { var notFoundAIFileException = - new NotFoundAIFileException(httpResponseNotFoundException); + new NotFoundAIFileException( + message: "Not found AI file error occurred, fix errors and try again.", + httpResponseNotFoundException); - throw new AIFileDependencyValidationException(notFoundAIFileException); + throw CreateAIFileDependencyValidationException( + notFoundAIFileException); } catch (HttpResponseBadRequestException httpResponseBadRequestException) { var invalidAIFileException = - new InvalidAIFileException(httpResponseBadRequestException); + new InvalidAIFileException( + message: "Invalid AI file error occurred, fix errors and try again.", + httpResponseBadRequestException); - throw new AIFileDependencyValidationException(invalidAIFileException); + throw CreateAIFileDependencyValidationException( + invalidAIFileException); } catch (HttpResponseTooManyRequestsException httpResponseTooManyRequestsException) { var excessiveCallAIFileException = - new ExcessiveCallAIFileException(httpResponseTooManyRequestsException); + new ExcessiveCallAIFileException( + message: "Excessive call error occurred, limit your calls.", + httpResponseTooManyRequestsException); - throw new AIFileDependencyValidationException(excessiveCallAIFileException); + throw CreateAIFileDependencyValidationException( + excessiveCallAIFileException); } catch (HttpResponseException httpResponseException) { var failedServerAIFileException = - new FailedServerAIFileException(httpResponseException); + new FailedServerAIFileException( + message: "Failed AI file server error occurred, contact support.", + httpResponseException); - throw new AIFileDependencyException(failedServerAIFileException); + throw CreateAIFileDependencyException( + failedServerAIFileException); } catch (Exception exception) { var failedAIFileServiceException = - new FailedAIFileServiceException(exception); + new FailedAIFileServiceException( + message: "Failed AI file service error occurred, contact support.", + exception); - throw new AIFileServiceException(failedAIFileServiceException); + throw CreateAIFileServiceException( + failedAIFileServiceException); } } @@ -97,45 +124,92 @@ private async ValueTask> TryCatch(ReturningAIFilesFu catch (HttpResponseUrlNotFoundException httpResponseUrlNotFoundException) { var invalidConfigurationAIFileException = - new InvalidConfigurationAIFileException(httpResponseUrlNotFoundException); + new InvalidConfigurationAIFileException( + message: "Invalid AI file configuration error occurred, contact support.", + httpResponseUrlNotFoundException); - throw new AIFileDependencyException(invalidConfigurationAIFileException); + throw CreateAIFileDependencyException( + invalidConfigurationAIFileException); } catch (HttpResponseUnauthorizedException httpResponseUnauthorizedException) { var unauthorizedAIFileException = - new UnauthorizedAIFileException(httpResponseUnauthorizedException); + new UnauthorizedAIFileException( + message: "Unauthorized AI file request, fix errors and try again.", + httpResponseUnauthorizedException); - throw new AIFileDependencyException(unauthorizedAIFileException); + throw CreateAIFileDependencyException( + unauthorizedAIFileException); } catch (HttpResponseForbiddenException httpResponseForbiddenException) { var unauthorizedAIFileException = - new UnauthorizedAIFileException(httpResponseForbiddenException); + new UnauthorizedAIFileException( + message: "Unauthorized AI file request, fix errors and try again.", + httpResponseForbiddenException); - throw new AIFileDependencyException(unauthorizedAIFileException); + throw CreateAIFileDependencyException( + unauthorizedAIFileException); } catch (HttpResponseTooManyRequestsException httpResponseTooManyRequestsException) { var excessiveCallAIFileException = - new ExcessiveCallAIFileException(httpResponseTooManyRequestsException); + new ExcessiveCallAIFileException( + message: "Excessive call error occurred, limit your calls.", + httpResponseTooManyRequestsException); - throw new AIFileDependencyValidationException(excessiveCallAIFileException); + throw CreateAIFileDependencyValidationException( + excessiveCallAIFileException); } catch (HttpResponseException httpResponseException) { var failedServerAIFileException = - new FailedServerAIFileException(httpResponseException); + new FailedServerAIFileException( + message: "Failed AI file server error occurred, contact support.", + httpResponseException); - throw new AIFileDependencyException(failedServerAIFileException); + throw CreateAIFileDependencyException( + failedServerAIFileException); } catch (Exception exception) { var failedAIFileServiceException = - new FailedAIFileServiceException(exception); + new FailedAIFileServiceException( + message: "Failed AI file service error occurred, contact support.", + exception); - throw new AIFileServiceException(failedAIFileServiceException); + throw CreateAIFileServiceException( + failedAIFileServiceException); } } + + private static AIFileValidationException CreateAIFileValidationException(Xeption innerException) + { + throw new AIFileValidationException( + message: "AI file validation error occurred, fix errors and try again.", + innerException); + } + + private static AIFileDependencyException CreateAIFileDependencyException(Xeption innerException) + { + return new AIFileDependencyException( + message: "AI file dependency error occurred, contact support.", + innerException); + } + + private static AIFileDependencyValidationException CreateAIFileDependencyValidationException( + Xeption innerException) + { + return new AIFileDependencyValidationException( + message: "AI file dependency validation error occurred, contact support.", + innerException); + } + + private static AIFileServiceException CreateAIFileServiceException(Xeption innerException) + { + return new AIFileServiceException( + message: "AI file service error occurred, contact support.", + innerException); + } } } \ No newline at end of file diff --git a/Standard.AI.OpenAI/Services/Foundations/AIFiles/AIFileService.Validations.cs b/Standard.AI.OpenAI/Services/Foundations/AIFiles/AIFileService.Validations.cs index 68f5fc7c..d7b149da 100644 --- a/Standard.AI.OpenAI/Services/Foundations/AIFiles/AIFileService.Validations.cs +++ b/Standard.AI.OpenAI/Services/Foundations/AIFiles/AIFileService.Validations.cs @@ -27,7 +27,7 @@ private static void ValidateAIFileNotNull(AIFile aiFile) { if (aiFile is null) { - throw new NullAIFileException(); + throw new NullAIFileException(message: "Ai file is null."); } } @@ -48,7 +48,9 @@ private static void ValidateFileId(string fileId) => private static void Validate(params (dynamic Rule, string Parameter)[] validations) { - var invalidAIFileException = new InvalidAIFileException(); + var invalidAIFileException = + new InvalidAIFileException( + message: "Invalid AI file error occurred, fix errors and try again."); foreach ((dynamic rule, string parameter) in validations) { diff --git a/Standard.AI.OpenAI/Services/Foundations/AIFiles/AIFileService.cs b/Standard.AI.OpenAI/Services/Foundations/AIFiles/AIFileService.cs index 39b48041..84364999 100644 --- a/Standard.AI.OpenAI/Services/Foundations/AIFiles/AIFileService.cs +++ b/Standard.AI.OpenAI/Services/Foundations/AIFiles/AIFileService.cs @@ -2,13 +2,16 @@ // Copyright (c) The Standard Organization, a coalition of the Good-Hearted Engineers // ---------------------------------------------------------------------------------- +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Standard.AI.OpenAI.Brokers.DateTimes; using Standard.AI.OpenAI.Brokers.OpenAIs; using Standard.AI.OpenAI.Models.Services.Foundations.AIFiles; +using Standard.AI.OpenAI.Models.Services.Foundations.AIFiles.Exceptions; using Standard.AI.OpenAI.Models.Services.Foundations.ExternalAIFiles; +using Xeptions; namespace Standard.AI.OpenAI.Services.Foundations.AIFiles { @@ -115,5 +118,6 @@ private static AIFileStatus ConvertToAIFileStatus(string externalStatus) _ => AIFileStatus.Unknown }; } + } } \ No newline at end of file From a6181d8a59d75303e248774b6b04b98682d4bdb9 Mon Sep 17 00:00:00 2001 From: Lezune Date: Wed, 12 Jun 2024 21:43:20 -0700 Subject: [PATCH 2/6] Removed extra lines and added a break to method call --- .../Foundations/AIFiles/Exceptions/NullAiFileException.cs | 3 +-- .../Services/Foundations/AIFiles/AIFileService.Validations.cs | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/NullAiFileException.cs b/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/NullAiFileException.cs index f5c8cb01..45015ae0 100644 --- a/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/NullAiFileException.cs +++ b/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/NullAiFileException.cs @@ -12,9 +12,8 @@ public partial class NullAIFileException : Xeption public NullAIFileException(String message) : base(message) { } - public NullAIFileException(string message, Exception innerException) : base(message, innerException) { } } -} +} \ No newline at end of file diff --git a/Standard.AI.OpenAI/Services/Foundations/AIFiles/AIFileService.Validations.cs b/Standard.AI.OpenAI/Services/Foundations/AIFiles/AIFileService.Validations.cs index d7b149da..3f313f86 100644 --- a/Standard.AI.OpenAI/Services/Foundations/AIFiles/AIFileService.Validations.cs +++ b/Standard.AI.OpenAI/Services/Foundations/AIFiles/AIFileService.Validations.cs @@ -27,7 +27,8 @@ private static void ValidateAIFileNotNull(AIFile aiFile) { if (aiFile is null) { - throw new NullAIFileException(message: "Ai file is null."); + throw new NullAIFileException( + message: "Ai file is null."); } } From ceb846ac1aa18a74815ebbcff13393cea6a8120a Mon Sep 17 00:00:00 2001 From: Lezune Date: Wed, 12 Jun 2024 21:46:51 -0700 Subject: [PATCH 3/6] Added back the line break in NullAIFileException class declaration --- .../Foundations/AIFiles/Exceptions/NullAiFileException.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/NullAiFileException.cs b/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/NullAiFileException.cs index 45015ae0..8e71ad46 100644 --- a/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/NullAiFileException.cs +++ b/Standard.AI.OpenAI/Models/Services/Foundations/AIFiles/Exceptions/NullAiFileException.cs @@ -12,6 +12,7 @@ public partial class NullAIFileException : Xeption public NullAIFileException(String message) : base(message) { } + public NullAIFileException(string message, Exception innerException) : base(message, innerException) { } From 49db0410b50adb0f7f18ce266ef416b1b36aef27 Mon Sep 17 00:00:00 2001 From: Lezune Date: Wed, 12 Jun 2024 22:02:27 -0700 Subject: [PATCH 4/6] Updated Create methods in the AIOrchestrationServiceTests.cs file to adhere to method naming standards. --- .../AIFiles/AIFileOrchestrationServiceTests.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Standard.AI.OpenAI.Tests.Unit/Services/Orchestrations/AIFiles/AIFileOrchestrationServiceTests.cs b/Standard.AI.OpenAI.Tests.Unit/Services/Orchestrations/AIFiles/AIFileOrchestrationServiceTests.cs index ca1609c2..c25b4135 100644 --- a/Standard.AI.OpenAI.Tests.Unit/Services/Orchestrations/AIFiles/AIFileOrchestrationServiceTests.cs +++ b/Standard.AI.OpenAI.Tests.Unit/Services/Orchestrations/AIFiles/AIFileOrchestrationServiceTests.cs @@ -52,7 +52,7 @@ public static TheoryData DependencyValidationExceptions() message: "AI file validation error occurred, fix errors and try again.", someInnerException), - createAIFileDependencyValidationException( + CreateAIFileDependencyValidationException( someInnerException) }; } @@ -65,8 +65,8 @@ public static TheoryData DependencyExceptions() { new LocalFileDependencyException(someInnerException), new LocalFileServiceException(someInnerException), - createAIFileDependencyException(someInnerException), - createAIFileServiceException(someInnerException), + CreateAIFileDependencyException(someInnerException), + CreateAIFileServiceException(someInnerException), }; } @@ -76,8 +76,8 @@ public static TheoryData AIFileServiceDependencyExceptions() return new TheoryData { - createAIFileDependencyException(someInnerException), - createAIFileServiceException(someInnerException), + CreateAIFileDependencyException(someInnerException), + CreateAIFileServiceException(someInnerException), }; } @@ -148,20 +148,20 @@ private static string CreateRandomFileId() return randomId; } - private static AIFileDependencyException createAIFileDependencyException(Xeption innerException) + private static AIFileDependencyException CreateAIFileDependencyException(Xeption innerException) { return new AIFileDependencyException( message: "AI file dependency error occurred, contact support.", innerException); } - private static AIFileServiceException createAIFileServiceException(Xeption innerException) + private static AIFileServiceException CreateAIFileServiceException(Xeption innerException) { return new AIFileServiceException( message: "AI file service error occurred, contact support.", innerException); } - private static AIFileDependencyValidationException createAIFileDependencyValidationException(Xeption innerException) + private static AIFileDependencyValidationException CreateAIFileDependencyValidationException(Xeption innerException) { return new AIFileDependencyValidationException( message: "AI file dependency validation error occurred, contact support.", From d0895fe41d16fc14067c6218afb9c20e0e5b0f3a Mon Sep 17 00:00:00 2001 From: Lezune Date: Wed, 12 Jun 2024 22:14:28 -0700 Subject: [PATCH 5/6] Refactored code. --- ...FileServiceTests.Validations.RemoveById.cs | 2 +- .../AIFileServiceTests.Validations.Upload.cs | 8 ++-- .../Foundations/AIFiles/AIFileServiceTests.cs | 7 --- .../AIFileOrchestrationServiceTests.cs | 47 ++++++++----------- 4 files changed, 23 insertions(+), 41 deletions(-) diff --git a/Standard.AI.OpenAI.Tests.Unit/Services/Foundations/AIFiles/AIFileServiceTests.Validations.RemoveById.cs b/Standard.AI.OpenAI.Tests.Unit/Services/Foundations/AIFiles/AIFileServiceTests.Validations.RemoveById.cs index 16465aca..5cae1f20 100644 --- a/Standard.AI.OpenAI.Tests.Unit/Services/Foundations/AIFiles/AIFileServiceTests.Validations.RemoveById.cs +++ b/Standard.AI.OpenAI.Tests.Unit/Services/Foundations/AIFiles/AIFileServiceTests.Validations.RemoveById.cs @@ -24,7 +24,7 @@ private async Task ShouldThrowValidationExceptionOnRemoveByIdIfIdIsInvalidAsync( string invalidFileId = invalidId; var invalidFileException = - createInvalidAIFileException(); + new InvalidAIFileException(); invalidFileException.AddData( key: nameof(AIFile.Response.Id), diff --git a/Standard.AI.OpenAI.Tests.Unit/Services/Foundations/AIFiles/AIFileServiceTests.Validations.Upload.cs b/Standard.AI.OpenAI.Tests.Unit/Services/Foundations/AIFiles/AIFileServiceTests.Validations.Upload.cs index 559cea9e..d3d570f8 100644 --- a/Standard.AI.OpenAI.Tests.Unit/Services/Foundations/AIFiles/AIFileServiceTests.Validations.Upload.cs +++ b/Standard.AI.OpenAI.Tests.Unit/Services/Foundations/AIFiles/AIFileServiceTests.Validations.Upload.cs @@ -19,9 +19,7 @@ private async Task ShouldThrowValidationExceptionOnUploadIfAIFileIsNull() { // given AIFile nullAIFile = null; - var nullAIFileException = - new NullAIFileException( - message: "Ai file is null."); + var nullAIFileException = new NullAIFileException(); var expectedAIFileValidationException = new AIFileValidationException( @@ -54,7 +52,7 @@ private async Task ShouldThrowValidationExceptionOnUploadIfAIFileRequestIsNull() invalidAIFile.Request = null; var invalidAIFileException = - createInvalidAIFileException(); + new InvalidAIFileException(); invalidAIFileException.AddData( key: nameof(AIFile.Request), @@ -101,7 +99,7 @@ private async Task ShouldThrowValidationExceptionOnUploadIfAIFileRequestIsInvali }; var invalidAIFileException = - createInvalidAIFileException(); + new InvalidAIFileException(); invalidAIFileException.AddData( key: nameof(AIFileRequest.Name), diff --git a/Standard.AI.OpenAI.Tests.Unit/Services/Foundations/AIFiles/AIFileServiceTests.cs b/Standard.AI.OpenAI.Tests.Unit/Services/Foundations/AIFiles/AIFileServiceTests.cs index 821e2058..be2f3472 100644 --- a/Standard.AI.OpenAI.Tests.Unit/Services/Foundations/AIFiles/AIFileServiceTests.cs +++ b/Standard.AI.OpenAI.Tests.Unit/Services/Foundations/AIFiles/AIFileServiceTests.cs @@ -14,7 +14,6 @@ using Standard.AI.OpenAI.Brokers.DateTimes; using Standard.AI.OpenAI.Brokers.OpenAIs; using Standard.AI.OpenAI.Models.Services.Foundations.AIFiles; -using Standard.AI.OpenAI.Models.Services.Foundations.AIFiles.Exceptions; using Standard.AI.OpenAI.Models.Services.Foundations.ExternalAIFiles; using Standard.AI.OpenAI.Services.Foundations.AIFiles; using Tynamix.ObjectFiller; @@ -156,11 +155,5 @@ private Filler CreateAIFileFiller() return filler; } - - private static InvalidAIFileException createInvalidAIFileException() - { - return new InvalidAIFileException( - message: "Invalid AI file error occurred, fix errors and try again."); - } } } diff --git a/Standard.AI.OpenAI.Tests.Unit/Services/Orchestrations/AIFiles/AIFileOrchestrationServiceTests.cs b/Standard.AI.OpenAI.Tests.Unit/Services/Orchestrations/AIFiles/AIFileOrchestrationServiceTests.cs index c25b4135..b111bbd7 100644 --- a/Standard.AI.OpenAI.Tests.Unit/Services/Orchestrations/AIFiles/AIFileOrchestrationServiceTests.cs +++ b/Standard.AI.OpenAI.Tests.Unit/Services/Orchestrations/AIFiles/AIFileOrchestrationServiceTests.cs @@ -7,7 +7,6 @@ using System.IO; using System.Linq.Expressions; using KellermanSoftware.CompareNetObjects; -using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; using Moq; using Standard.AI.OpenAI.Models.Services.Foundations.AIFiles; using Standard.AI.OpenAI.Models.Services.Foundations.AIFiles.Exceptions; @@ -47,12 +46,13 @@ public static TheoryData DependencyValidationExceptions() { new LocalFileValidationException(someInnerException), new LocalFileDependencyValidationException(someInnerException), - + new AIFileValidationException( - message: "AI file validation error occurred, fix errors and try again.", + message: "AI file validation error occurred, fix errors and try again.", someInnerException), - CreateAIFileDependencyValidationException( + new AIFileDependencyValidationException( + message: "AI file dependency validation error occurred, contact support.", someInnerException) }; } @@ -65,8 +65,14 @@ public static TheoryData DependencyExceptions() { new LocalFileDependencyException(someInnerException), new LocalFileServiceException(someInnerException), - CreateAIFileDependencyException(someInnerException), - CreateAIFileServiceException(someInnerException), + + new AIFileDependencyException( + message: "AI file dependency error occurred, contact support.", + someInnerException), + + new AIFileServiceException( + message: "AI file service error occurred, contact support.", + someInnerException), }; } @@ -76,8 +82,13 @@ public static TheoryData AIFileServiceDependencyExceptions() return new TheoryData { - CreateAIFileDependencyException(someInnerException), - CreateAIFileServiceException(someInnerException), + new AIFileDependencyException( + message: "AI file dependency error occurred, contact support.", + someInnerException), + + new AIFileServiceException( + message: "AI file service error occurred, contact support.", + someInnerException), }; } @@ -147,25 +158,5 @@ private static string CreateRandomFileId() return randomId; } - - private static AIFileDependencyException CreateAIFileDependencyException(Xeption innerException) - { - return new AIFileDependencyException( - message: "AI file dependency error occurred, contact support.", - innerException); - } - private static AIFileServiceException CreateAIFileServiceException(Xeption innerException) - { - return new AIFileServiceException( - message: "AI file service error occurred, contact support.", - innerException); - } - - private static AIFileDependencyValidationException CreateAIFileDependencyValidationException(Xeption innerException) - { - return new AIFileDependencyValidationException( - message: "AI file dependency validation error occurred, contact support.", - innerException); - } } } \ No newline at end of file From b36df9b6ce0640699ca22656e3a9919a5a2e385c Mon Sep 17 00:00:00 2001 From: Lezune Date: Thu, 13 Jun 2024 10:45:01 -0700 Subject: [PATCH 6/6] Updated method calls in Unit Test files to adhere to changes in the class declarations --- .../AIFiles/AIFileServiceTests.Validations.RemoveById.cs | 3 ++- .../AIFiles/AIFileServiceTests.Validations.Upload.cs | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Standard.AI.OpenAI.Tests.Unit/Services/Foundations/AIFiles/AIFileServiceTests.Validations.RemoveById.cs b/Standard.AI.OpenAI.Tests.Unit/Services/Foundations/AIFiles/AIFileServiceTests.Validations.RemoveById.cs index 5cae1f20..aa594bce 100644 --- a/Standard.AI.OpenAI.Tests.Unit/Services/Foundations/AIFiles/AIFileServiceTests.Validations.RemoveById.cs +++ b/Standard.AI.OpenAI.Tests.Unit/Services/Foundations/AIFiles/AIFileServiceTests.Validations.RemoveById.cs @@ -24,7 +24,8 @@ private async Task ShouldThrowValidationExceptionOnRemoveByIdIfIdIsInvalidAsync( string invalidFileId = invalidId; var invalidFileException = - new InvalidAIFileException(); + new InvalidAIFileException( + message: "Invalid AI file error occurred, fix errors and try again."); invalidFileException.AddData( key: nameof(AIFile.Response.Id), diff --git a/Standard.AI.OpenAI.Tests.Unit/Services/Foundations/AIFiles/AIFileServiceTests.Validations.Upload.cs b/Standard.AI.OpenAI.Tests.Unit/Services/Foundations/AIFiles/AIFileServiceTests.Validations.Upload.cs index d3d570f8..bc399f80 100644 --- a/Standard.AI.OpenAI.Tests.Unit/Services/Foundations/AIFiles/AIFileServiceTests.Validations.Upload.cs +++ b/Standard.AI.OpenAI.Tests.Unit/Services/Foundations/AIFiles/AIFileServiceTests.Validations.Upload.cs @@ -19,7 +19,8 @@ private async Task ShouldThrowValidationExceptionOnUploadIfAIFileIsNull() { // given AIFile nullAIFile = null; - var nullAIFileException = new NullAIFileException(); + var nullAIFileException = new NullAIFileException( + message: "Ai file is null."); var expectedAIFileValidationException = new AIFileValidationException( @@ -52,7 +53,8 @@ private async Task ShouldThrowValidationExceptionOnUploadIfAIFileRequestIsNull() invalidAIFile.Request = null; var invalidAIFileException = - new InvalidAIFileException(); + new InvalidAIFileException( + message: "Invalid AI file error occurred, fix errors and try again."); invalidAIFileException.AddData( key: nameof(AIFile.Request), @@ -99,7 +101,8 @@ private async Task ShouldThrowValidationExceptionOnUploadIfAIFileRequestIsInvali }; var invalidAIFileException = - new InvalidAIFileException(); + new InvalidAIFileException( + message: "Invalid AI file error occurred, fix errors and try again."); invalidAIFileException.AddData( key: nameof(AIFileRequest.Name),