Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 59 additions & 59 deletions src/AzureOpenAIProxy.ApiApp/Models/AdminEventDetails.cs
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
using System.Text.Json.Serialization;

namespace AzureOpenAIProxy.ApiApp.Models;

/// <summary>
/// This represent the event detail data for response by admin event endpoint.
/// </summary>
public class AdminEventDetails : EventDetails
{
/// <summary>
/// Gets or sets the event description.
/// </summary>
public string? Description { get; set; }

/// <summary>
/// Gets or sets the event start date.
/// </summary>
[JsonRequired]
public DateTimeOffset DateStart { get; set; }

/// <summary>
/// Gets or sets the event end date.
/// </summary>
[JsonRequired]
public DateTimeOffset DateEnd { get; set; }

/// <summary>
/// Gets or sets the event start to end date timezone.
/// </summary>
[JsonRequired]
public string TimeZone { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the event active status.
/// </summary>
[JsonRequired]
public bool IsActive { get; set; }

/// <summary>
/// Gets or sets the event organizer name.
/// </summary>
[JsonRequired]
public string OrganizerName { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the event organizer email.
/// </summary>
[JsonRequired]
public string OrganizerEmail { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the event coorganizer name.
/// </summary>
public string? CoorganizerName { get; set; }

/// <summary>
/// Gets or sets the event coorganizer email.
/// </summary>
public string? CoorganizerEmail { get; set; }
using System.Text.Json.Serialization;
namespace AzureOpenAIProxy.ApiApp.Models;
/// <summary>
/// This represent the entity for the event details for admin.
/// </summary>
public class AdminEventDetails : EventDetails
{
/// <summary>
/// Gets or sets the event description.
/// </summary>
public string? Description { get; set; }
/// <summary>
/// Gets or sets the event start date.
/// </summary>
[JsonRequired]
public DateTimeOffset DateStart { get; set; }
/// <summary>
/// Gets or sets the event end date.
/// </summary>
[JsonRequired]
public DateTimeOffset DateEnd { get; set; }
/// <summary>
/// Gets or sets the event start to end date timezone.
/// </summary>
[JsonRequired]
public string TimeZone { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the event active status.
/// </summary>
[JsonRequired]
public bool IsActive { get; set; }
/// <summary>
/// Gets or sets the event organizer name.
/// </summary>
[JsonRequired]
public string OrganizerName { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the event organizer email.
/// </summary>
[JsonRequired]
public string OrganizerEmail { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the event coorganizer name.
/// </summary>
public string? CoorganizerName { get; set; }
/// <summary>
/// Gets or sets the event coorganizer email.
/// </summary>
public string? CoorganizerEmail { get; set; }
}
84 changes: 84 additions & 0 deletions src/AzureOpenAIProxy.ApiApp/Models/AdminResourceDetails.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using System.Runtime.Serialization;
using System.Text.Json.Serialization;

using AzureOpenAIProxy.ApiApp.Converters;

namespace AzureOpenAIProxy.ApiApp.Models;

/// <summary>
/// This represent the entity for the resource details for admin.
/// </summary>
public class AdminResourceDetails
{
/// <summary>
/// Gets or sets the event id.
/// </summary>
[JsonRequired]
public Guid ResourceId { get; set; }

/// <summary>
/// Gets or sets the friendly name of the resource.
/// </summary>
[JsonRequired]
public string FriendlyName { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the deployment name of the resource.
/// </summary>
[JsonRequired]
public string DeploymentName { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the resource type.
/// </summary>
[JsonRequired]
public ResourceType ResourceType { get; set; } = ResourceType.None;

/// <summary>
/// Gets or sets the resource endpoint.
/// </summary>
[JsonRequired]
public string Endpoint { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the resource API key.
/// </summary>
[JsonRequired]
public string ApiKey { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the resource region.
/// </summary>
[JsonRequired]
public string Region { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the value indicating whether the resource is active.
/// </summary>
[JsonRequired]
public bool IsActive { get; set; }
}

/// <summary>
/// /// This defines the type of the resource.
[JsonConverter(typeof(EnumMemberConverter<ResourceType>))]
public enum ResourceType
{
/// <summary>
/// Indicates the resource type is not defined.
/// </summary>
[EnumMember(Value = "none")]
None,

/// <summary>
/// Indicates the chat resource type.
/// </summary>
[EnumMember(Value = "chat")]
Chat,

/// <summary>
/// Indicates the image resource type.
/// </summary>
[EnumMember(Value = "image")]
Image,
}
72 changes: 36 additions & 36 deletions src/AzureOpenAIProxy.ApiApp/Models/EventDetails.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
using System.Text.Json.Serialization;

/// <summary>
/// This represents the event's detailed data for response by EventEndpoint.
/// </summary>
public class EventDetails
{
/// <summary>
/// Gets or sets the event id.
/// </summary>
[JsonRequired]
public Guid EventId { get; set; }

/// <summary>
/// Gets or sets the event title name.
/// </summary>
[JsonRequired]
public string Title { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the event summary.
/// </summary>
[JsonRequired]
public string Summary { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the Azure OpenAI Service request max token capacity.
/// </summary>
[JsonRequired]
public int MaxTokenCap { get; set; }

/// <summary>
/// Gets or sets the Azure OpenAI Service daily request capacity.
/// </summary>
[JsonRequired]
public int DailyRequestCap { get; set; }
using System.Text.Json.Serialization;
/// <summary>
/// This represent the entity for the event details for users.
/// </summary>
public class EventDetails
{
/// <summary>
/// Gets or sets the event id.
/// </summary>
[JsonRequired]
public Guid EventId { get; set; }
/// <summary>
/// Gets or sets the event title name.
/// </summary>
[JsonRequired]
public string Title { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the event summary.
/// </summary>
[JsonRequired]
public string Summary { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the Azure OpenAI Service request max token capacity.
/// </summary>
[JsonRequired]
public int MaxTokenCap { get; set; }
/// <summary>
/// Gets or sets the Azure OpenAI Service daily request capacity.
/// </summary>
[JsonRequired]
public int DailyRequestCap { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System.Text.Json;

using AzureOpenAIProxy.ApiApp.Models;

using FluentAssertions;

namespace AzureOpenAIProxy.ApiApp.Tests.Models;

public class AdminResourceDetailsTests
{
private static readonly AdminResourceDetails examplePayload = new()
{
ResourceId = Guid.Parse("67f410a3-c5e4-4326-a3ad-5812b9adfc06"),
FriendlyName = "Test Resource",
DeploymentName = "Test Deployment",
ResourceType = ResourceType.Chat,
Endpoint = "https://test.endpoint.com",
ApiKey = "test-api-key",
Region = "test-region",
IsActive = true
};

private static readonly string exampleJson = """
{
"resourceId": "67f410a3-c5e4-4326-a3ad-5812b9adfc06",
"friendlyName": "Test Resource",
"deploymentName": "Test Deployment",
"resourceType": "chat",
"endpoint": "https://test.endpoint.com",
"apiKey": "test-api-key",
"region": "test-region",
"isActive": true
}
""";

private static readonly JsonSerializerOptions options = new()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
WriteIndented = true
};

[Fact]
public void Given_ExamplePayload_When_Serialized_Then_It_Should_Match_Json()
{
// Act
var serialised = JsonSerializer.Serialize(examplePayload, options);

// Assert
serialised.Should().ContainAll(
"\"resourceId\":", "\"67f410a3-c5e4-4326-a3ad-5812b9adfc06\"",
"\"friendlyName\":", "\"Test Resource\"",
"\"deploymentName\":", "\"Test Deployment\"",
"\"resourceType\":", "\"chat\"",
"\"endpoint\":", "\"https://test.endpoint.com\"",
"\"apiKey\":", "\"test-api-key\"",
"\"region\":", "\"test-region\"",
"\"isActive\":", "true");
}

[Fact]
public void Given_ExampleJson_When_Deserialized_Then_It_Should_Match_Object()
{
// Arrange & Act
var deserialised = JsonSerializer.Deserialize<AdminResourceDetails>(exampleJson, options);

// Assert
deserialised.Should().BeEquivalentTo(examplePayload);
}
}
Loading
Loading