- 
                Notifications
    You must be signed in to change notification settings 
- Fork 18
[OpenAPI] Add endpoint for list of deployment models #294
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
Changes from 13 commits
a8685bb
              0844926
              549bd95
              6d9356f
              99e9c30
              6750d41
              433a867
              4f2befc
              69290d0
              9d87a67
              831ef9d
              ac237a7
              b4e6e46
              b298981
              86ee842
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| using System.Text.Json.Serialization; | ||
|  | ||
| /// <summary> | ||
| /// This represent the event detail data for response by admin event endpoint. | ||
| /// </summary> | ||
| public class DeploymentModelDetails | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the deployment model name. | ||
| /// </summary> | ||
| [JsonRequired] | ||
| public string Name { get; set; } = string.Empty; | ||
|  | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,239 @@ | ||
| using System.Text.Json; | ||
|  | ||
| using AzureOpenAIProxy.AppHost.Tests.Fixtures; | ||
|  | ||
| using FluentAssertions; | ||
|  | ||
| using IdentityModel.Client; | ||
|  | ||
|  | ||
| namespace AzureOpenAIProxy.AppHost.Tests.ApiApp.Endpoints; | ||
|  | ||
| public class GetDeploymentModelsOpenApiTests(AspireAppHostFixture host) : IClassFixture<AspireAppHostFixture> | ||
| { | ||
| [Fact] | ||
| public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Path() | ||
| { | ||
| // Arrange | ||
| using var httpClient = host.App!.CreateHttpClient("apiapp"); | ||
|  | ||
| // Act | ||
| var json = await httpClient.GetStringAsync("/swagger/v1.0.0/swagger.json"); | ||
| var apiDocument = JsonSerializer.Deserialize<JsonDocument>(json); | ||
|  | ||
| // Assert | ||
| var result = apiDocument!.RootElement.GetProperty("paths") | ||
| .TryGetProperty("/events/{eventId}/deployment-models", out var property) ? property : default; | ||
| result.ValueKind.Should().Be(JsonValueKind.Object); | ||
| } | ||
|  | ||
| [Fact] | ||
| public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Verb() | ||
| { | ||
| // Arrange | ||
| using var httpClient = host.App!.CreateHttpClient("apiapp"); | ||
|  | ||
| // Act | ||
| var json = await httpClient.GetStringAsync("/swagger/v1.0.0/swagger.json"); | ||
| var apiDocument = JsonSerializer.Deserialize<JsonDocument>(json); | ||
|  | ||
| // Assert | ||
| var result = apiDocument!.RootElement.GetProperty("paths") | ||
| .GetProperty("/events/{eventId}/deployment-models") | ||
| .TryGetProperty("get", out var property) ? property : default; | ||
| result.ValueKind.Should().Be(JsonValueKind.Object); | ||
| } | ||
|  | ||
| [Theory] | ||
| [InlineData("events")] | ||
| public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Tags(string tag) | ||
| { | ||
| // Arrange | ||
| using var httpClient = host.App!.CreateHttpClient("apiapp"); | ||
|  | ||
| // Act | ||
| var json = await httpClient.GetStringAsync("/swagger/v1.0.0/swagger.json"); | ||
| var apiDocument = JsonSerializer.Deserialize<JsonDocument>(json); | ||
|  | ||
| // Assert | ||
| var result = apiDocument!.RootElement.GetProperty("paths") | ||
| .GetProperty("/events/{eventId}/deployment-models") | ||
| .GetProperty("get") | ||
| .TryGetProperty("tags", out var property) ? property : default; | ||
| result.ValueKind.Should().Be(JsonValueKind.Array); | ||
| result.EnumerateArray().Select(p => p.GetString()).Should().Contain(tag); | ||
| } | ||
|  | ||
| [Theory] | ||
| [InlineData("summary")] | ||
| [InlineData("description")] | ||
| [InlineData("operationId")] | ||
| public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Value(string attribute) | ||
| { | ||
| // Arrange | ||
| using var httpClient = host.App!.CreateHttpClient("apiapp"); | ||
|  | ||
| // Act | ||
| var json = await httpClient.GetStringAsync("/swagger/v1.0.0/swagger.json"); | ||
| var apiDocument = JsonSerializer.Deserialize<JsonDocument>(json); | ||
|  | ||
| // Assert | ||
| var result = apiDocument!.RootElement.GetProperty("paths") | ||
| .GetProperty("/events/{eventId}/deployment-models") | ||
| .GetProperty("get") | ||
| .TryGetProperty(attribute, out var property) ? property : default; | ||
| result.ValueKind.Should().Be(JsonValueKind.String); | ||
| } | ||
|  | ||
|  | ||
| [Theory] | ||
| [InlineData("eventId")] | ||
| public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Path_Parameter(string name) | ||
| { | ||
| // Arrange | ||
| using var httpClient = host.App!.CreateHttpClient("apiapp"); | ||
|  | ||
| // Act | ||
| var json = await httpClient.GetStringAsync("/swagger/v1.0.0/swagger.json"); | ||
| var openapi = JsonSerializer.Deserialize<JsonDocument>(json); | ||
|  | ||
| // Assert | ||
| var result = openapi!.RootElement.GetProperty("paths") | ||
| .GetProperty("/events/{eventId}/deployment-models") | ||
| .GetProperty("get") | ||
| .GetProperty("parameters") | ||
| .EnumerateArray() | ||
| .Where(p => p.GetProperty("in").GetString() == "path") | ||
| .Select(p => p.GetProperty("name").ToString()); | ||
| result.Should().Contain(name); | ||
| } | ||
|  | ||
| [Theory] | ||
| [InlineData("responses")] | ||
| public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Object(string attribute) | ||
| { | ||
| // Arrange | ||
| using var httpClient = host.App!.CreateHttpClient("apiapp"); | ||
|  | ||
| // Act | ||
| var json = await httpClient.GetStringAsync("/swagger/v1.0.0/swagger.json"); | ||
| var apiDocument = JsonSerializer.Deserialize<JsonDocument>(json); | ||
|  | ||
| // Assert | ||
| var result = apiDocument!.RootElement.GetProperty("paths") | ||
| .GetProperty("/events/{eventId}/deployment-models") | ||
| .GetProperty("get") | ||
| .TryGetProperty(attribute, out var property) ? property : default; | ||
| result.ValueKind.Should().Be(JsonValueKind.Object); | ||
| } | ||
|  | ||
| [Theory] | ||
| [InlineData("200")] | ||
| [InlineData("401")] | ||
| [InlineData("404")] | ||
|         
                  jihyunmoon16 marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| [InlineData("500")] | ||
| public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Response(string attribute) | ||
| { | ||
| // Arrange | ||
| using var httpClient = host.App!.CreateHttpClient("apiapp"); | ||
|  | ||
| // Act | ||
| var json = await httpClient.GetStringAsync("/swagger/v1.0.0/swagger.json"); | ||
| var apiDocument = JsonSerializer.Deserialize<JsonDocument>(json); | ||
|  | ||
| // Assert | ||
| var result = apiDocument!.RootElement.GetProperty("paths") | ||
| .GetProperty("/events/{eventId}/deployment-models") | ||
| .GetProperty("get") | ||
| .GetProperty("responses") | ||
| .TryGetProperty(attribute, out var property) ? property : default; | ||
| result.ValueKind.Should().Be(JsonValueKind.Object); | ||
| } | ||
|  | ||
|  | ||
| [Fact] | ||
| public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Model() | ||
| { | ||
| // Arrange | ||
| using var httpClient = host.App!.CreateHttpClient("apiapp"); | ||
|  | ||
| // Act | ||
| var json = await httpClient.GetStringAsync("/swagger/v1.0.0/swagger.json"); | ||
| var openapi = JsonSerializer.Deserialize<JsonDocument>(json); | ||
|  | ||
| // Assert | ||
| var result = openapi!.RootElement.GetProperty("components") | ||
| .GetProperty("schemas") | ||
| .TryGetProperty("DeploymentModelDetails", out var property) ? property : default; | ||
| result.ValueKind.Should().Be(JsonValueKind.Object); | ||
| } | ||
|  | ||
| public static IEnumerable<object[]> DeploymentModelAttributeData => | ||
| [ | ||
| ["name", true, "string"] | ||
| ]; | ||
|  | ||
|  | ||
| [Theory] | ||
| [MemberData(nameof(DeploymentModelAttributeData))] | ||
|         
                  jihyunmoon16 marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Required(string attribute, bool isRequired, string type) | ||
| { | ||
| // Arrange | ||
| using var httpClient = host.App!.CreateHttpClient("apiapp"); | ||
|  | ||
| var isReq = isRequired; | ||
| var typeStr = type; | ||
|         
                  jihyunmoon16 marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
|  | ||
| // Act | ||
| var json = await httpClient.GetStringAsync("/swagger/v1.0.0/swagger.json"); | ||
| var openapi = JsonSerializer.Deserialize<JsonDocument>(json); | ||
|  | ||
| // Assert | ||
| var result = openapi!.RootElement.GetProperty("components") | ||
| .GetProperty("schemas") | ||
| .GetProperty("DeploymentModelDetails") | ||
| .TryGetStringArray("required") | ||
| .ToList(); | ||
| result.Contains(attribute).Should().Be(isRequired); | ||
| } | ||
|  | ||
| [Theory] | ||
| [MemberData(nameof(DeploymentModelAttributeData))] | ||
| public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Property(string attribute, bool isRequired, string type) | ||
| Check warning on line 202 in test/AzureOpenAIProxy.AppHost.Tests/ApiApp/Endpoints/GetDeploymentModelsOpenApiTest.cs 
     | ||
|         
                  jihyunmoon16 marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| { | ||
| // Arrange | ||
| using var httpClient = host.App!.CreateHttpClient("apiapp"); | ||
|  | ||
| // Act | ||
| var json = await httpClient.GetStringAsync("/swagger/v1.0.0/swagger.json"); | ||
| var openapi = JsonSerializer.Deserialize<JsonDocument>(json); | ||
|  | ||
| // Assert | ||
| var result = openapi!.RootElement.GetProperty("components") | ||
| .GetProperty("schemas") | ||
| .GetProperty("DeploymentModelDetails") | ||
|         
                  jihyunmoon16 marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| .GetProperty("properties") | ||
| .TryGetProperty(attribute, out var property) ? property : default; | ||
| result.ValueKind.Should().Be(JsonValueKind.Object); | ||
| } | ||
|  | ||
| [Theory] | ||
| [MemberData(nameof(DeploymentModelAttributeData))] | ||
| public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Type(string attribute, bool isRequired, string type) | ||
| Check warning on line 222 in test/AzureOpenAIProxy.AppHost.Tests/ApiApp/Endpoints/GetDeploymentModelsOpenApiTest.cs 
     | ||
|         
                  jihyunmoon16 marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| { | ||
| // Arrange | ||
| using var httpClient = host.App!.CreateHttpClient("apiapp"); | ||
|  | ||
| // Act | ||
| var json = await httpClient.GetStringAsync("/swagger/v1.0.0/swagger.json"); | ||
| var openapi = JsonSerializer.Deserialize<JsonDocument>(json); | ||
|  | ||
| // Assert | ||
| var result = openapi!.RootElement.GetProperty("components") | ||
| .GetProperty("schemas") | ||
| .GetProperty("DeploymentModelDetails") | ||
| .GetProperty("properties") | ||
| .GetProperty(attribute); | ||
| result.TryGetString("type").Should().Be(type); | ||
| } | ||
| } | ||
|         
                  jihyunmoon16 marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
Uh oh!
There was an error while loading. Please reload this page.