-
Notifications
You must be signed in to change notification settings - Fork 12
Refactor tests #29
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
Merged
Merged
Refactor tests #29
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ca1ff94
chore: Move tests to root.
peombwa 24aeef5
chore: Update solution.
peombwa 55e564b
- Adds verification tokens to OpenAI manifest auth
peombwa 29a3390
chore: Fix code smells.
peombwa a9ab5ad
chore: Remove empty statement.
peombwa fa21e6a
Merge branch 'main' into po/refactorTests
peombwa 8d373a0
- refactor BaseManifestAuth class.
peombwa 52a56f4
chore: Adds missing coverlet.msbuild
peombwa 653400a
- Adds OpenAI Plugin manifest validation
peombwa 05a9949
chore: Simplify OpenAIPluginManifest constructor.
peombwa 687f1d3
chore: Adds tests for ParseHelpers.
peombwa 36189d1
chore: Use ThrowIfNull for validating null objects.
peombwa ff2841e
chore: Remove explicit caller argument info on ThrowIfNull.
peombwa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| using System.Text.RegularExpressions; | ||
|
|
||
| namespace Microsoft.OpenApi.ApiManifest.Helpers | ||
| { | ||
| internal static class ValidationHelpers | ||
| { | ||
| internal static void ValidateNullOrWhitespace(string parameterName, string? value, string parentName) | ||
| { | ||
| if (string.IsNullOrWhiteSpace(value)) | ||
| throw new ArgumentNullException(parameterName, string.Format(ErrorMessage.FieldIsRequired, parameterName, parentName)); | ||
| } | ||
|
|
||
| internal static void ValidateNullObject(string parameterName, object? value, string parentName) | ||
peombwa marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| if (value == null) | ||
| throw new ArgumentNullException(parameterName, string.Format(ErrorMessage.FieldIsRequired, parameterName, parentName)); | ||
| } | ||
|
|
||
| internal static void ValidateLength(string parameterName, string? value, int maxLength) | ||
| { | ||
| if (value?.Length > maxLength) | ||
| throw new ArgumentOutOfRangeException(parameterName, string.Format(ErrorMessage.FieldLengthExceeded, parameterName, maxLength)); | ||
| } | ||
|
|
||
| internal static void ValidateEmail(string parameterName, string? value, string parentName) | ||
| { | ||
| if (string.IsNullOrWhiteSpace(value)) | ||
| throw new ArgumentNullException(parameterName, string.Format(ErrorMessage.FieldIsRequired, parameterName, parentName)); | ||
| else | ||
| ValidateEmail(parameterName, value); | ||
| } | ||
|
|
||
| internal static void ValidateBaseUrl(string parameterName, string? baseUrl) | ||
| { | ||
| // Check if the baseUrl is a valid URL and ends in a slash. | ||
| if (string.IsNullOrWhiteSpace(baseUrl) || !baseUrl.EndsWith("/", StringComparison.Ordinal) || !Uri.TryCreate(baseUrl, UriKind.Absolute, out _)) | ||
| throw new ArgumentException(string.Format(ErrorMessage.BaseUrlIsNotValid, nameof(baseUrl)), parameterName); | ||
| } | ||
|
|
||
| private static readonly Regex s_emailRegex = new(@"^[^@\s]+@[^@\s]+$", RegexOptions.Compiled, Constants.DefaultRegexTimeout); | ||
| private static void ValidateEmail(string parameterName, string value) | ||
| { | ||
| if (!s_emailRegex.IsMatch(value)) | ||
| throw new ArgumentException(string.Format(ErrorMessage.FieldIsNotValid, parameterName), parameterName); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,37 +1,64 @@ | ||
|
|
||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. | ||
|
|
||
| using Microsoft.OpenApi.ApiManifest.Helpers; | ||
| using System.Text.Json; | ||
|
|
||
| namespace Microsoft.OpenApi.ApiManifest.OpenAI; | ||
|
|
||
| public class Api | ||
| { | ||
| private const string TypeProperty = "type"; | ||
| private const string UrlProperty = "url"; | ||
| private const string IsUserAuthenticatedProperty = "is_user_authenticated"; | ||
| public string? Type { get; set; } | ||
| public string? Url { get; set; } | ||
| public bool? IsUserAuthenticated { get; set; } | ||
|
|
||
| public Api(string type, string url) | ||
| { | ||
| Type = type; | ||
| Url = url; | ||
| Validate(this); | ||
| } | ||
|
|
||
| internal Api(JsonElement value) | ||
| { | ||
| ParsingHelpers.ParseMap(value, this, handlers); | ||
| Validate(this); | ||
| } | ||
|
|
||
| public static Api Load(JsonElement value) | ||
| { | ||
| var api = new Api(); | ||
| var api = new Api(value); | ||
| ParsingHelpers.ParseMap(value, api, handlers); | ||
| return api; | ||
| } | ||
|
|
||
| // Create handlers FixedFieldMap for Api | ||
| private static readonly FixedFieldMap<Api> handlers = new() | ||
| { | ||
| { "type", (o,v) => {o.Type = v.GetString(); } }, | ||
| { "url", (o,v) => {o.Url = v.GetString(); } }, | ||
| { "is_user_authenticated", (o,v) => {o.IsUserAuthenticated = v.GetBoolean(); }}, | ||
| { TypeProperty, (o,v) => {o.Type = v.GetString(); } }, | ||
| { UrlProperty, (o,v) => {o.Url = v.GetString(); } }, | ||
| { IsUserAuthenticatedProperty, (o,v) => {o.IsUserAuthenticated = v.GetBoolean(); }}, | ||
| }; | ||
|
|
||
| public void Write(Utf8JsonWriter writer) | ||
| { | ||
| Validate(this); | ||
| writer.WriteStartObject(); | ||
| writer.WriteString("type", Type); | ||
| writer.WriteString("url", Url); | ||
| writer.WriteBoolean("is_user_authenticated", IsUserAuthenticated ?? false); | ||
| writer.WriteString(TypeProperty, Type); | ||
| writer.WriteString(UrlProperty, Url); | ||
| writer.WriteBoolean(IsUserAuthenticatedProperty, IsUserAuthenticated ?? false); | ||
| writer.WriteEndObject(); | ||
| } | ||
|
|
||
| private void Validate(Api api) | ||
| { | ||
| ValidationHelpers.ValidateNullOrWhitespace(nameof(Type), api.Type, nameof(Api)); | ||
| ValidationHelpers.ValidateNullOrWhitespace(nameof(Url), api.Url, nameof(Api)); | ||
| } | ||
| } | ||
|
|
||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.