Skip to content

Commit 3f0eca9

Browse files
authored
Add AdminResourceDetails model (#306)
1 parent c8c1e83 commit 3f0eca9

File tree

5 files changed

+526
-372
lines changed

5 files changed

+526
-372
lines changed
Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
1-
using System.Text.Json.Serialization;
2-
3-
namespace AzureOpenAIProxy.ApiApp.Models;
4-
5-
/// <summary>
6-
/// This represent the event detail data for response by admin event endpoint.
7-
/// </summary>
8-
public class AdminEventDetails : EventDetails
9-
{
10-
/// <summary>
11-
/// Gets or sets the event description.
12-
/// </summary>
13-
public string? Description { get; set; }
14-
15-
/// <summary>
16-
/// Gets or sets the event start date.
17-
/// </summary>
18-
[JsonRequired]
19-
public DateTimeOffset DateStart { get; set; }
20-
21-
/// <summary>
22-
/// Gets or sets the event end date.
23-
/// </summary>
24-
[JsonRequired]
25-
public DateTimeOffset DateEnd { get; set; }
26-
27-
/// <summary>
28-
/// Gets or sets the event start to end date timezone.
29-
/// </summary>
30-
[JsonRequired]
31-
public string TimeZone { get; set; } = string.Empty;
32-
33-
/// <summary>
34-
/// Gets or sets the event active status.
35-
/// </summary>
36-
[JsonRequired]
37-
public bool IsActive { get; set; }
38-
39-
/// <summary>
40-
/// Gets or sets the event organizer name.
41-
/// </summary>
42-
[JsonRequired]
43-
public string OrganizerName { get; set; } = string.Empty;
44-
45-
/// <summary>
46-
/// Gets or sets the event organizer email.
47-
/// </summary>
48-
[JsonRequired]
49-
public string OrganizerEmail { get; set; } = string.Empty;
50-
51-
/// <summary>
52-
/// Gets or sets the event coorganizer name.
53-
/// </summary>
54-
public string? CoorganizerName { get; set; }
55-
56-
/// <summary>
57-
/// Gets or sets the event coorganizer email.
58-
/// </summary>
59-
public string? CoorganizerEmail { get; set; }
1+
using System.Text.Json.Serialization;
2+
3+
namespace AzureOpenAIProxy.ApiApp.Models;
4+
5+
/// <summary>
6+
/// This represent the entity for the event details for admin.
7+
/// </summary>
8+
public class AdminEventDetails : EventDetails
9+
{
10+
/// <summary>
11+
/// Gets or sets the event description.
12+
/// </summary>
13+
public string? Description { get; set; }
14+
15+
/// <summary>
16+
/// Gets or sets the event start date.
17+
/// </summary>
18+
[JsonRequired]
19+
public DateTimeOffset DateStart { get; set; }
20+
21+
/// <summary>
22+
/// Gets or sets the event end date.
23+
/// </summary>
24+
[JsonRequired]
25+
public DateTimeOffset DateEnd { get; set; }
26+
27+
/// <summary>
28+
/// Gets or sets the event start to end date timezone.
29+
/// </summary>
30+
[JsonRequired]
31+
public string TimeZone { get; set; } = string.Empty;
32+
33+
/// <summary>
34+
/// Gets or sets the event active status.
35+
/// </summary>
36+
[JsonRequired]
37+
public bool IsActive { get; set; }
38+
39+
/// <summary>
40+
/// Gets or sets the event organizer name.
41+
/// </summary>
42+
[JsonRequired]
43+
public string OrganizerName { get; set; } = string.Empty;
44+
45+
/// <summary>
46+
/// Gets or sets the event organizer email.
47+
/// </summary>
48+
[JsonRequired]
49+
public string OrganizerEmail { get; set; } = string.Empty;
50+
51+
/// <summary>
52+
/// Gets or sets the event coorganizer name.
53+
/// </summary>
54+
public string? CoorganizerName { get; set; }
55+
56+
/// <summary>
57+
/// Gets or sets the event coorganizer email.
58+
/// </summary>
59+
public string? CoorganizerEmail { get; set; }
6060
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
using System.Runtime.Serialization;
2+
using System.Text.Json.Serialization;
3+
4+
using AzureOpenAIProxy.ApiApp.Converters;
5+
6+
namespace AzureOpenAIProxy.ApiApp.Models;
7+
8+
/// <summary>
9+
/// This represent the entity for the resource details for admin.
10+
/// </summary>
11+
public class AdminResourceDetails
12+
{
13+
/// <summary>
14+
/// Gets or sets the event id.
15+
/// </summary>
16+
[JsonRequired]
17+
public Guid ResourceId { get; set; }
18+
19+
/// <summary>
20+
/// Gets or sets the friendly name of the resource.
21+
/// </summary>
22+
[JsonRequired]
23+
public string FriendlyName { get; set; } = string.Empty;
24+
25+
/// <summary>
26+
/// Gets or sets the deployment name of the resource.
27+
/// </summary>
28+
[JsonRequired]
29+
public string DeploymentName { get; set; } = string.Empty;
30+
31+
/// <summary>
32+
/// Gets or sets the resource type.
33+
/// </summary>
34+
[JsonRequired]
35+
public ResourceType ResourceType { get; set; } = ResourceType.None;
36+
37+
/// <summary>
38+
/// Gets or sets the resource endpoint.
39+
/// </summary>
40+
[JsonRequired]
41+
public string Endpoint { get; set; } = string.Empty;
42+
43+
/// <summary>
44+
/// Gets or sets the resource API key.
45+
/// </summary>
46+
[JsonRequired]
47+
public string ApiKey { get; set; } = string.Empty;
48+
49+
/// <summary>
50+
/// Gets or sets the resource region.
51+
/// </summary>
52+
[JsonRequired]
53+
public string Region { get; set; } = string.Empty;
54+
55+
/// <summary>
56+
/// Gets or sets the value indicating whether the resource is active.
57+
/// </summary>
58+
[JsonRequired]
59+
public bool IsActive { get; set; }
60+
}
61+
62+
/// <summary>
63+
/// /// This defines the type of the resource.
64+
[JsonConverter(typeof(EnumMemberConverter<ResourceType>))]
65+
public enum ResourceType
66+
{
67+
/// <summary>
68+
/// Indicates the resource type is not defined.
69+
/// </summary>
70+
[EnumMember(Value = "none")]
71+
None,
72+
73+
/// <summary>
74+
/// Indicates the chat resource type.
75+
/// </summary>
76+
[EnumMember(Value = "chat")]
77+
Chat,
78+
79+
/// <summary>
80+
/// Indicates the image resource type.
81+
/// </summary>
82+
[EnumMember(Value = "image")]
83+
Image,
84+
}
Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
using System.Text.Json.Serialization;
2-
3-
/// <summary>
4-
/// This represents the event's detailed data for response by EventEndpoint.
5-
/// </summary>
6-
public class EventDetails
7-
{
8-
/// <summary>
9-
/// Gets or sets the event id.
10-
/// </summary>
11-
[JsonRequired]
12-
public Guid EventId { get; set; }
13-
14-
/// <summary>
15-
/// Gets or sets the event title name.
16-
/// </summary>
17-
[JsonRequired]
18-
public string Title { get; set; } = string.Empty;
19-
20-
/// <summary>
21-
/// Gets or sets the event summary.
22-
/// </summary>
23-
[JsonRequired]
24-
public string Summary { get; set; } = string.Empty;
25-
26-
/// <summary>
27-
/// Gets or sets the Azure OpenAI Service request max token capacity.
28-
/// </summary>
29-
[JsonRequired]
30-
public int MaxTokenCap { get; set; }
31-
32-
/// <summary>
33-
/// Gets or sets the Azure OpenAI Service daily request capacity.
34-
/// </summary>
35-
[JsonRequired]
36-
public int DailyRequestCap { get; set; }
1+
using System.Text.Json.Serialization;
2+
3+
/// <summary>
4+
/// This represent the entity for the event details for users.
5+
/// </summary>
6+
public class EventDetails
7+
{
8+
/// <summary>
9+
/// Gets or sets the event id.
10+
/// </summary>
11+
[JsonRequired]
12+
public Guid EventId { get; set; }
13+
14+
/// <summary>
15+
/// Gets or sets the event title name.
16+
/// </summary>
17+
[JsonRequired]
18+
public string Title { get; set; } = string.Empty;
19+
20+
/// <summary>
21+
/// Gets or sets the event summary.
22+
/// </summary>
23+
[JsonRequired]
24+
public string Summary { get; set; } = string.Empty;
25+
26+
/// <summary>
27+
/// Gets or sets the Azure OpenAI Service request max token capacity.
28+
/// </summary>
29+
[JsonRequired]
30+
public int MaxTokenCap { get; set; }
31+
32+
/// <summary>
33+
/// Gets or sets the Azure OpenAI Service daily request capacity.
34+
/// </summary>
35+
[JsonRequired]
36+
public int DailyRequestCap { get; set; }
3737
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using System.Text.Json;
2+
3+
using AzureOpenAIProxy.ApiApp.Models;
4+
5+
using FluentAssertions;
6+
7+
namespace AzureOpenAIProxy.ApiApp.Tests.Models;
8+
9+
public class AdminResourceDetailsTests
10+
{
11+
private static readonly AdminResourceDetails examplePayload = new()
12+
{
13+
ResourceId = Guid.Parse("67f410a3-c5e4-4326-a3ad-5812b9adfc06"),
14+
FriendlyName = "Test Resource",
15+
DeploymentName = "Test Deployment",
16+
ResourceType = ResourceType.Chat,
17+
Endpoint = "https://test.endpoint.com",
18+
ApiKey = "test-api-key",
19+
Region = "test-region",
20+
IsActive = true
21+
};
22+
23+
private static readonly string exampleJson = """
24+
{
25+
"resourceId": "67f410a3-c5e4-4326-a3ad-5812b9adfc06",
26+
"friendlyName": "Test Resource",
27+
"deploymentName": "Test Deployment",
28+
"resourceType": "chat",
29+
"endpoint": "https://test.endpoint.com",
30+
"apiKey": "test-api-key",
31+
"region": "test-region",
32+
"isActive": true
33+
}
34+
""";
35+
36+
private static readonly JsonSerializerOptions options = new()
37+
{
38+
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
39+
WriteIndented = true
40+
};
41+
42+
[Fact]
43+
public void Given_ExamplePayload_When_Serialized_Then_It_Should_Match_Json()
44+
{
45+
// Act
46+
var serialised = JsonSerializer.Serialize(examplePayload, options);
47+
48+
// Assert
49+
serialised.Should().ContainAll(
50+
"\"resourceId\":", "\"67f410a3-c5e4-4326-a3ad-5812b9adfc06\"",
51+
"\"friendlyName\":", "\"Test Resource\"",
52+
"\"deploymentName\":", "\"Test Deployment\"",
53+
"\"resourceType\":", "\"chat\"",
54+
"\"endpoint\":", "\"https://test.endpoint.com\"",
55+
"\"apiKey\":", "\"test-api-key\"",
56+
"\"region\":", "\"test-region\"",
57+
"\"isActive\":", "true");
58+
}
59+
60+
[Fact]
61+
public void Given_ExampleJson_When_Deserialized_Then_It_Should_Match_Object()
62+
{
63+
// Arrange & Act
64+
var deserialised = JsonSerializer.Deserialize<AdminResourceDetails>(exampleJson, options);
65+
66+
// Assert
67+
deserialised.Should().BeEquivalentTo(examplePayload);
68+
}
69+
}

0 commit comments

Comments
 (0)